diff --git a/src/Hamster.cpp b/src/Hamster.cpp index e078c05..22bead6 100644 --- a/src/Hamster.cpp +++ b/src/Hamster.cpp @@ -176,11 +176,15 @@ void Hamster::HandlePlayerControls(){ if(HamsterGame::Game().GetKey(A).bHeld){ aimingDir+=vf2d{-1,0}; } - if(HamsterGame::Game().GetKey(PGUP).bHeld){ + if(HamsterGame::Game().GetKey(PGUP).bPressed){ + HamsterGame::Game().tv.ZoomAtScreenPos(0.95f,HamsterGame::Game().tv.WorldToScreen(GetPos())); + HamsterGame::Game().camera.SetViewSize(HamsterGame::Game().camera.GetViewSize()*1.05f); z+=HamsterGame::Game().GetElapsedTime(); } - if(HamsterGame::Game().GetKey(PGDN).bHeld){ + if(HamsterGame::Game().GetKey(PGDN).bPressed){ z=std::max(0.f,z-HamsterGame::Game().GetElapsedTime()); + HamsterGame::Game().tv.ZoomAtScreenPos(1.05f,HamsterGame::Game().tv.WorldToScreen(GetPos())); + HamsterGame::Game().camera.SetViewSize(HamsterGame::Game().camera.GetViewSize()*0.95f); } if(aimingDir!=vf2d{}){ targetRot=aimingDir.norm().polar().y; diff --git a/src/HamsterGame.cpp b/src/HamsterGame.cpp index 78e0b79..852de8b 100644 --- a/src/HamsterGame.cpp +++ b/src/HamsterGame.cpp @@ -96,13 +96,14 @@ void HamsterGame::LoadLevel(const std::string_view mapName){ void HamsterGame::UpdateGame(const float fElapsedTime){ /*if(Hamster::GetPlayer().GetZ()>1.f){ - tv.SetZoom(1.f/sqrt(Hamster::GetPlayer().GetZ()),tv.WorldToScreen(Hamster::GetPlayer().GetPos())-SCREEN_FRAME.pos); + tv.SetZoom(1/Hamster::GetPlayer().GetZ(),tv.WorldToScreen(Hamster::GetPlayer().GetPos())); }else{ - tv.SetZoom(1.f,tv.WorldToScreen(Hamster::GetPlayer().GetPos())-SCREEN_FRAME.pos); + tv.SetZoom(1.f,tv.WorldToScreen(Hamster::GetPlayer().GetPos())); }*/ + + camera.Update(fElapsedTime); - tv.HandlePanAndZoom(); - //std::cout<=currentMap.value().GetData().GetMapData().width*16||y>=currentMap.value().GetData().GetMapData().height*16)continue; const int numTilesWide{GetGFX("gametiles.png").Sprite()->width/16}; const int numTilesTall{GetGFX("gametiles.png").Sprite()->height/16}; diff --git a/src/HamsterGame.h b/src/HamsterGame.h index a9edb7d..3574be9 100644 --- a/src/HamsterGame.h +++ b/src/HamsterGame.h @@ -70,10 +70,10 @@ public: static std::unordered_mapANIMATED_TILE_IDS; const double GetRuntime()const; const Terrain::TerrainType GetTerrainTypeAtPos(const vf2d pos)const; + Camera2D camera; private: void UpdateGame(const float fElapsedTime); void DrawGame(); - Camera2D camera; void LoadGraphics(); void LoadAnimations(); void LoadLevel(const std::string_view mapName);