|
|
@ -3,6 +3,7 @@ |
|
|
|
#define OLC_PGEX_TRANSFORMEDVIEW |
|
|
|
#define OLC_PGEX_TRANSFORMEDVIEW |
|
|
|
#include "olcUTIL_Geometry2D.h" |
|
|
|
#include "olcUTIL_Geometry2D.h" |
|
|
|
#include "TileManager.h" |
|
|
|
#include "TileManager.h" |
|
|
|
|
|
|
|
#include "util.h" |
|
|
|
|
|
|
|
|
|
|
|
#include "VirusAttack.h" |
|
|
|
#include "VirusAttack.h" |
|
|
|
|
|
|
|
|
|
|
@ -22,10 +23,12 @@ void VirusAttack::InitializeImages(){ |
|
|
|
LoadImage(OUTLINE,"assets/outline.png"); |
|
|
|
LoadImage(OUTLINE,"assets/outline.png"); |
|
|
|
LoadImage(VIRUS_IMG1,"assets/unit.png"); |
|
|
|
LoadImage(VIRUS_IMG1,"assets/unit.png"); |
|
|
|
LoadImage(SELECTION_CIRCLE,"assets/selection_circle.png"); |
|
|
|
LoadImage(SELECTION_CIRCLE,"assets/selection_circle.png"); |
|
|
|
|
|
|
|
LoadImage(MEMORY_COLLECTION_POINT,"assets/memory_collection_point.png"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool VirusAttack::OnUserCreate(){ |
|
|
|
bool VirusAttack::OnUserCreate(){ |
|
|
|
|
|
|
|
SetPixelMode(Pixel::MASK); |
|
|
|
|
|
|
|
|
|
|
|
game.Initialise(GetScreenSize()); |
|
|
|
game.Initialise(GetScreenSize()); |
|
|
|
|
|
|
|
|
|
|
|
InitializeImages(); |
|
|
|
InitializeImages(); |
|
|
@ -33,6 +36,10 @@ bool VirusAttack::OnUserCreate(){ |
|
|
|
IMAGES[MINIMAP_OUTLINE]=std::make_unique<Renderable>(); |
|
|
|
IMAGES[MINIMAP_OUTLINE]=std::make_unique<Renderable>(); |
|
|
|
IMAGES[MINIMAP_OUTLINE]->Create(64,64); |
|
|
|
IMAGES[MINIMAP_OUTLINE]->Create(64,64); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IMAGES[MATRIX]=std::make_unique<Renderable>(); |
|
|
|
|
|
|
|
IMAGES[MATRIX]->Create(64,64,false,false); |
|
|
|
|
|
|
|
IMAGES[MATRIX]->Sprite()->SetSampleMode(Sprite::PERIODIC); |
|
|
|
|
|
|
|
|
|
|
|
units.push_back(std::make_unique<BasicUnit>(vf2d{32,32},*IMAGES[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){ |
|
|
@ -41,6 +48,12 @@ bool VirusAttack::OnUserCreate(){ |
|
|
|
units.push_back(std::make_unique<BasicUnit2>(vf2d{float(rand()%ScreenWidth()),float(rand()%ScreenHeight())},*IMAGES[VIRUS_IMG1],false)); |
|
|
|
units.push_back(std::make_unique<BasicUnit2>(vf2d{float(rand()%ScreenWidth()),float(rand()%ScreenHeight())},*IMAGES[VIRUS_IMG1],false)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for(int i=0;i<5;i++){ |
|
|
|
|
|
|
|
collectionPoints.push_back(std::make_unique<CollectionPoint>(this,vf2d{32.f+48*i,32.f},0,*IMAGES[MEMORY_COLLECTION_POINT],MemoryType(i))); |
|
|
|
|
|
|
|
collectionPoints.push_back(std::make_unique<CollectionPoint>(this,vf2d{32.f,32.f+48*i},-PI/2,*IMAGES[MEMORY_COLLECTION_POINT],MemoryType(i))); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -136,11 +149,7 @@ void VirusAttack::DrawMinimap(){ |
|
|
|
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(IMAGES[MINIMAP_OUTLINE]->Sprite()); |
|
|
|
SetDrawTarget(IMAGES[MINIMAP_OUTLINE]->Sprite()); |
|
|
|
for(int y=0;y<64;y++){ |
|
|
|
Clear(BLANK); |
|
|
|
for(int x=0;x<64;x++){ |
|
|
|
|
|
|
|
Draw(x,y,BLANK); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
DrawRect((game.GetWorldOffset()/worldPixelSize*64),viewingTilesPct*64/game.GetWorldScale()); |
|
|
|
DrawRect((game.GetWorldOffset()/worldPixelSize*64),viewingTilesPct*64/game.GetWorldScale()); |
|
|
|
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); |
|
|
@ -184,7 +193,59 @@ void VirusAttack::HandleMinimapClick(){ |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void VirusAttack::UpdateMatrixTexture(float fElapsedTime){ |
|
|
|
|
|
|
|
if(matrixTimer==0){ |
|
|
|
|
|
|
|
activeLetters.emplace_back(vf2d{float(rand()%64),float(64)},util::random(-40)-20,matrixLetters[rand()%matrixLetters.size()]); |
|
|
|
|
|
|
|
matrixTimer=util::random(0.125); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if(updatePixelsTimer==0){ |
|
|
|
|
|
|
|
SetDrawTarget(IMAGES[MATRIX]->Sprite()); |
|
|
|
|
|
|
|
Sprite*img=IMAGES[MATRIX]->Sprite(); |
|
|
|
|
|
|
|
for(int y=63;y>=0;y--){ |
|
|
|
|
|
|
|
for(int x=63;x>=0;x--){ |
|
|
|
|
|
|
|
Pixel col=img->GetPixel(x,y); |
|
|
|
|
|
|
|
if(col.r>0){ |
|
|
|
|
|
|
|
if(x>0){ |
|
|
|
|
|
|
|
Pixel leftCol=img->GetPixel(x-1,y); |
|
|
|
|
|
|
|
if(leftCol.r<col.r){ |
|
|
|
|
|
|
|
leftCol=PixelLerp(col,leftCol,0.125); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Draw(x-1,y,leftCol); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if(x<img->width-1){ |
|
|
|
|
|
|
|
Pixel rightCol=img->GetPixel(x+1,y); |
|
|
|
|
|
|
|
if(rightCol.r<col.r){ |
|
|
|
|
|
|
|
rightCol=PixelLerp(col,rightCol,0.125); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Draw(x+1,y,rightCol); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
col/=8; |
|
|
|
|
|
|
|
Draw(x,y,col); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
for(int y=0;y<64;y++){ |
|
|
|
|
|
|
|
Draw({0,y},img->GetPixel(1,y)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
SetDrawTarget(nullptr); |
|
|
|
|
|
|
|
updatePixelsTimer=0.1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if(activeLetters.size()>0){ |
|
|
|
|
|
|
|
SetDrawTarget(IMAGES[MATRIX]->Sprite()); |
|
|
|
|
|
|
|
for(Letter&letter:activeLetters){ |
|
|
|
|
|
|
|
letter.pos.y+=letter.spd*fElapsedTime; |
|
|
|
|
|
|
|
DrawString(letter.pos,std::string(1,letter.c)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
SetDrawTarget(nullptr); |
|
|
|
|
|
|
|
IMAGES[MATRIX]->Decal()->Update(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
matrixTimer=std::max(0.f,matrixTimer-fElapsedTime); |
|
|
|
|
|
|
|
updatePixelsTimer=std::max(0.f,updatePixelsTimer-fElapsedTime); |
|
|
|
|
|
|
|
std::erase_if(activeLetters,[](Letter&letter){return letter.pos.y<-32;}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool VirusAttack::OnUserUpdate(float fElapsedTime){ |
|
|
|
bool VirusAttack::OnUserUpdate(float fElapsedTime){ |
|
|
|
|
|
|
|
UpdateMatrixTexture(fElapsedTime); |
|
|
|
HandleDraggingSelection(); |
|
|
|
HandleDraggingSelection(); |
|
|
|
HandleRightClickMove(); |
|
|
|
HandleRightClickMove(); |
|
|
|
HandlePanAndZoom(fElapsedTime); |
|
|
|
HandlePanAndZoom(fElapsedTime); |
|
|
@ -223,6 +284,34 @@ bool VirusAttack::OnUserUpdate(float fElapsedTime){ |
|
|
|
for(auto&u:units){ |
|
|
|
for(auto&u:units){ |
|
|
|
u->Draw(game,IMAGES); |
|
|
|
u->Draw(game,IMAGES); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for(auto&collectionPoint:collectionPoints){ |
|
|
|
|
|
|
|
collectionPoint->Update(this,*IMAGES[MATRIX]); |
|
|
|
|
|
|
|
geom2d::rect<float>cpRect=geom2d::rect<float>({collectionPoint->pos-collectionPoint->img.Sprite()->Size()/2,collectionPoint->img.Sprite()->Size()}); |
|
|
|
|
|
|
|
geom2d::rect<float>viewRegion=geom2d::rect<float>({game.GetWorldTL(),game.GetWorldVisibleArea()}); |
|
|
|
|
|
|
|
if(geom2d::overlaps(cpRect,viewRegion)){ |
|
|
|
|
|
|
|
Pixel col; |
|
|
|
|
|
|
|
switch(collectionPoint->type){ |
|
|
|
|
|
|
|
case HEALTH:{ |
|
|
|
|
|
|
|
col=CONSTANT::HEALTH_COLOR; |
|
|
|
|
|
|
|
}break; |
|
|
|
|
|
|
|
case RANGE:{ |
|
|
|
|
|
|
|
col=CONSTANT::RANGE_COLOR; |
|
|
|
|
|
|
|
}break; |
|
|
|
|
|
|
|
case ATKSPD:{ |
|
|
|
|
|
|
|
col=CONSTANT::ATKSPD_COLOR; |
|
|
|
|
|
|
|
}break; |
|
|
|
|
|
|
|
case MOVESPD:{ |
|
|
|
|
|
|
|
col=CONSTANT::MOVESPD_COLOR; |
|
|
|
|
|
|
|
}break; |
|
|
|
|
|
|
|
case PROCEDURE:{ |
|
|
|
|
|
|
|
col=CONSTANT::PROCEDURE_COLOR; |
|
|
|
|
|
|
|
}break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
game.DrawRotatedDecal(collectionPoint->pos,collectionPoint->img.Decal(),collectionPoint->rot,collectionPoint->img.Sprite()->Size()/2,{1,1},col); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for(auto&u:units){ |
|
|
|
for(auto&u:units){ |
|
|
|
u->DrawHud(game,IMAGES); |
|
|
|
u->DrawHud(game,IMAGES); |
|
|
|
} |
|
|
|
} |
|
|
@ -240,9 +329,35 @@ bool VirusAttack::OnUserUpdate(float fElapsedTime){ |
|
|
|
|
|
|
|
|
|
|
|
DrawMinimap(); |
|
|
|
DrawMinimap(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DrawDecal({0,0},IMAGES[MATRIX]->Decal(),{1,1},{128,0,128}); |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
VirusAttack::CollectionPoint::CollectionPoint(PixelGameEngine*pge,vf2d pos,float rot,Renderable&collectionPointImg,MemoryType type) |
|
|
|
|
|
|
|
:pos(pos),rot(rot),type(type),originalCollectionPointImg(collectionPointImg.Sprite()),randomOffset({util::random(128),util::random(128)}){ |
|
|
|
|
|
|
|
img.Create(collectionPointImg.Sprite()->width,collectionPointImg.Sprite()->height); |
|
|
|
|
|
|
|
pge->SetDrawTarget(img.Sprite()); |
|
|
|
|
|
|
|
pge->Clear(BLANK); |
|
|
|
|
|
|
|
pge->DrawSprite({0,0},collectionPointImg.Sprite()); |
|
|
|
|
|
|
|
pge->SetDrawTarget(nullptr); |
|
|
|
|
|
|
|
img.Decal()->Update(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void VirusAttack::CollectionPoint::Update(PixelGameEngine*pge,Renderable&matrixImg){ |
|
|
|
|
|
|
|
pge->SetDrawTarget(img.Sprite()); |
|
|
|
|
|
|
|
for(int y=0;y<img.Sprite()->height;y++){ |
|
|
|
|
|
|
|
for(int x=0;x<img.Sprite()->width;x++){ |
|
|
|
|
|
|
|
Pixel col=originalCollectionPointImg->GetPixel(x,y); |
|
|
|
|
|
|
|
if(col==WHITE){ |
|
|
|
|
|
|
|
pge->Draw(x,y,matrixImg.Sprite()->GetPixel(int(x+randomOffset.x),int(y+randomOffset.y))); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
img.Decal()->Update(); |
|
|
|
|
|
|
|
pge->SetDrawTarget(nullptr); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int main() |
|
|
|
int main() |
|
|
|
{ |
|
|
|
{ |
|
|
|
VirusAttack app; |
|
|
|
VirusAttack app; |
|
|
|