diff --git a/olcCodeJam2023Entry/VirusAttack.cpp b/olcCodeJam2023Entry/VirusAttack.cpp index 0ca6e0d..31d8021 100644 --- a/olcCodeJam2023Entry/VirusAttack.cpp +++ b/olcCodeJam2023Entry/VirusAttack.cpp @@ -18,6 +18,9 @@ bool VirusAttack::OnUserCreate(){ CONSTANT::SELECTION_CIRCLE.Load("assets/selection_circle.png"); TILE.Load("assets/tile.png",nullptr,false,false); + MINIMAP_HUD.Load("assets/minimap_hud.png"); + OUTLINE.Load("assets/outline.png"); + MINIMAP_OUTLINE.Create(64,64); units.push_back(std::make_unique(vf2d{32,32},CONSTANT::VIRUS_IMG1,true)); for(int i=0;i<10;i++){ @@ -113,21 +116,36 @@ void VirusAttack::IdentifyClosestTarget(Unit*&closestUnit,float&closestDist,std: } } -bool VirusAttack::OnUserUpdate(float fElapsedTime){ - HandleDraggingSelection(); - HandleRightClickMove(); +void VirusAttack::DrawMinimap(){ + DrawDecal(GetScreenSize()-MINIMAP_HUD.Sprite()->Size(),MINIMAP_HUD.Decal(),{1,1}); + vf2d minimapTL=GetScreenSize()-vf2d{64,64}; + vi2d worldPixelSize=CONSTANT::WORLD_SIZE*CONSTANT::TILE_SIZE; + vf2d viewingTilesPct=vf2d{float(ScreenWidth()),float(ScreenHeight())}/CONSTANT::TILE_SIZE/CONSTANT::WORLD_SIZE; + SetDrawTarget(MINIMAP_OUTLINE.Sprite()); + for(int y=0;y<64;y++){ + for(int x=0;x<64;x++){ + Draw(x,y,BLANK); + } + } + DrawRect((game.GetWorldOffset()/worldPixelSize*64),viewingTilesPct*64/game.GetWorldScale()); + MINIMAP_OUTLINE.Decal()->Update(); + SetDrawTarget(nullptr); + DrawDecal(minimapTL,MINIMAP_OUTLINE.Decal()); +} +void VirusAttack::HandlePanAndZoom(float fElapsedTime){ + float speedScale=std::min(1.f,game.GetWorldScale().x); if(GetKey(A).bHeld){ - game.MoveWorldOffset({-256*fElapsedTime,0}); + game.MoveWorldOffset(vf2d{-256*fElapsedTime,0}/speedScale); } if(GetKey(W).bHeld){ - game.MoveWorldOffset({0,-256*fElapsedTime}); + game.MoveWorldOffset(vf2d{0,-256*fElapsedTime}/speedScale); } if(GetKey(S).bHeld){ - game.MoveWorldOffset({0,256*fElapsedTime}); + game.MoveWorldOffset(vf2d{0,256*fElapsedTime}/speedScale); } if(GetKey(D).bHeld){ - game.MoveWorldOffset({256*fElapsedTime,0}); + game.MoveWorldOffset(vf2d{256*fElapsedTime,0}/speedScale); } if(GetMouseWheel()>0){ @@ -135,11 +153,17 @@ bool VirusAttack::OnUserUpdate(float fElapsedTime){ game.ZoomAtScreenPos(1.25,GetMousePos()); } } else - if(GetMouseWheel()<0){ - if(game.GetWorldScale().x>0.5){ - game.ZoomAtScreenPos(0.75,GetMousePos()); + if(GetMouseWheel()<0){ + if(game.GetWorldScale().x>0.5){ + game.ZoomAtScreenPos(0.75,GetMousePos()); + } } - } +} + +bool VirusAttack::OnUserUpdate(float fElapsedTime){ + HandleDraggingSelection(); + HandleRightClickMove(); + HandlePanAndZoom(fElapsedTime); for(auto&u:units){ Unit*closestUnit=nullptr; @@ -162,6 +186,8 @@ bool VirusAttack::OnUserUpdate(float fElapsedTime){ DrawSelectionRectangle(); + DrawMinimap(); + return true; } diff --git a/olcCodeJam2023Entry/VirusAttack.h b/olcCodeJam2023Entry/VirusAttack.h index f821b80..ce127fa 100644 --- a/olcCodeJam2023Entry/VirusAttack.h +++ b/olcCodeJam2023Entry/VirusAttack.h @@ -8,7 +8,7 @@ class VirusAttack : public olc::PixelGameEngine private: std::vector>units; - Renderable TILE; + Renderable TILE,MINIMAP_HUD,OUTLINE,MINIMAP_OUTLINE; TileTransformedView game; @@ -19,6 +19,8 @@ private: void CollisionChecking(std::shared_ptru,std::shared_ptru2); void IdentifyClosestTarget(Unit*&closestUnit,float&closestDist,std::shared_ptru,std::shared_ptru2); vf2d GetWorldMousePos(); + void HandlePanAndZoom(float fElapsedTime); + void DrawMinimap(); public: VirusAttack(); diff --git a/olcCodeJam2023Entry/assets/minimap_hud.png b/olcCodeJam2023Entry/assets/minimap_hud.png new file mode 100644 index 0000000..533e96a Binary files /dev/null and b/olcCodeJam2023Entry/assets/minimap_hud.png differ diff --git a/olcCodeJam2023Entry/assets/outline.png b/olcCodeJam2023Entry/assets/outline.png new file mode 100644 index 0000000..ddb3785 Binary files /dev/null and b/olcCodeJam2023Entry/assets/outline.png differ