From a35d6d01a61db6712c123b68dfdd17f3bb6d62d9 Mon Sep 17 00:00:00 2001 From: Ben Date: Thu, 3 Sep 2020 17:55:54 +0100 Subject: [PATCH] i seem to have just made a fancy camera instead of actually progressign --- The Great Machine/Camera.cpp | 15 ++++++++--- The Great Machine/Camera.hpp | 5 +++- The Great Machine/Dungeon.cpp | 28 +++++++++++++++------ The Great Machine/Dungeon.hpp | 2 +- The Great Machine/The Great Machine.vcxproj | 2 +- The Great Machine/Things.hpp | 2 +- 6 files changed, 39 insertions(+), 15 deletions(-) diff --git a/The Great Machine/Camera.cpp b/The Great Machine/Camera.cpp index 19a7ed5..19e7d8f 100644 --- a/The Great Machine/Camera.cpp +++ b/The Great Machine/Camera.cpp @@ -1,14 +1,21 @@ #include "Camera.hpp" -#include "Things.hpp" +#include +#include "Things.hpp" #include "Logger.hpp" void Camera::Update(float fTime) { if (_Track == nullptr) return; - Coords.x = _Track->Coords.x - (ViewPort.x / 2); - Coords.y = _Track->Coords.y - (ViewPort.y / 2); + _DesiredCoords.x = _Track->Coords.x - (ViewPort.x / 2); + _DesiredCoords.y = _Track->Coords.y - (ViewPort.y / 2); + + float lerpX = std::lerp(Coords.x, _DesiredCoords.x, _SmoothSpeed); + float lerpY = std::lerp(Coords.y, _DesiredCoords.y, _SmoothSpeed); + + Coords.x = lerpX; + Coords.y = lerpY; } void Camera::Input(olc::PixelGameEngine* engine) @@ -19,4 +26,6 @@ void Camera::Input(olc::PixelGameEngine* engine) void Camera::TrackEntity(Entity* entity) { _Track = entity; + Coords.x = _Track->Coords.x - (ViewPort.x / 2); + Coords.y = _Track->Coords.y - (ViewPort.y / 2); } diff --git a/The Great Machine/Camera.hpp b/The Great Machine/Camera.hpp index ffb3e89..3925f20 100644 --- a/The Great Machine/Camera.hpp +++ b/The Great Machine/Camera.hpp @@ -8,7 +8,7 @@ class Entity; class Camera { public: - olc::vi2d Coords; + olc::vf2d Coords; olc::vi2d ViewPort; void Update(float fTime); @@ -21,6 +21,9 @@ private: Entity* _Track = nullptr; + olc::vi2d _DesiredCoords; + float _SmoothSpeed = 0.0125f; + }; #endif diff --git a/The Great Machine/Dungeon.cpp b/The Great Machine/Dungeon.cpp index a5a3f46..1878748 100644 --- a/The Great Machine/Dungeon.cpp +++ b/The Great Machine/Dungeon.cpp @@ -174,7 +174,7 @@ void Dungeon::Generate() DungeonTiles[t->Coords] = t; } - DungeonRenderTarget = new olc::Renderable(); + //DungeonRenderTarget = new olc::Renderable(); //DungeonRenderTarget->Create(DungeonWidth * TileSize, DungeonHeight * TileSize); //DungeonRenderTarget->Create(200, 200); } @@ -187,24 +187,27 @@ void Dungeon::SpawnEntity(Entity* entity) void Dungeon::Input(olc::PixelGameEngine* engine, float fTime) { if (engine->GetKey(olc::W).bHeld) - Player->Coords.y -= static_cast(static_cast(TileSize) * (fTime * 10.0f)); + Player->Coords.y -= static_cast(TileSize) * (fTime * 10.0f); if (engine->GetKey(olc::A).bHeld) - Player->Coords.x -= static_cast(static_cast(TileSize) * (fTime * 10.0f)); + Player->Coords.x -= static_cast(TileSize) * (fTime * 10.0f); if (engine->GetKey(olc::S).bHeld) - Player->Coords.y += static_cast(static_cast(TileSize) * (fTime * 10.0f)); + Player->Coords.y += static_cast(TileSize) * (fTime * 10.0f); if (engine->GetKey(olc::D).bHeld) - Player->Coords.x += static_cast(static_cast(TileSize) * (fTime * 10.0f)); + Player->Coords.x += static_cast(TileSize) * (fTime * 10.0f); } void Dungeon::Update(float fTime) { + + + ActiveCamera->Update(fTime); } void Dungeon::Draw(olc::PixelGameEngine* engine) { //int - engine->SetDrawTarget(DungeonRenderTarget->Sprite()); + //engine->SetDrawTarget(DungeonRenderTarget->Sprite()); for (std::pair tile : DungeonTiles) { // TODO: Perform culling @@ -213,8 +216,8 @@ void Dungeon::Draw(olc::PixelGameEngine* engine) { static_cast(TileSize), static_cast(TileSize) }, TileSet->Decal(), TileSetDictionary->Dictionary[tile.second->Type], { 16, 16 }); } - engine->SetDrawTarget(1); - engine->DrawSprite({ 0, 0 }, DungeonRenderTarget->Sprite()); + //engine->SetDrawTarget(1); + //engine->DrawSprite({ 0, 0 }, DungeonRenderTarget->Sprite()); // Draw character engine->DrawPartialDecal({ static_cast(Player->Coords.x - ActiveCamera->Coords.x), static_cast(Player->Coords.y - ActiveCamera->Coords.y) }, @@ -224,6 +227,15 @@ void Dungeon::Draw(olc::PixelGameEngine* engine) Dungeon::~Dungeon() { + delete Player; + delete ActiveCamera; + delete TileSetDictionary; + delete TileSet; + delete DungeonRenderTarget; for (std::pair tile : DungeonTiles) delete tile.second; + for (std::pair entity : Entities) + delete entity.second; + for (std::pair entity : FixedItems) + delete entity.second; } diff --git a/The Great Machine/Dungeon.hpp b/The Great Machine/Dungeon.hpp index 4723ef7..c222c96 100644 --- a/The Great Machine/Dungeon.hpp +++ b/The Great Machine/Dungeon.hpp @@ -31,7 +31,7 @@ public: Playable* Player; Camera* ActiveCamera; - int TileSize = 16; + int TileSize = 64; int DungeonWidth; int DungeonHeight; diff --git a/The Great Machine/The Great Machine.vcxproj b/The Great Machine/The Great Machine.vcxproj index 141ce50..6902a57 100644 --- a/The Great Machine/The Great Machine.vcxproj +++ b/The Great Machine/The Great Machine.vcxproj @@ -131,7 +131,7 @@ true NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) true - stdcpp17 + stdcpplatest Console diff --git a/The Great Machine/Things.hpp b/The Great Machine/Things.hpp index a67b77a..ebe1679 100644 --- a/The Great Machine/Things.hpp +++ b/The Great Machine/Things.hpp @@ -95,7 +95,7 @@ class HitBox; class Entity { public: - olc::vi2d Coords; + olc::vf2d Coords; EEntity::Type Type; HitBox* AABBHitBox; olc::vf2d SpriteTextureMask;