|
|
@ -12,23 +12,33 @@ VirusAttack::VirusAttack() |
|
|
|
sAppName = "olcCodeJam 2023 Entry"; |
|
|
|
sAppName = "olcCodeJam 2023 Entry"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void VirusAttack::InitializeImages(){ |
|
|
|
|
|
|
|
auto LoadImage=[&](Image img,std::string filepath,bool filter=false,bool clamp=true){ |
|
|
|
|
|
|
|
IMAGES[img]=std::make_unique<Renderable>(); |
|
|
|
|
|
|
|
IMAGES[img]->Load(filepath,nullptr,filter,clamp); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
LoadImage(TILE,"assets/tile.png",false,false); |
|
|
|
|
|
|
|
LoadImage(MINIMAP_HUD,"assets/minimap_hud.png"); |
|
|
|
|
|
|
|
LoadImage(OUTLINE,"assets/outline.png"); |
|
|
|
|
|
|
|
LoadImage(VIRUS_IMG1,"assets/unit.png"); |
|
|
|
|
|
|
|
LoadImage(SELECTION_CIRCLE,"assets/selection_circle.png"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool VirusAttack::OnUserCreate(){ |
|
|
|
bool VirusAttack::OnUserCreate(){ |
|
|
|
game.Initialise(GetScreenSize()); |
|
|
|
game.Initialise(GetScreenSize()); |
|
|
|
|
|
|
|
|
|
|
|
CONSTANT::VIRUS_IMG1.Load("assets/unit.png"); |
|
|
|
InitializeImages(); |
|
|
|
CONSTANT::SELECTION_CIRCLE.Load("assets/selection_circle.png"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TILE.Load("assets/tile.png",nullptr,false,false); |
|
|
|
IMAGES[MINIMAP_OUTLINE]=std::make_unique<Renderable>(); |
|
|
|
MINIMAP_HUD.Load("assets/minimap_hud.png"); |
|
|
|
IMAGES[MINIMAP_OUTLINE]->Create(64,64); |
|
|
|
OUTLINE.Load("assets/outline.png"); |
|
|
|
|
|
|
|
MINIMAP_OUTLINE.Create(64,64); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
units.push_back(std::make_unique<BasicUnit>(vf2d{32,32},CONSTANT::VIRUS_IMG1,true)); |
|
|
|
units.push_back(std::make_unique<BasicUnit>(vf2d{32,32},*IMAGES[VIRUS_IMG1],true)); |
|
|
|
for(int i=0;i<10;i++){ |
|
|
|
for(int i=0;i<10;i++){ |
|
|
|
if(rand()%2==0){ |
|
|
|
if(rand()%2==0){ |
|
|
|
units.push_back(std::make_unique<BasicUnit>(vf2d{float(rand()%ScreenWidth()),float(rand()%ScreenHeight())},CONSTANT::VIRUS_IMG1,true)); |
|
|
|
units.push_back(std::make_unique<BasicUnit>(vf2d{float(rand()%ScreenWidth()),float(rand()%ScreenHeight())},*IMAGES[VIRUS_IMG1],true)); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
units.push_back(std::make_unique<BasicUnit2>(vf2d{float(rand()%ScreenWidth()),float(rand()%ScreenHeight())},CONSTANT::VIRUS_IMG1,false)); |
|
|
|
units.push_back(std::make_unique<BasicUnit2>(vf2d{float(rand()%ScreenWidth()),float(rand()%ScreenHeight())},*IMAGES[VIRUS_IMG1],false)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return true; |
|
|
|
return true; |
|
|
@ -121,11 +131,11 @@ void VirusAttack::IdentifyClosestTarget(Unit*&closestUnit,float&closestDist,std: |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void VirusAttack::DrawMinimap(){ |
|
|
|
void VirusAttack::DrawMinimap(){ |
|
|
|
DrawDecal(GetScreenSize()-MINIMAP_HUD.Sprite()->Size(),MINIMAP_HUD.Decal(),{1,1}); |
|
|
|
DrawDecal(GetScreenSize()-IMAGES[MINIMAP_HUD]->Sprite()->Size(),IMAGES[MINIMAP_HUD]->Decal(),{1,1}); |
|
|
|
vf2d minimapTL=GetScreenSize()-vf2d{64,64}; |
|
|
|
vf2d minimapTL=GetScreenSize()-vf2d{64,64}; |
|
|
|
vi2d worldPixelSize=CONSTANT::WORLD_SIZE*CONSTANT::TILE_SIZE; |
|
|
|
vi2d worldPixelSize=CONSTANT::WORLD_SIZE*CONSTANT::TILE_SIZE; |
|
|
|
vf2d viewingTilesPct=vf2d{float(ScreenWidth()),float(ScreenHeight())}/CONSTANT::TILE_SIZE/CONSTANT::WORLD_SIZE; |
|
|
|
vf2d viewingTilesPct=vf2d{float(ScreenWidth()),float(ScreenHeight())}/CONSTANT::TILE_SIZE/CONSTANT::WORLD_SIZE; |
|
|
|
SetDrawTarget(MINIMAP_OUTLINE.Sprite()); |
|
|
|
SetDrawTarget(IMAGES[MINIMAP_OUTLINE]->Sprite()); |
|
|
|
for(int y=0;y<64;y++){ |
|
|
|
for(int y=0;y<64;y++){ |
|
|
|
for(int x=0;x<64;x++){ |
|
|
|
for(int x=0;x<64;x++){ |
|
|
|
Draw(x,y,BLANK); |
|
|
|
Draw(x,y,BLANK); |
|
|
@ -135,9 +145,9 @@ void VirusAttack::DrawMinimap(){ |
|
|
|
for(auto&u:units){ |
|
|
|
for(auto&u:units){ |
|
|
|
FillRect(u->GetGhostPos()/worldPixelSize*64,vf2d{2,2}*u->GetUnitSize()/24,u->IsFriendly()?GREEN:RED); |
|
|
|
FillRect(u->GetGhostPos()/worldPixelSize*64,vf2d{2,2}*u->GetUnitSize()/24,u->IsFriendly()?GREEN:RED); |
|
|
|
} |
|
|
|
} |
|
|
|
MINIMAP_OUTLINE.Decal()->Update(); |
|
|
|
IMAGES[MINIMAP_OUTLINE]->Decal()->Update(); |
|
|
|
SetDrawTarget(nullptr); |
|
|
|
SetDrawTarget(nullptr); |
|
|
|
DrawDecal(minimapTL,MINIMAP_OUTLINE.Decal()); |
|
|
|
DrawDecal(minimapTL,IMAGES[MINIMAP_OUTLINE]->Decal()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void VirusAttack::HandlePanAndZoom(float fElapsedTime){ |
|
|
|
void VirusAttack::HandlePanAndZoom(float fElapsedTime){ |
|
|
@ -208,13 +218,13 @@ bool VirusAttack::OnUserUpdate(float fElapsedTime){ |
|
|
|
u->HideGhost(); |
|
|
|
u->HideGhost(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
game.DrawPartialDecal({0,0},CONSTANT::WORLD_SIZE*CONSTANT::TILE_SIZE,TILE.Decal(),{0,0},CONSTANT::WORLD_SIZE*CONSTANT::TILE_SIZE,DARK_GREEN); |
|
|
|
game.DrawPartialDecal({0,0},CONSTANT::WORLD_SIZE*CONSTANT::TILE_SIZE,IMAGES[TILE]->Decal(),{0,0},CONSTANT::WORLD_SIZE*CONSTANT::TILE_SIZE,DARK_GREEN); |
|
|
|
|
|
|
|
|
|
|
|
for(auto&u:units){ |
|
|
|
for(auto&u:units){ |
|
|
|
u->Draw(game); |
|
|
|
u->Draw(game,IMAGES); |
|
|
|
} |
|
|
|
} |
|
|
|
for(auto&u:units){ |
|
|
|
for(auto&u:units){ |
|
|
|
u->DrawHud(game); |
|
|
|
u->DrawHud(game,IMAGES); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
DrawSelectionRectangle(); |
|
|
|
DrawSelectionRectangle(); |
|
|
|