From bf61fa77b4bd2eb5ef6d6173c9083750fa9bb3cb Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Fri, 25 Aug 2023 16:56:05 -0500 Subject: [PATCH] Condense functions. --- olcCodeJam2023Entry/ImageManager.h | 8 ++++++++ olcCodeJam2023Entry/VirusAttack.cpp | 18 +++++++++++++----- olcCodeJam2023Entry/VirusAttack.h | 2 ++ 3 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 olcCodeJam2023Entry/ImageManager.h diff --git a/olcCodeJam2023Entry/ImageManager.h b/olcCodeJam2023Entry/ImageManager.h new file mode 100644 index 0000000..084967f --- /dev/null +++ b/olcCodeJam2023Entry/ImageManager.h @@ -0,0 +1,8 @@ +#pragma once +#include "olcPixelGameEngine.h" + +class ImageManager{ +public: + Renderable VIRUS_IMG1; + Renderable SELECTION_CIRCLE; +}; \ No newline at end of file diff --git a/olcCodeJam2023Entry/VirusAttack.cpp b/olcCodeJam2023Entry/VirusAttack.cpp index d67fe0e..776cf4f 100644 --- a/olcCodeJam2023Entry/VirusAttack.cpp +++ b/olcCodeJam2023Entry/VirusAttack.cpp @@ -27,8 +27,7 @@ bool VirusAttack::OnUserCreate(){ return true; } -bool VirusAttack::OnUserUpdate(float fElapsedTime){ - // Called once per frame, draws random coloured pixels +void VirusAttack::HandleDraggingSelection(){ if(GetMouse(0).bPressed){ for(std::unique_ptr&u:units){ u->Deselect(); @@ -51,6 +50,16 @@ bool VirusAttack::OnUserUpdate(float fElapsedTime){ } startingDragPos=CONSTANT::UNSELECTED; } +} + +void VirusAttack::DrawSelectionRectangle(){ + if(startingDragPos!=CONSTANT::UNSELECTED){ + FillRectDecal(startingDragPos,GetMousePos()-startingDragPos,{255,255,0,128}); + } +} + +bool VirusAttack::OnUserUpdate(float fElapsedTime){ + HandleDraggingSelection(); for(std::unique_ptr&u:units){ u->Update(fElapsedTime); @@ -60,9 +69,8 @@ bool VirusAttack::OnUserUpdate(float fElapsedTime){ u->Draw(this); } - if(startingDragPos!=CONSTANT::UNSELECTED){ - FillRectDecal(startingDragPos,GetMousePos()-startingDragPos,{255,255,0,128}); - } + DrawSelectionRectangle(); + return true; } diff --git a/olcCodeJam2023Entry/VirusAttack.h b/olcCodeJam2023Entry/VirusAttack.h index 7a349f9..8166405 100644 --- a/olcCodeJam2023Entry/VirusAttack.h +++ b/olcCodeJam2023Entry/VirusAttack.h @@ -8,6 +8,8 @@ private: std::vector>units; vf2d startingDragPos=CONSTANT::UNSELECTED; + void HandleDraggingSelection(); + void DrawSelectionRectangle(); public: VirusAttack();