i seem to have just made a fancy camera instead of actually progressign
This commit is contained in:
@@ -1,14 +1,21 @@
|
||||
#include "Camera.hpp"
|
||||
|
||||
#include "Things.hpp"
|
||||
#include <cmath>
|
||||
|
||||
#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);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<int>(static_cast<float>(TileSize) * (fTime * 10.0f));
|
||||
Player->Coords.y -= static_cast<float>(TileSize) * (fTime * 10.0f);
|
||||
if (engine->GetKey(olc::A).bHeld)
|
||||
Player->Coords.x -= static_cast<int>(static_cast<float>(TileSize) * (fTime * 10.0f));
|
||||
Player->Coords.x -= static_cast<float>(TileSize) * (fTime * 10.0f);
|
||||
if (engine->GetKey(olc::S).bHeld)
|
||||
Player->Coords.y += static_cast<int>(static_cast<float>(TileSize) * (fTime * 10.0f));
|
||||
Player->Coords.y += static_cast<float>(TileSize) * (fTime * 10.0f);
|
||||
if (engine->GetKey(olc::D).bHeld)
|
||||
Player->Coords.x += static_cast<int>(static_cast<float>(TileSize) * (fTime * 10.0f));
|
||||
Player->Coords.x += static_cast<float>(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<olc::vi2d, Tile*> tile : DungeonTiles)
|
||||
{
|
||||
// TODO: Perform culling
|
||||
@@ -213,8 +216,8 @@ void Dungeon::Draw(olc::PixelGameEngine* engine)
|
||||
{ static_cast<float>(TileSize), static_cast<float>(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<float>(Player->Coords.x - ActiveCamera->Coords.x), static_cast<float>(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<olc::vi2d, Tile*> tile : DungeonTiles)
|
||||
delete tile.second;
|
||||
for (std::pair<olc::vi2d, Entity*> entity : Entities)
|
||||
delete entity.second;
|
||||
for (std::pair<olc::vi2d, FixedItem*> entity : FixedItems)
|
||||
delete entity.second;
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ public:
|
||||
Playable* Player;
|
||||
Camera* ActiveCamera;
|
||||
|
||||
int TileSize = 16;
|
||||
int TileSize = 64;
|
||||
|
||||
int DungeonWidth;
|
||||
int DungeonHeight;
|
||||
|
||||
@@ -131,7 +131,7 @@
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||
<LanguageStandard>stdcpplatest</LanguageStandard>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
|
||||
@@ -95,7 +95,7 @@ class HitBox;
|
||||
class Entity
|
||||
{
|
||||
public:
|
||||
olc::vi2d Coords;
|
||||
olc::vf2d Coords;
|
||||
EEntity::Type Type;
|
||||
HitBox* AABBHitBox;
|
||||
olc::vf2d SpriteTextureMask;
|
||||
|
||||
Reference in New Issue
Block a user