|
|
|
@ -24,6 +24,13 @@ void VirusAttack::InitializeImages(){ |
|
|
|
|
LoadImage(VIRUS_IMG1,"assets/unit.png"); |
|
|
|
|
LoadImage(SELECTION_CIRCLE,"assets/selection_circle.png"); |
|
|
|
|
LoadImage(MEMORY_COLLECTION_POINT,"assets/memory_collection_point.png"); |
|
|
|
|
LoadImage(LEFT_SHIFTER,"assets/left_shifter.png"); |
|
|
|
|
LoadImage(RIGHT_SHIFTER,"assets/right_shifter.png"); |
|
|
|
|
LoadImage(BIT_RESTORER,"assets/bit_restorer.png"); |
|
|
|
|
LoadImage(MEMORY_SWAPPER,"assets/memory_swapper.png"); |
|
|
|
|
LoadImage(CORRUPTER,"assets/corrupter.png"); |
|
|
|
|
LoadImage(UNIT_ALLOCATOR,"assets/shell.png"); |
|
|
|
|
LoadImage(RAM_BANK,"assets/ram_bank.png"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool VirusAttack::OnUserCreate(){ |
|
|
|
@ -40,14 +47,14 @@ bool VirusAttack::OnUserCreate(){ |
|
|
|
|
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)); |
|
|
|
|
for(int i=0;i<10;i++){ |
|
|
|
|
if(rand()%2==0){ |
|
|
|
|
units.push_back(std::make_unique<BasicUnit>(vf2d{float(rand()%ScreenWidth()),float(rand()%ScreenHeight())},*IMAGES[VIRUS_IMG1],true)); |
|
|
|
|
} else { |
|
|
|
|
units.push_back(std::make_unique<BasicUnit2>(vf2d{float(rand()%ScreenWidth()),float(rand()%ScreenHeight())},*IMAGES[VIRUS_IMG1],false)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
units.push_back(std::make_unique<LeftShifter>(vf2d{128,128},IMAGES,true)); |
|
|
|
|
units.push_back(std::make_unique<RightShifter>(vf2d{129,129},IMAGES,true)); |
|
|
|
|
units.push_back(std::make_unique<BitRestorer>(vf2d{130,130},IMAGES,true)); |
|
|
|
|
units.push_back(std::make_unique<MemorySwapper>(vf2d{131,131},IMAGES,true)); |
|
|
|
|
units.push_back(std::make_unique<Corrupter>(vf2d{132,132},IMAGES,true)); |
|
|
|
|
units.push_back(std::make_unique<MemoryAllocator>(vf2d{133,133},IMAGES,true)); |
|
|
|
|
units.push_back(std::make_unique<RAMBank>(this,vf2d{134,134},IMAGES,true)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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))); |
|
|
|
@ -161,16 +168,16 @@ void VirusAttack::DrawMinimap(){ |
|
|
|
|
|
|
|
|
|
void VirusAttack::HandlePanAndZoom(float fElapsedTime){ |
|
|
|
|
float speedScale=std::min(1.f,game.GetWorldScale().x); |
|
|
|
|
if(GetKey(A).bHeld){ |
|
|
|
|
if(GetKey(A).bHeld/*||GetMouseX()<=CONSTANT::SCROLL_BOUNDARY*/){ |
|
|
|
|
game.MoveWorldOffset(vf2d{-256*fElapsedTime,0}/speedScale); |
|
|
|
|
} |
|
|
|
|
if(GetKey(W).bHeld){ |
|
|
|
|
if(GetKey(W).bHeld/*||GetMouseY()<=CONSTANT::SCROLL_BOUNDARY*/){ |
|
|
|
|
game.MoveWorldOffset(vf2d{0,-256*fElapsedTime}/speedScale); |
|
|
|
|
} |
|
|
|
|
if(GetKey(S).bHeld){ |
|
|
|
|
if(GetKey(S).bHeld/*||GetMouseY()>=ScreenHeight()-CONSTANT::SCROLL_BOUNDARY*/){ |
|
|
|
|
game.MoveWorldOffset(vf2d{0,256*fElapsedTime}/speedScale); |
|
|
|
|
} |
|
|
|
|
if(GetKey(D).bHeld){ |
|
|
|
|
if(GetKey(D).bHeld/*||GetMouseX()>=ScreenWidth()-CONSTANT::SCROLL_BOUNDARY*/){ |
|
|
|
|
game.MoveWorldOffset(vf2d{256*fElapsedTime,0}/speedScale); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -244,6 +251,32 @@ void VirusAttack::UpdateMatrixTexture(float fElapsedTime){ |
|
|
|
|
std::erase_if(activeLetters,[](Letter&letter){return letter.pos.y<-32;}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void VirusAttack::RenderCollectionPoints(CollectionPoint*cp){ |
|
|
|
|
geom2d::rect<float>cpRect=geom2d::rect<float>({cp->pos-cp->img.Sprite()->Size()/2,cp->img.Sprite()->Size()}); |
|
|
|
|
geom2d::rect<float>viewRegion=geom2d::rect<float>({game.GetWorldTL(),game.GetWorldVisibleArea()}); |
|
|
|
|
if(geom2d::overlaps(cpRect,viewRegion)){ |
|
|
|
|
Pixel col; |
|
|
|
|
switch(cp->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(cp->pos,cp->img.Decal(),cp->rot,cp->img.Sprite()->Size()/2,{1,1},col); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool VirusAttack::OnUserUpdate(float fElapsedTime){ |
|
|
|
|
UpdateMatrixTexture(fElapsedTime); |
|
|
|
|
HandleDraggingSelection(); |
|
|
|
@ -272,12 +305,7 @@ bool VirusAttack::OnUserUpdate(float fElapsedTime){ |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
u->AttemptAttack(closestUnit); |
|
|
|
|
u->Update(fElapsedTime); |
|
|
|
|
} |
|
|
|
|
for(auto&u:units){ |
|
|
|
|
if(!u->GhostInFogOfWar()&&u->InFogOfWar()){ |
|
|
|
|
u->HideGhost(); |
|
|
|
|
} |
|
|
|
|
u->_Update(this); |
|
|
|
|
} |
|
|
|
|
game.DrawPartialDecal({0,0},CONSTANT::WORLD_SIZE*CONSTANT::TILE_SIZE,IMAGES[TILE]->Decal(),{0,0},CONSTANT::WORLD_SIZE*CONSTANT::TILE_SIZE,DARK_GREEN); |
|
|
|
|
|
|
|
|
@ -287,29 +315,7 @@ bool VirusAttack::OnUserUpdate(float fElapsedTime){ |
|
|
|
|
|
|
|
|
|
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); |
|
|
|
|
} |
|
|
|
|
RenderCollectionPoints(collectionPoint.get()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for(auto&u:units){ |
|
|
|
@ -317,6 +323,14 @@ bool VirusAttack::OnUserUpdate(float fElapsedTime){ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
DrawSelectionRectangle(); |
|
|
|
|
RenderFogOfWar(); |
|
|
|
|
|
|
|
|
|
DrawMinimap(); |
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void VirusAttack::RenderFogOfWar(){ |
|
|
|
|
for(int y=game.GetTopLeftTile().y/96-1;y<=game.GetBottomRightTile().y/96+1;y++){ |
|
|
|
|
for(int x=game.GetTopLeftTile().x/96-1;x<=game.GetBottomRightTile().x/96+1;x++){ |
|
|
|
|
if(TileManager::visibleTiles.count(vi2d{x,y})==0){ |
|
|
|
@ -326,12 +340,6 @@ bool VirusAttack::OnUserUpdate(float fElapsedTime){ |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
DrawMinimap(); |
|
|
|
|
|
|
|
|
|
DrawDecal({0,0},IMAGES[MATRIX]->Decal(),{1,1},{128,0,128}); |
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
VirusAttack::CollectionPoint::CollectionPoint(PixelGameEngine*pge,vf2d pos,float rot,Renderable&collectionPointImg,MemoryType type) |
|
|
|
|