Scale and camera correction almost fixed. Still need to solidify zoom factors somehow.

main
sigonasr2 3 months ago
parent 66622c84f7
commit 530fdc7494
  1. 8
      src/Hamster.cpp
  2. 19
      src/HamsterGame.cpp
  3. 2
      src/HamsterGame.h

@ -176,11 +176,15 @@ void Hamster::HandlePlayerControls(){
if(HamsterGame::Game().GetKey(A).bHeld){ if(HamsterGame::Game().GetKey(A).bHeld){
aimingDir+=vf2d{-1,0}; 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(); 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()); 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{}){ if(aimingDir!=vf2d{}){
targetRot=aimingDir.norm().polar().y; targetRot=aimingDir.norm().polar().y;

@ -96,13 +96,14 @@ void HamsterGame::LoadLevel(const std::string_view mapName){
void HamsterGame::UpdateGame(const float fElapsedTime){ void HamsterGame::UpdateGame(const float fElapsedTime){
/*if(Hamster::GetPlayer().GetZ()>1.f){ /*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{ }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); camera.Update(fElapsedTime);
tv.HandlePanAndZoom(); tv.SetWorldOffset(-SCREEN_FRAME.pos*(camera.GetViewSize()/SCREEN_FRAME.size)+camera.GetViewPosition());
//std::cout<<tv.GetWorldScale().str()<<std::endl;
Hamster::UpdateHamsters(fElapsedTime); Hamster::UpdateHamsters(fElapsedTime);
Powerup::UpdatePowerups(fElapsedTime); Powerup::UpdatePowerups(fElapsedTime);
border.Update(fElapsedTime); border.Update(fElapsedTime);
@ -113,8 +114,6 @@ void HamsterGame::DrawGame(){
Powerup::DrawPowerups(tv); Powerup::DrawPowerups(tv);
Hamster::DrawHamsters(tv); Hamster::DrawHamsters(tv);
border.Draw(); border.Draw();
DrawStringDecal(SCREEN_FRAME.pos+vf2d{1,1},"Terrain Type: "+Terrain::TerrainToString(Hamster::GetPlayer().GetTerrainStandingOn()),BLACK);
DrawStringDecal(SCREEN_FRAME.pos,"Terrain Type: "+Terrain::TerrainToString(Hamster::GetPlayer().GetTerrainStandingOn()));
#pragma region Powerup Display #pragma region Powerup Display
for(int y:std::ranges::iota_view(0,4)){ for(int y:std::ranges::iota_view(0,4)){
@ -145,6 +144,8 @@ void HamsterGame::DrawGame(){
GradientFillRectDecal(vf2d{12.f,240.f}+vf2d{12.f,5.f},vf2d{Hamster::GetPlayer().GetBurnRatio()*57.f,4.f},{250,177,163},{226,228,255},{226,228,255},{250,177,163}); GradientFillRectDecal(vf2d{12.f,240.f}+vf2d{12.f,5.f},vf2d{Hamster::GetPlayer().GetBurnRatio()*57.f,4.f},{250,177,163},{226,228,255},{226,228,255},{250,177,163});
} }
#pragma endregion #pragma endregion
tv.FillRectDecal(GetMousePos(),{2,2},GREEN);
} }
const Terrain::TerrainType HamsterGame::GetTerrainTypeAtPos(const vf2d pos)const{ const Terrain::TerrainType HamsterGame::GetTerrainTypeAtPos(const vf2d pos)const{
@ -163,11 +164,9 @@ const Terrain::TerrainType HamsterGame::GetTerrainTypeAtPos(const vf2d pos)const
void HamsterGame::DrawLevelTiles(){ void HamsterGame::DrawLevelTiles(){
float extendedBounds{SCREEN_FRAME.pos.x}; float extendedBounds{SCREEN_FRAME.pos.x};
extendedBounds*=1/tv.GetWorldScale().x; extendedBounds*=1/tv.GetWorldScale().x;
std::cout<<tv.GetWorldTL().str()<<std::endl;
std::cout<<tv.GetWorldBR().str()<<std::endl;
for(const LayerTag&layer:currentMap.value().GetData().GetLayers()){ for(const LayerTag&layer:currentMap.value().GetData().GetLayers()){
for(float y=tv.GetWorldTL().y-16;y<=tv.GetWorldBR().y+16;y+=16){ for(float y=tv.GetWorldTL().y-17;y<=tv.GetWorldBR().y+16;y+=16){
for(float x=tv.GetWorldTL().x-1+extendedBounds;x<=tv.GetWorldBR().x+16+extendedBounds;x+=16){ for(float x=tv.GetWorldTL().x-17+extendedBounds;x<=tv.GetWorldBR().x+16+extendedBounds;x+=16){
if(x<=0.f||y<=0.f||x>=currentMap.value().GetData().GetMapData().width*16||y>=currentMap.value().GetData().GetMapData().height*16)continue; if(x<=0.f||y<=0.f||x>=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 numTilesWide{GetGFX("gametiles.png").Sprite()->width/16};
const int numTilesTall{GetGFX("gametiles.png").Sprite()->height/16}; const int numTilesTall{GetGFX("gametiles.png").Sprite()->height/16};

@ -70,10 +70,10 @@ public:
static std::unordered_map<uint32_t,Animate2D::FrameSequence>ANIMATED_TILE_IDS; static std::unordered_map<uint32_t,Animate2D::FrameSequence>ANIMATED_TILE_IDS;
const double GetRuntime()const; const double GetRuntime()const;
const Terrain::TerrainType GetTerrainTypeAtPos(const vf2d pos)const; const Terrain::TerrainType GetTerrainTypeAtPos(const vf2d pos)const;
Camera2D camera;
private: private:
void UpdateGame(const float fElapsedTime); void UpdateGame(const float fElapsedTime);
void DrawGame(); void DrawGame();
Camera2D camera;
void LoadGraphics(); void LoadGraphics();
void LoadAnimations(); void LoadAnimations();
void LoadLevel(const std::string_view mapName); void LoadLevel(const std::string_view mapName);

Loading…
Cancel
Save