Implemented zooming and minimap navigation.

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

@ -34,15 +34,18 @@ bool VirusAttack::OnUserCreate(){
}
void VirusAttack::HandleDraggingSelection(){
auto NotClickingOnMinimap=[&](){return !(GetMouseX()>=ScreenWidth()-64&&GetMouseY()>=ScreenHeight()-64);};
if(GetMouse(0).bPressed){
for(auto&u:units){
u->Deselect();
}
if(startingDragPos==CONSTANT::UNSELECTED){
startingDragPos=GetWorldMousePos();
if(NotClickingOnMinimap()){
for(auto&u:units){
u->Deselect();
}
if(startingDragPos==CONSTANT::UNSELECTED){
startingDragPos=GetWorldMousePos();
}
}
}
if(GetMouse(0).bReleased){
if(GetMouse(0).bReleased&&startingDragPos!=CONSTANT::UNSELECTED){
vf2d endDragPos=GetWorldMousePos();
if(endDragPos.x<startingDragPos.x){std::swap(startingDragPos.x,endDragPos.x);}
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){
HandleDraggingSelection();
HandleRightClickMove();
HandlePanAndZoom(fElapsedTime);
HandleMinimapClick();
for(auto&u:units){
Unit*closestUnit=nullptr;

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

Loading…
Cancel
Save