|
|
|
@ -2,8 +2,12 @@ |
|
|
|
|
#include "olcPixelGameEngine.h" |
|
|
|
|
#define OLC_SOUNDWAVE |
|
|
|
|
#include "olcSoundWaveEngine.h" |
|
|
|
|
#include "VirusAttack.h" |
|
|
|
|
#define OLC_PGEX_TRANSFORMEDVIEW |
|
|
|
|
#include "olcPGEX_TransformedView.h" |
|
|
|
|
#include "olcUTIL_Geometry2D.h" |
|
|
|
|
#include "olcUTIL_Camera2D.h" |
|
|
|
|
|
|
|
|
|
#include "VirusAttack.h" |
|
|
|
|
|
|
|
|
|
VirusAttack::VirusAttack() |
|
|
|
|
{ |
|
|
|
@ -12,10 +16,13 @@ VirusAttack::VirusAttack() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool VirusAttack::OnUserCreate(){ |
|
|
|
|
game.Initialise(GetScreenSize()); |
|
|
|
|
|
|
|
|
|
CONSTANT::VIRUS_IMG1.Load("assets/unit.png"); |
|
|
|
|
CONSTANT::SELECTION_CIRCLE.Load("assets/selection_circle.png"); |
|
|
|
|
|
|
|
|
|
TILE.Load("assets/tile.png",nullptr,false,false); |
|
|
|
|
|
|
|
|
|
units.push_back(std::make_unique<BasicUnit>(vf2d{32,32},CONSTANT::VIRUS_IMG1,true)); |
|
|
|
|
for(int i=0;i<10;i++){ |
|
|
|
|
if(rand()%2==0){ |
|
|
|
@ -33,11 +40,11 @@ void VirusAttack::HandleDraggingSelection(){ |
|
|
|
|
u->Deselect(); |
|
|
|
|
} |
|
|
|
|
if(startingDragPos==CONSTANT::UNSELECTED){ |
|
|
|
|
startingDragPos=GetMousePos(); |
|
|
|
|
startingDragPos=GetWorldMousePos(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if(GetMouse(0).bReleased){ |
|
|
|
|
vf2d endDragPos=GetMousePos(); |
|
|
|
|
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);} |
|
|
|
|
geom2d::rect<float> selectionRegion(startingDragPos,endDragPos-startingDragPos); |
|
|
|
@ -52,9 +59,13 @@ void VirusAttack::HandleDraggingSelection(){ |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
vf2d VirusAttack::GetWorldMousePos(){
|
|
|
|
|
return game.ScreenToWorld(GetMousePos()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void VirusAttack::DrawSelectionRectangle(){ |
|
|
|
|
if(startingDragPos!=CONSTANT::UNSELECTED){ |
|
|
|
|
FillRectDecal(startingDragPos,GetMousePos()-startingDragPos,{255,255,0,128}); |
|
|
|
|
game.FillRectDecal(startingDragPos,GetWorldMousePos()-startingDragPos,{255,255,0,128}); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -64,7 +75,7 @@ void VirusAttack::HandleRightClickMove(){ |
|
|
|
|
for(auto&u:units){ |
|
|
|
|
if(!u->IsFriendly()){ |
|
|
|
|
geom2d::rect<float> unitRegion(u->GetPos()-u->GetUnitSize()/2,u->GetUnitSize()); |
|
|
|
|
if(geom2d::overlaps(unitRegion,GetMousePos())){ |
|
|
|
|
if(geom2d::overlaps(unitRegion,GetWorldMousePos())){ |
|
|
|
|
for(auto&u2:units){ |
|
|
|
|
if(u2->IsFriendly()&&u2->IsSelected()){ |
|
|
|
|
u2->SetTargetUnit(u); |
|
|
|
@ -78,7 +89,7 @@ void VirusAttack::HandleRightClickMove(){ |
|
|
|
|
if(!selectedTarget){ |
|
|
|
|
for(auto&u:units){ |
|
|
|
|
if(u->IsFriendly()&&u->IsSelected()){ |
|
|
|
|
u->SetTargetLocation(GetMousePos()); |
|
|
|
|
u->SetTargetLocation(GetWorldMousePos()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -110,6 +121,8 @@ bool VirusAttack::OnUserUpdate(float fElapsedTime){ |
|
|
|
|
HandleDraggingSelection(); |
|
|
|
|
HandleRightClickMove(); |
|
|
|
|
|
|
|
|
|
game.HandlePanAndZoom(); |
|
|
|
|
|
|
|
|
|
for(auto&u:units){ |
|
|
|
|
Unit*closestUnit=nullptr; |
|
|
|
|
float closestDist=999999; |
|
|
|
@ -120,9 +133,13 @@ bool VirusAttack::OnUserUpdate(float fElapsedTime){ |
|
|
|
|
u->AttemptAttack(closestUnit); |
|
|
|
|
u->Update(fElapsedTime); |
|
|
|
|
} |
|
|
|
|
game.DrawPartialDecal({0,0},CONSTANT::WORLD_SIZE*CONSTANT::TILE_SIZE,TILE.Decal(),{0,0},CONSTANT::WORLD_SIZE*CONSTANT::TILE_SIZE,DARK_GREEN); |
|
|
|
|
|
|
|
|
|
for(auto&u:units){ |
|
|
|
|
u->Draw(this); |
|
|
|
|
u->Draw(game); |
|
|
|
|
} |
|
|
|
|
for(auto&u:units){ |
|
|
|
|
u->DrawHud(game); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
DrawSelectionRectangle(); |
|
|
|
|