From e632af5d58b42cb3a402897dd0392cdbae9d3b42 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Sat, 26 Aug 2023 00:08:40 -0500 Subject: [PATCH] Implemented zooming and minimap navigation. --- olcCodeJam2023Entry/VirusAttack.cpp | 23 +++++++++++++++++------ olcCodeJam2023Entry/VirusAttack.h | 1 + 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/olcCodeJam2023Entry/VirusAttack.cpp b/olcCodeJam2023Entry/VirusAttack.cpp index 31d8021..2aeeebf 100644 --- a/olcCodeJam2023Entry/VirusAttack.cpp +++ b/olcCodeJam2023Entry/VirusAttack.cpp @@ -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=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; diff --git a/olcCodeJam2023Entry/VirusAttack.h b/olcCodeJam2023Entry/VirusAttack.h index ce127fa..1c6871f 100644 --- a/olcCodeJam2023Entry/VirusAttack.h +++ b/olcCodeJam2023Entry/VirusAttack.h @@ -21,6 +21,7 @@ private: vf2d GetWorldMousePos(); void HandlePanAndZoom(float fElapsedTime); void DrawMinimap(); + void HandleMinimapClick(); public: VirusAttack();