#define OLC_PGE_APPLICATION #include "olcPixelGameEngine.h" #define OLC_SOUNDWAVE #include "olcSoundWaveEngine.h" #include "VirusAttack.h" #include "olcUTIL_Geometry2D.h" VirusAttack::VirusAttack() { // Name your application sAppName = "olcCodeJam 2023 Entry"; } bool VirusAttack::OnUserCreate(){ CONSTANT::VIRUS_IMG1.Load("assets/unit.png"); CONSTANT::SELECTION_CIRCLE.Load("assets/selection_circle.png"); units.push_back(std::make_unique(vf2d{32,32},CONSTANT::VIRUS_IMG1,true)); for(int i=0;i<10;i++){ if(rand()%2==0){ units.push_back(std::make_unique(vf2d{float(rand()%ScreenWidth()),float(rand()%ScreenHeight())},CONSTANT::VIRUS_IMG1,false)); } else { units.push_back(std::make_unique(vf2d{float(rand()%ScreenWidth()),float(rand()%ScreenHeight())},CONSTANT::VIRUS_IMG1,false)); } } return true; } bool VirusAttack::OnUserUpdate(float fElapsedTime){ // Called once per frame, draws random coloured pixels if(GetMouse(0).bPressed){ for(std::unique_ptr&u:units){ u->Deselect(); } if(startingDragPos==CONSTANT::UNSELECTED){ startingDragPos=GetMousePos(); } } if(GetMouse(0).bReleased){ vf2d endDragPos=GetMousePos(); if(endDragPos.x selectionRegion(startingDragPos,endDragPos-startingDragPos); for(std::unique_ptr&u:units){ if(u->IsFriendly()){ if(utils::geom2d::overlaps(selectionRegion,u->GetPos())){ u->Select(); } } } startingDragPos=CONSTANT::UNSELECTED; } for(std::unique_ptr&u:units){ u->Update(fElapsedTime); } for(std::unique_ptr&u:units){ u->Draw(this); } if(startingDragPos!=CONSTANT::UNSELECTED){ FillRectDecal(startingDragPos,GetMousePos()-startingDragPos,{255,255,0,128}); } return true; } int main() { VirusAttack app; if (app.Construct(426, 320, 4, 4)) app.Start(); return 0; }