Implemented zooming and minimap navigation.

CorrectiveAction
sigonasr2 1 year ago
parent ab6c43f347
commit e632af5d58
  1. 13
      olcCodeJam2023Entry/VirusAttack.cpp
  2. 1
      olcCodeJam2023Entry/VirusAttack.h

@ -34,7 +34,9 @@ bool VirusAttack::OnUserCreate(){
} }
void VirusAttack::HandleDraggingSelection(){ void VirusAttack::HandleDraggingSelection(){
auto NotClickingOnMinimap=[&](){return !(GetMouseX()>=ScreenWidth()-64&&GetMouseY()>=ScreenHeight()-64);};
if(GetMouse(0).bPressed){ if(GetMouse(0).bPressed){
if(NotClickingOnMinimap()){
for(auto&u:units){ for(auto&u:units){
u->Deselect(); u->Deselect();
} }
@ -42,7 +44,8 @@ void VirusAttack::HandleDraggingSelection(){
startingDragPos=GetWorldMousePos(); startingDragPos=GetWorldMousePos();
} }
} }
if(GetMouse(0).bReleased){ }
if(GetMouse(0).bReleased&&startingDragPos!=CONSTANT::UNSELECTED){
vf2d endDragPos=GetWorldMousePos(); vf2d endDragPos=GetWorldMousePos();
if(endDragPos.x<startingDragPos.x){std::swap(startingDragPos.x,endDragPos.x);} if(endDragPos.x<startingDragPos.x){std::swap(startingDragPos.x,endDragPos.x);}
if(endDragPos.y<startingDragPos.y){std::swap(startingDragPos.y,endDragPos.y);} if(endDragPos.y<startingDragPos.y){std::swap(startingDragPos.y,endDragPos.y);}
@ -160,10 +163,18 @@ void VirusAttack::HandlePanAndZoom(float fElapsedTime){
} }
} }
void VirusAttack::HandleMinimapClick(){
if(startingDragPos==CONSTANT::UNSELECTED&&GetMouse(0).bHeld&&GetMouseX()>=ScreenWidth()-64&&GetMouseY()>=ScreenHeight()-64){
vf2d minimapTL=GetScreenSize()-vf2d{64,64};
game.SetWorldOffset(vf2d(GetMousePos()-minimapTL)/64*CONSTANT::WORLD_SIZE*CONSTANT::TILE_SIZE-vf2d(GetScreenSize())/game.GetWorldScale()/2.f);
}
}
bool VirusAttack::OnUserUpdate(float fElapsedTime){ bool VirusAttack::OnUserUpdate(float fElapsedTime){
HandleDraggingSelection(); HandleDraggingSelection();
HandleRightClickMove(); HandleRightClickMove();
HandlePanAndZoom(fElapsedTime); HandlePanAndZoom(fElapsedTime);
HandleMinimapClick();
for(auto&u:units){ for(auto&u:units){
Unit*closestUnit=nullptr; Unit*closestUnit=nullptr;

@ -21,6 +21,7 @@ private:
vf2d GetWorldMousePos(); vf2d GetWorldMousePos();
void HandlePanAndZoom(float fElapsedTime); void HandlePanAndZoom(float fElapsedTime);
void DrawMinimap(); void DrawMinimap();
void HandleMinimapClick();
public: public:
VirusAttack(); VirusAttack();

Loading…
Cancel
Save