@ -124,54 +124,60 @@ void VirusAttack::InitializeSounds(){
bool VirusAttack : : UnitCreationClickHandled ( ) {
bool VirusAttack : : UnitCreationClickHandled ( ) {
if ( leftShifterButton - > bPressed ) {
if ( leftShifterButton - > bPressed ) {
for ( auto & u : units ) {
for ( auto & u : units ) {
if ( u - > IsSelected ( ) & & u - > IsAllocator ( ) & & CanAfford ( LeftShifter : : resourceCost ) ) {
if ( u - > IsSelected ( ) & & u - > IsAllocator ( ) & & CanAfford ( player_resources , LeftShifter : : resourceCost ) ) {
std : : unique_ptr < LeftShifter > buildUnit = std : : make_unique < LeftShifter > ( this , u - > GetPos ( ) , IMAGES , u - > IsFriendly ( ) ) ;
std : : unique_ptr < LeftShifter > buildUnit = std : : make_unique < LeftShifter > ( this , u - > GetPos ( ) , IMAGES , u - > IsFriendly ( ) ) ;
u - > SetBuildUnit ( CONSTANT : : UNIT_BUILD_TIME , std : : move ( buildUnit ) ) ;
u - > SetBuildUnit ( CONSTANT : : UNIT_BUILD_TIME , std : : move ( buildUnit ) ) ;
ExpendResources ( player_resources , LeftShifter : : resourceCost ) ;
}
}
}
}
return true ;
return true ;
}
}
if ( rightShifterButton - > bPressed ) {
if ( rightShifterButton - > bPressed ) {
for ( auto & u : units ) {
for ( auto & u : units ) {
if ( u - > IsSelected ( ) & & u - > IsAllocator ( ) & & CanAfford ( RightShifter : : resourceCost ) ) {
if ( u - > IsSelected ( ) & & u - > IsAllocator ( ) & & CanAfford ( player_resources , RightShifter : : resourceCost ) ) {
std : : unique_ptr < RightShifter > buildUnit = std : : make_unique < RightShifter > ( this , u - > GetPos ( ) , IMAGES , u - > IsFriendly ( ) ) ;
std : : unique_ptr < RightShifter > buildUnit = std : : make_unique < RightShifter > ( this , u - > GetPos ( ) , IMAGES , u - > IsFriendly ( ) ) ;
u - > SetBuildUnit ( CONSTANT : : UNIT_BUILD_TIME , std : : move ( buildUnit ) ) ;
u - > SetBuildUnit ( CONSTANT : : UNIT_BUILD_TIME , std : : move ( buildUnit ) ) ;
ExpendResources ( player_resources , RightShifter : : resourceCost ) ;
}
}
}
}
return true ;
return true ;
}
}
if ( bitRestorerButton - > bPressed ) {
if ( bitRestorerButton - > bPressed ) {
for ( auto & u : units ) {
for ( auto & u : units ) {
if ( u - > IsSelected ( ) & & u - > IsAllocator ( ) & & CanAfford ( BitRestorer : : resourceCost ) ) {
if ( u - > IsSelected ( ) & & u - > IsAllocator ( ) & & CanAfford ( player_resources , BitRestorer : : resourceCost ) ) {
std : : unique_ptr < BitRestorer > buildUnit = std : : make_unique < BitRestorer > ( this , u - > GetPos ( ) , IMAGES , u - > IsFriendly ( ) ) ;
std : : unique_ptr < BitRestorer > buildUnit = std : : make_unique < BitRestorer > ( this , u - > GetPos ( ) , IMAGES , u - > IsFriendly ( ) ) ;
u - > SetBuildUnit ( CONSTANT : : UNIT_BUILD_TIME , std : : move ( buildUnit ) ) ;
u - > SetBuildUnit ( CONSTANT : : UNIT_BUILD_TIME , std : : move ( buildUnit ) ) ;
ExpendResources ( player_resources , BitRestorer : : resourceCost ) ;
}
}
}
}
return true ;
return true ;
}
}
if ( memorySwapperButton - > bPressed ) {
if ( memorySwapperButton - > bPressed ) {
for ( auto & u : units ) {
for ( auto & u : units ) {
if ( u - > IsSelected ( ) & & u - > IsAllocator ( ) & & CanAfford ( MemorySwapper : : resourceCost ) ) {
if ( u - > IsSelected ( ) & & u - > IsAllocator ( ) & & CanAfford ( player_resources , MemorySwapper : : resourceCost ) ) {
std : : unique_ptr < MemorySwapper > buildUnit = std : : make_unique < MemorySwapper > ( this , u - > GetPos ( ) , IMAGES , u - > IsFriendly ( ) ) ;
std : : unique_ptr < MemorySwapper > buildUnit = std : : make_unique < MemorySwapper > ( this , u - > GetPos ( ) , IMAGES , u - > IsFriendly ( ) ) ;
u - > SetBuildUnit ( CONSTANT : : UNIT_BUILD_TIME , std : : move ( buildUnit ) ) ;
u - > SetBuildUnit ( CONSTANT : : UNIT_BUILD_TIME , std : : move ( buildUnit ) ) ;
ExpendResources ( player_resources , MemorySwapper : : resourceCost ) ;
}
}
}
}
return true ;
return true ;
}
}
if ( corrupterButton - > bPressed ) {
if ( corrupterButton - > bPressed ) {
for ( auto & u : units ) {
for ( auto & u : units ) {
if ( u - > IsSelected ( ) & & u - > IsAllocator ( ) & & CanAfford ( Corrupter : : resourceCost ) ) {
if ( u - > IsSelected ( ) & & u - > IsAllocator ( ) & & CanAfford ( player_resources , Corrupter : : resourceCost ) ) {
std : : unique_ptr < Corrupter > buildUnit = std : : make_unique < Corrupter > ( this , u - > GetPos ( ) , IMAGES , u - > IsFriendly ( ) ) ;
std : : unique_ptr < Corrupter > buildUnit = std : : make_unique < Corrupter > ( this , u - > GetPos ( ) , IMAGES , u - > IsFriendly ( ) ) ;
u - > SetBuildUnit ( CONSTANT : : UNIT_BUILD_TIME , std : : move ( buildUnit ) ) ;
u - > SetBuildUnit ( CONSTANT : : UNIT_BUILD_TIME , std : : move ( buildUnit ) ) ;
ExpendResources ( player_resources , Corrupter : : resourceCost ) ;
}
}
}
}
return true ;
return true ;
}
}
if ( platformButton - > bPressed ) {
if ( platformButton - > bPressed ) {
for ( auto & u : units ) {
for ( auto & u : units ) {
if ( u - > IsSelected ( ) & & u - > IsAllocator ( ) & & CanAfford ( MemoryAllocator : : resourceCost ) ) {
if ( u - > IsSelected ( ) & & u - > IsAllocator ( ) & & CanAfford ( player_resources , MemoryAllocator : : resourceCost ) ) {
std : : unique_ptr < MemoryAllocator > buildUnit = std : : make_unique < MemoryAllocator > ( this , u - > GetPos ( ) , IMAGES , u - > IsFriendly ( ) ) ;
std : : unique_ptr < MemoryAllocator > buildUnit = std : : make_unique < MemoryAllocator > ( this , u - > GetPos ( ) , IMAGES , u - > IsFriendly ( ) ) ;
u - > SetBuildUnit ( CONSTANT : : UNIT_BUILD_TIME , std : : move ( buildUnit ) ) ;
u - > SetBuildUnit ( CONSTANT : : UNIT_BUILD_TIME , std : : move ( buildUnit ) ) ;
ExpendResources ( player_resources , MemoryAllocator : : resourceCost ) ;
}
}
}
}
return true ;
return true ;
@ -179,6 +185,17 @@ bool VirusAttack::UnitCreationClickHandled(){
return false ;
return false ;
} ;
} ;
void VirusAttack : : UpdateUnitCreationListGUI ( bool allocatorSelected ) {
unitCreationList . DisplayAllControls ( allocatorSelected ) ;
leftShifterButton - > Enable ( CanAfford ( player_resources , LeftShifter : : resourceCost ) ) ;
rightShifterButton - > Enable ( CanAfford ( player_resources , RightShifter : : resourceCost ) ) ;
bitRestorerButton - > Enable ( CanAfford ( player_resources , BitRestorer : : resourceCost ) ) ;
memorySwapperButton - > Enable ( CanAfford ( player_resources , MemorySwapper : : resourceCost ) ) ;
corrupterButton - > Enable ( CanAfford ( player_resources , Corrupter : : resourceCost ) ) ;
platformButton - > Enable ( CanAfford ( player_resources , MemoryAllocator : : resourceCost ) ) ;
unitCreationList . Update ( this ) ;
}
void VirusAttack : : HandleDraggingSelection ( ) {
void VirusAttack : : HandleDraggingSelection ( ) {
auto NotClickingOnMinimap = [ & ] ( ) { return ! ( GetMouseX ( ) > = ScreenWidth ( ) - 64 & & GetMouseY ( ) > = ScreenHeight ( ) - 64 ) ; } ;
auto NotClickingOnMinimap = [ & ] ( ) { return ! ( GetMouseX ( ) > = ScreenWidth ( ) - 64 & & GetMouseY ( ) > = ScreenHeight ( ) - 64 ) ; } ;
bool allocatorSelected = false ;
bool allocatorSelected = false ;
@ -188,14 +205,7 @@ void VirusAttack::HandleDraggingSelection(){
allocatorSelected = true ;
allocatorSelected = true ;
}
}
}
}
unitCreationList . DisplayAllControls ( allocatorSelected ) ;
UpdateUnitCreationListGUI ( allocatorSelected ) ;
leftShifterButton - > Enable ( CanAfford ( LeftShifter : : resourceCost ) ) ;
rightShifterButton - > Enable ( CanAfford ( RightShifter : : resourceCost ) ) ;
bitRestorerButton - > Enable ( CanAfford ( BitRestorer : : resourceCost ) ) ;
memorySwapperButton - > Enable ( CanAfford ( MemorySwapper : : resourceCost ) ) ;
corrupterButton - > Enable ( CanAfford ( Corrupter : : resourceCost ) ) ;
platformButton - > Enable ( CanAfford ( MemoryAllocator : : resourceCost ) ) ;
unitCreationList . Update ( this ) ;
if ( GetMouse ( 0 ) . bPressed ) {
if ( GetMouse ( 0 ) . bPressed ) {
if ( NotClickingOnMinimap ( ) ) {
if ( NotClickingOnMinimap ( ) ) {
for ( auto & u : units ) {
for ( auto & u : units ) {
@ -482,7 +492,7 @@ bool VirusAttack::OnUserUpdate(float fElapsedTime){
}
}
}
}
u - > AttemptAttack ( u , closestUnit , units , debuffIcons , IMAGES ) ;
u - > AttemptAttack ( u , closestUnit , units , debuffIcons , IMAGES ) ;
u - > _Update ( this , SOUNDS , player_resources , enemy_resources ) ;
u - > _Update ( this , SOUNDS , player_resources , enemy_resources , queuedUnits ) ;
}
}
std : : erase_if ( units , [ & ] ( std : : shared_ptr < Unit > u ) {
std : : erase_if ( units , [ & ] ( std : : shared_ptr < Unit > u ) {
@ -495,6 +505,11 @@ bool VirusAttack::OnUserUpdate(float fElapsedTime){
}
}
} ) ;
} ) ;
for ( auto & queuedUnit : queuedUnits ) {
units . push_back ( std : : move ( queuedUnit ) ) ;
}
queuedUnits . clear ( ) ;
game . DrawPartialDecal ( { 0 , 0 } , CONSTANT : : WORLD_SIZE * CONSTANT : : TILE_SIZE , IMAGES [ 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 ) ;
@ -575,29 +590,51 @@ void VirusAttack::RenderFogOfWar(){
}
}
}
}
bool VirusAttack : : CanAfford ( std : : vector < Memory > & unitCosts ) {
bool VirusAttack : : CanAfford ( Resources & resources , std : : vector < Memory > & unitCosts ) {
for ( Memory & mem : unitCosts ) {
for ( Memory & mem : unitCosts ) {
switch ( mem . type ) {
switch ( mem . type ) {
case HEALTH : {
case HEALTH : {
if ( player_ resources. health < mem . size ) return false ;
if ( resources . health < mem . size ) return false ;
} break ;
} break ;
case ATKSPD : {
case ATKSPD : {
if ( player_ resources. atkSpd < mem . size ) return false ;
if ( resources . atkSpd < mem . size ) return false ;
} break ;
} break ;
case MOVESPD : {
case MOVESPD : {
if ( player_ resources. moveSpd < mem . size ) return false ;
if ( resources . moveSpd < mem . size ) return false ;
} break ;
} break ;
case RANGE : {
case RANGE : {
if ( player_ resources. range < mem . size ) return false ;
if ( resources . range < mem . size ) return false ;
} break ;
} break ;
case PROCEDURE : {
case PROCEDURE : {
if ( player_ resources. procedure < mem . size ) return false ;
if ( resources . procedure < mem . size ) return false ;
} break ;
} break ;
}
}
}
}
return true ;
return true ;
}
}
void VirusAttack : : ExpendResources ( Resources & resources , std : : vector < Memory > & unitCosts ) {
for ( Memory & mem : unitCosts ) {
switch ( mem . type ) {
case HEALTH : {
resources . health - = mem . size ;
} break ;
case ATKSPD : {
resources . atkSpd - = mem . size ;
} break ;
case MOVESPD : {
resources . moveSpd - = mem . size ;
} break ;
case RANGE : {
resources . range - = mem . size ;
} break ;
case PROCEDURE : {
resources . procedure - = mem . size ;
} break ;
}
}
}
int main ( )
int main ( )
{
{
VirusAttack app ;
VirusAttack app ;