From 0b2b51c70cdd739060f6d5af15e6c169f0a886f1 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Sun, 3 Sep 2023 13:25:35 -0500 Subject: [PATCH] Add in ability for enemies to help other enemies. --- olcCodeJam2023Entry/Scenario.cpp | 168 ++++++++++++++++++++++-- olcCodeJam2023Entry/Scenario.h | 2 + olcCodeJam2023Entry/Sound.h | 1 + olcCodeJam2023Entry/Unit.cpp | 110 ++++++++++++---- olcCodeJam2023Entry/Unit.h | 3 +- olcCodeJam2023Entry/VirusAttack.cpp | 196 +++++++++++++++++++++++++++- 6 files changed, 440 insertions(+), 40 deletions(-) diff --git a/olcCodeJam2023Entry/Scenario.cpp b/olcCodeJam2023Entry/Scenario.cpp index 77d2293..293a015 100644 --- a/olcCodeJam2023Entry/Scenario.cpp +++ b/olcCodeJam2023Entry/Scenario.cpp @@ -1,5 +1,6 @@ #include "Scenario.h" #include "TileManager.h" +#include "olcUTIL_Geometry2D.h" Scenario::Scenario(std::vector>&units,std::vector>&IMAGES,std::vector>&SOUNDS,std::string&objective,TileTransformedView&game,GameFlags&flags) @@ -44,8 +45,29 @@ void Scenario::RunAI(Resources&enemy_resources,std::vectorGetElapsedTime()); + std::weak_ptrbaseOfOperations; + for(auto&u:units){ + if(!u->IsFriendly()&&u->IsRAMBank()){ + baseOfOperations=u; + break; + } + } + if(baseOfOperations.expired()){ + for(auto&u:units){ + if(!u->IsFriendly()){ + baseOfOperations=u; + break; + } + } + } //See if there are collectors, if so send memory allocator units towards them. - for(auto cp:collectionPoints){ + if(!baseOfOperations.expired()){ + std::sort(collectionPoints.begin(),collectionPoints.end(),[&](std::shared_ptrcp1,std::shared_ptrcp2){ + geom2d::linetoCP1={cp1->pos,baseOfOperations.lock()->GetPos()}; + geom2d::linetoCP2={cp2->pos,baseOfOperations.lock()->GetPos()}; + return toCP1.length()attachedUnit.expired()){ if(cpCheckTimer.count(cp.get())==0||cpCheckTimer[cp.get()]<=0){ for(auto&u:units){ @@ -89,7 +111,7 @@ void Scenario::RunAI(Resources&enemy_resources,std::vector>&units,std::vectorIsAttached()){ + collectorsAttached++; + } + } + if(collectorsAttached>=2){ + std::shared_ptrtarget; + for(auto&u:units){ + if(u->IsRAMBank()){ + target=u; + } + } + state=7; + SOUNDS[Sound::ALARM]->PlayCentered(); + flags.playerInControl=false; + auto u1=std::make_shared(game.GetPGE(),vf2d{4*24,10*24},IMAGES,false); + auto u2=std::make_shared(game.GetPGE(),vf2d{4*24,10*24},IMAGES,false); + auto u3=std::make_shared(game.GetPGE(),vf2d{4*24,10*24},IMAGES,false); + units.push_back(u1); + units.push_back(u2); + units.push_back(u3); + u1->SetTargetUnit(target); + u2->SetTargetUnit(target); + u3->SetTargetUnit(target); + } + }break; + case 7:{ + SetCameraTarget({4*24,4*24}); + if(camera.ReachedTarget()){ + state=8; + SOUNDS[Sound::WIND]->PlayCentered(); + } + }break; + case 8:{ + DisplayBox("An ambush...? I, WHAT? -- THIS IS NOT-"); + if(box.bPressed){ + state=9; + box.SetVisible(false); + nextLevelTimer=5; + } + }break; + case 9:{ + nextLevelTimer=std::max(0.f,nextLevelTimer-game.GetPGE()->GetElapsedTime()); + if(nextLevelTimer==0){ + state=10; + } + }break; + case 10:{ + transitionToNextLevel=true; + state=11; + }break; } }; bool Stage4::MissionCompleted(){ @@ -525,6 +643,9 @@ bool Stage4::MissionCompleted(){ Stage5::Stage5(std::vector>&units,std::vector>&IMAGES,std::vector>&SOUNDS,std::string&objective,TileTransformedView&game,GameFlags&flags) :Scenario(units,IMAGES,SOUNDS,objective,game,flags){} void Stage5::Start(){ + SetCameraTarget({4*24,4*24},true); + flags.playerInControl=true; + SetObjective("Defeat all enemy RAM banks."); nextLevel=LevelName::STAGE6; }; void Stage5::Update(){ @@ -535,11 +656,19 @@ void Stage5::Update(){ } }; bool Stage5::MissionCompleted(){ - return false; + for(auto&u:units){ + if(!u->IsFriendly()&&u->IsRAMBank()){ + return false; + } + } + return true; } Stage6::Stage6(std::vector>&units,std::vector>&IMAGES,std::vector>&SOUNDS,std::string&objective,TileTransformedView&game,GameFlags&flags) :Scenario(units,IMAGES,SOUNDS,objective,game,flags){} void Stage6::Start(){ + SetCameraTarget({4*24,4*24},true); + flags.playerInControl=true; + SetObjective("Defeat all enemy RAM banks."); nextLevel=LevelName::STAGE7; }; void Stage6::Update(){ @@ -550,11 +679,19 @@ void Stage6::Update(){ } }; bool Stage6::MissionCompleted(){ - return false; + for(auto&u:units){ + if(!u->IsFriendly()&&u->IsRAMBank()){ + return false; + } + } + return true; } Stage7::Stage7(std::vector>&units,std::vector>&IMAGES,std::vector>&SOUNDS,std::string&objective,TileTransformedView&game,GameFlags&flags) :Scenario(units,IMAGES,SOUNDS,objective,game,flags){} void Stage7::Start(){ + SetCameraTarget({4*24,4*24},true); + flags.playerInControl=true; + SetObjective("Defeat all enemy units."); nextLevel=LevelName::STAGE8; }; void Stage7::Update(){ @@ -565,11 +702,19 @@ void Stage7::Update(){ } }; bool Stage7::MissionCompleted(){ - return false; + for(auto&u:units){ + if(!u->IsFriendly()){ + return false; + } + } + return true; } Stage8::Stage8(std::vector>&units,std::vector>&IMAGES,std::vector>&SOUNDS,std::string&objective,TileTransformedView&game,GameFlags&flags) :Scenario(units,IMAGES,SOUNDS,objective,game,flags){} void Stage8::Start(){ + SetCameraTarget({4*24,4*24},true); + flags.playerInControl=true; + SetObjective("Defeat all enemy units."); nextLevel=LevelName::FINISH; }; void Stage8::Update(){ @@ -580,5 +725,10 @@ void Stage8::Update(){ } }; bool Stage8::MissionCompleted(){ - return false; + for(auto&u:units){ + if(!u->IsFriendly()){ + return false; + } + } + return true; } \ No newline at end of file diff --git a/olcCodeJam2023Entry/Scenario.h b/olcCodeJam2023Entry/Scenario.h index fb5deb0..5758787 100644 --- a/olcCodeJam2023Entry/Scenario.h +++ b/olcCodeJam2023Entry/Scenario.h @@ -74,6 +74,8 @@ protected: class Stage4:public Scenario{ public: Stage4(std::vector>&units,std::vector>&IMAGES,std::vector>&SOUNDS,std::string&objective,TileTransformedView&game,GameFlags&flags); + int collectorsAttached=0; + float nextLevelTimer=0; protected: void Start(); void Update(); diff --git a/olcCodeJam2023Entry/Sound.h b/olcCodeJam2023Entry/Sound.h index 6f68ecd..dea10d7 100644 --- a/olcCodeJam2023Entry/Sound.h +++ b/olcCodeJam2023Entry/Sound.h @@ -25,5 +25,6 @@ namespace Sound{ DEAD1, DEAD2, DEAD3, + WIND, }; } \ No newline at end of file diff --git a/olcCodeJam2023Entry/Unit.cpp b/olcCodeJam2023Entry/Unit.cpp index 3e0bbdb..6c6e60c 100644 --- a/olcCodeJam2023Entry/Unit.cpp +++ b/olcCodeJam2023Entry/Unit.cpp @@ -588,28 +588,30 @@ void Unit::_DrawHud(TileTransformedView&game,std::vector>&IMAGES){ - if(!target.expired()){ - geom2d::linelineToTarget(pos,target.lock()->pos); - lineToTarget.start=lineToTarget.rpoint(GetUnitSize().x/2); - lineToTarget.end=lineToTarget.rpoint(lineToTarget.length()-GetUnitSize().x/4); - util::ApplyMatrixEffect(game.GetPGE(),targetingLine,*IMAGES[TARGETING_LINE],IMAGES[MATRIX]); - game.DrawPartialRotatedDecal(lineToTarget.upoint(0.5),targetingLine.Decal(),lineToTarget.vector().polar().y,{lineToTarget.length()/2,12},{lineShift*10,0},{lineToTarget.length(),24},{1,1},targetLineCol); - } else - if(targetLoc!=CONSTANT::UNSELECTED){ - geom2d::linelineToTarget(pos,targetLoc); - lineToTarget.start=lineToTarget.rpoint(GetUnitSize().x/2); - lineToTarget.end=lineToTarget.rpoint(lineToTarget.length()-GetUnitSize().x/4); - util::ApplyMatrixEffect(game.GetPGE(),targetingLine,*IMAGES[TARGETING_LINE],IMAGES[MATRIX]); - game.DrawPartialRotatedDecal(lineToTarget.upoint(0.5),targetingLine.Decal(),lineToTarget.vector().polar().y,{lineToTarget.length()/2,12},{lineShift*10,0},{lineToTarget.length(),24},{1,0.6},CONSTANT::MOVE_LINE_COL); - } - if(!appliedTarget.expired()){ - geom2d::linelineToTarget(pos,appliedTarget.lock()->pos); - lineToTarget.start=lineToTarget.rpoint(GetUnitSize().x/2); - lineToTarget.end=lineToTarget.rpoint(lineToTarget.length()-GetUnitSize().x/4); - if(reloadTimer>0){ - util::ApplyMatrixEffect(game.GetPGE(),attackingLine,*IMAGES[ATTACKING_LINE],IMAGES[MATRIX]); - float reloadSpd=1.f/(GetAtkSpd()/2.f); - game.DrawPartialRotatedDecal(lineToTarget.upoint(0.5),attackingLine.Decal(),lineToTarget.vector().polar().y,{lineToTarget.length()/2,12},{lineShift*30,0},{lineToTarget.length(),24},{1,1+(attackFailed?-0.3f:(reloadTimer/reloadSpd)*0.25f)},attackFailed?Pixel{192,192,192,130}:Pixel{attackingLineCol.r,attackingLineCol.g,attackingLineCol.b,uint8_t(IsFriendly()?200:160)}); + if(!InFogOfWar()){ + if(!target.expired()){ + geom2d::linelineToTarget(pos,target.lock()->pos); + lineToTarget.start=lineToTarget.rpoint(GetUnitSize().x/2); + lineToTarget.end=lineToTarget.rpoint(lineToTarget.length()-GetUnitSize().x/4); + util::ApplyMatrixEffect(game.GetPGE(),targetingLine,*IMAGES[TARGETING_LINE],IMAGES[MATRIX]); + game.DrawPartialRotatedDecal(lineToTarget.upoint(0.5),targetingLine.Decal(),lineToTarget.vector().polar().y,{lineToTarget.length()/2,12},{lineShift*10,0},{lineToTarget.length(),24},{1,1},targetLineCol); + } else + if(targetLoc!=CONSTANT::UNSELECTED){ + geom2d::linelineToTarget(pos,targetLoc); + lineToTarget.start=lineToTarget.rpoint(GetUnitSize().x/2); + lineToTarget.end=lineToTarget.rpoint(lineToTarget.length()-GetUnitSize().x/4); + util::ApplyMatrixEffect(game.GetPGE(),targetingLine,*IMAGES[TARGETING_LINE],IMAGES[MATRIX]); + game.DrawPartialRotatedDecal(lineToTarget.upoint(0.5),targetingLine.Decal(),lineToTarget.vector().polar().y,{lineToTarget.length()/2,12},{lineShift*10,0},{lineToTarget.length(),24},{1,0.6},CONSTANT::MOVE_LINE_COL); + } + if(!appliedTarget.expired()){ + geom2d::linelineToTarget(pos,appliedTarget.lock()->pos); + lineToTarget.start=lineToTarget.rpoint(GetUnitSize().x/2); + lineToTarget.end=lineToTarget.rpoint(lineToTarget.length()-GetUnitSize().x/4); + if(reloadTimer>0){ + util::ApplyMatrixEffect(game.GetPGE(),attackingLine,*IMAGES[ATTACKING_LINE],IMAGES[MATRIX]); + float reloadSpd=1.f/(GetAtkSpd()/2.f); + game.DrawPartialRotatedDecal(lineToTarget.upoint(0.5),attackingLine.Decal(),lineToTarget.vector().polar().y,{lineToTarget.length()/2,12},{lineShift*30,0},{lineToTarget.length(),24},{1,1+(attackFailed?-0.3f:(reloadTimer/reloadSpd)*0.25f)},attackFailed?Pixel{192,192,192,130}:Pixel{attackingLineCol.r,attackingLineCol.g,attackingLineCol.b,uint8_t(IsFriendly()?200:160)}); + } } } float dist=geom2d::line(game.ScreenToWorld(pge->GetMousePos()),GetGhostPos()).length(); @@ -701,7 +703,7 @@ void Unit::_RunAI(PixelGameEngine*pge){ RunAI(pge); } -void Unit::_Update(PixelGameEngine*pge,std::vector>&SOUNDS,Resources&player_resources,Resources&enemy_resources,std::vector>&queuedUnits,std::array&resourceGainTimer,std::vector&resourceGainIcons,std::vector>&IMAGES){ +void Unit::_Update(PixelGameEngine*pge,std::vector>&SOUNDS,Resources&player_resources,Resources&enemy_resources,std::vector>&queuedUnits,std::array&resourceGainTimer,std::vector&resourceGainIcons,std::vector>&IMAGES,GameFlags&flags){ if(!target.expired()){ auto ptrTarget=target.lock(); if(!InRange(ptrTarget)&&CanMove()){ @@ -731,22 +733,69 @@ void Unit::_Update(PixelGameEngine*pge,std::vector>&SOUND Resources&targetResource=IsFriendly()?player_resources:enemy_resources; switch(attachedPoint.lock()->type){ case HEALTH:{ + if(!IsFriendly()&&flags.difficulty==2){ + targetResource.health+=3; + } + if(!IsFriendly()&&flags.difficulty==1){ + targetResource.health++; + } + if(!IsFriendly()&&flags.difficulty==0){ + targetResource.health--; + } targetResource.health++; }break; case RANGE:{ + if(!IsFriendly()&&flags.difficulty==2){ + targetResource.range+=3; + } + if(!IsFriendly()&&flags.difficulty==1){ + targetResource.range++; + } + if(!IsFriendly()&&flags.difficulty==0){ + targetResource.range--; + } targetResource.range++; }break; case ATKSPD:{ + if(!IsFriendly()&&flags.difficulty==2){ + targetResource.atkSpd+=3; + } + if(!IsFriendly()&&flags.difficulty==1){ + targetResource.atkSpd++; + } + if(!IsFriendly()&&flags.difficulty==0){ + targetResource.atkSpd--; + } targetResource.atkSpd++; }break; case MOVESPD:{ + if(!IsFriendly()&&flags.difficulty==2){ + targetResource.moveSpd+=3; + } + if(!IsFriendly()&&flags.difficulty==1){ + targetResource.moveSpd++; + } + if(!IsFriendly()&&flags.difficulty==0){ + targetResource.moveSpd--; + } targetResource.moveSpd++; }break; case PROCEDURE:{ + if(!IsFriendly()&&flags.difficulty==2){ + targetResource.procedure+=3; + } + if(!IsFriendly()&&flags.difficulty==1){ + targetResource.procedure++; + } + if(!IsFriendly()&&flags.difficulty==0){ + targetResource.procedure--; + } targetResource.procedure++; }break; } - resourceGainIcons.push_back({IMAGES[RESOURCE].get(),attachedPoint.lock()->type,GetPos()}); + if(!InFogOfWar()){ + resourceGainIcons.push_back({IMAGES[RESOURCE].get(),attachedPoint.lock()->type,GetPos()}); + } } } @@ -909,6 +958,19 @@ void Unit::_Attack(std::weak_ptrattacker,std::weak_ptrfinalTarget,st if(finalTarget.lock()->IsFriendly()!=IsFriendly()&&CanInteractWithEnemies()){ SetTargetUnit(finalTarget); } + for(auto&u:otherUnits){ + if(this!=u.get()&&!u->IsFriendly()&&u->GetCurrentTarget().expired()){ + geom2d::linedistLine={GetPos(),u->GetPos()}; + if(distLine.length()<200){ + if(u->CanInteractWithEnemies()){ + u->SetTargetUnit(finalTarget); + }else + if(u->CanInteractWithAllies()){ + u->SetTargetLocation(GetPos()); + } + } + } + } } } else { reloadTimer=1.f/(GetAtkSpd()/2.f); diff --git a/olcCodeJam2023Entry/Unit.h b/olcCodeJam2023Entry/Unit.h index 14791cc..e60fa38 100644 --- a/olcCodeJam2023Entry/Unit.h +++ b/olcCodeJam2023Entry/Unit.h @@ -11,6 +11,7 @@ #include "Resources.h" #include "Textbox.h" #include "Memory.h" +#include "GameFlags.h" #include "olcPGEX_QuickGUI.h" enum class UnitType{ @@ -68,7 +69,7 @@ public: bool GhostInFogOfWar(); void HideGhost(); vf2d GetGhostPos(); - void _Update(PixelGameEngine*pge,std::vector>&SOUNDS,Resources&player_resources,Resources&enemy_resources,std::vector>&queuedUnits,std::array&resourceGainTimer,std::vector&resourceGainIcons,std::vector>&IMAGES); + void _Update(PixelGameEngine*pge,std::vector>&SOUNDS,Resources&player_resources,Resources&enemy_resources,std::vector>&queuedUnits,std::array&resourceGainTimer,std::vector&resourceGainIcons,std::vector>&IMAGES,GameFlags&flags); bool IsMoveable(); void DrawRangeIndicator(PixelGameEngine*pge,TileTransformedView&game,std::vector>&IMAGES); bool CanInteractWithEnemies(); diff --git a/olcCodeJam2023Entry/VirusAttack.cpp b/olcCodeJam2023Entry/VirusAttack.cpp index 84d06ea..741a5cb 100644 --- a/olcCodeJam2023Entry/VirusAttack.cpp +++ b/olcCodeJam2023Entry/VirusAttack.cpp @@ -189,7 +189,7 @@ void VirusAttack::InitializeLevelData(){ levelData[stage].worldZoom={1,1}; levelData[stage].size={36,36}; levelData[stage].levelColor=DARK_GREEN; - levelData[stage].bgm=Sound::GRAVITY; + levelData[stage].bgm=Sound::COSMOS; levelData[stage].scenarioIndex=int(stage); levelData[stage].availableMemory=300; levelData[stage].player_starting_resources={3,0,0,0,0}; @@ -203,14 +203,184 @@ void VirusAttack::InitializeLevelData(){ units.push_back({UnitType::MemoryAllocator,vf2d{4*24,6*24},true}); } + collectionPoints.push_back(CPData{{8*24,1*24},0,MemoryType::HEALTH}); + collectionPoints.push_back(CPData{{9*24,1*24},0,MemoryType::HEALTH}); + collectionPoints.push_back(CPData{{12*24,1*24},0,MemoryType::PROCEDURE}); + collectionPoints.push_back(CPData{{15*24,1*24},0,MemoryType::PROCEDURE}); + collectionPoints.push_back(CPData{{1*24,12*24},-PI/2,MemoryType::RANGE}); + collectionPoints.push_back(CPData{{1*24,13*24},-PI/2,MemoryType::ATKSPD}); + collectionPoints.push_back(CPData{{1*24,17*24},-PI/2,MemoryType::MOVESPD}); + collectionPoints.push_back(CPData{{1*24,20*24},-PI/2,MemoryType::RANGE}); + + } + } + #pragma endregion +#pragma region Stage 5 + { + //Stage 5 data. + LevelName stage=STAGE5; + levelData[stage].name=stage; + levelData[stage].cameraStart={96,96}; + levelData[stage].worldZoom={1,1}; + levelData[stage].size={48,48}; + levelData[stage].levelColor=DARK_GREY; + levelData[stage].bgm=Sound::BOSS1; + levelData[stage].scenarioIndex=int(stage); + levelData[stage].availableMemory=640; + levelData[stage].player_starting_resources={5,5,5,5,5}; + levelData[stage].enemy_starting_resources={5,5,5,5,5}; + { + std::vector&units=levelData[stage].unitPlacement; + std::vector&collectionPoints=levelData[stage].cpPlacement; + + units.push_back({UnitType::RAMBank,vf2d{4*24,4*24},true}); + for(int i=0;i<5;i++){ + units.push_back({UnitType::MemoryAllocator,vf2d{4*24,6*24},true}); + } + + collectionPoints.push_back(CPData{{8*24,1*24},0,MemoryType::HEALTH}); + collectionPoints.push_back(CPData{{10*24,1*24},0,MemoryType::HEALTH}); + collectionPoints.push_back(CPData{{32*24,12*24},0,MemoryType::HEALTH}); + collectionPoints.push_back(CPData{{20*24,32*24},0,MemoryType::HEALTH}); + collectionPoints.push_back(CPData{{9*24,1*24},0,MemoryType::PROCEDURE}); + collectionPoints.push_back(CPData{{1*24,7*24},-PI/2,MemoryType::PROCEDURE}); + collectionPoints.push_back(CPData{{16*24,16*24},0,MemoryType::PROCEDURE}); + collectionPoints.push_back(CPData{{36*24,1*24},-PI/2,MemoryType::PROCEDURE}); + collectionPoints.push_back(CPData{{1*24,3*24},-PI/2,MemoryType::RANGE}); + collectionPoints.push_back(CPData{{1*24,6*24},-PI/2,MemoryType::ATKSPD}); + collectionPoints.push_back(CPData{{1*24,11*24},-PI/2,MemoryType::MOVESPD}); + collectionPoints.push_back(CPData{{1*24,22*24},-PI/2,MemoryType::RANGE}); + collectionPoints.push_back(CPData{{6*24,16*24},-PI/2,MemoryType::ATKSPD}); + collectionPoints.push_back(CPData{{1*24,32*24},-PI/2,MemoryType::MOVESPD}); + collectionPoints.push_back(CPData{{(48-1)*24,(48-4)*24},PI/2,MemoryType::RANGE}); + collectionPoints.push_back(CPData{{(48-1)*24,(48-7)*24},PI/2,MemoryType::ATKSPD}); + collectionPoints.push_back(CPData{{(48-1)*24,(48-12)*24},PI/2,MemoryType::MOVESPD}); + collectionPoints.push_back(CPData{{(48-1)*24,(48-23)*24},PI/2,MemoryType::RANGE}); + collectionPoints.push_back(CPData{{(48-6)*24,(48-17)*24},PI/2,MemoryType::ATKSPD}); + collectionPoints.push_back(CPData{{(48-1)*24,(48-33)*24},PI/2,MemoryType::MOVESPD}); + + collectionPoints.push_back(CPData{{(48-8)*24,(48-2)*24},PI,MemoryType::HEALTH}); + collectionPoints.push_back(CPData{{(48-10)*24,(48-2)*24},PI,MemoryType::HEALTH}); + collectionPoints.push_back(CPData{{(48-32)*24,(48-13)*24},PI,MemoryType::HEALTH}); + collectionPoints.push_back(CPData{{(48-20)*24,(48-33)*24},PI,MemoryType::HEALTH}); + collectionPoints.push_back(CPData{{(48-9)*24,(48-2)*24},PI,MemoryType::PROCEDURE}); + collectionPoints.push_back(CPData{{(48-1)*24,(48-8)*24},PI/2,MemoryType::PROCEDURE}); + collectionPoints.push_back(CPData{{(48-16)*24,(48-17)*24},PI,MemoryType::PROCEDURE}); + collectionPoints.push_back(CPData{{(48-36)*24,(48-2)*24},PI/2,MemoryType::PROCEDURE}); for(int i=0;i<5;i++){ - units.push_back({UnitType::MemoryAllocator,vf2d{4*24,30*24},false}); + units.push_back({UnitType::MemoryAllocator,vf2d{44*24,44*24},false}); } - units.push_back({UnitType::RAMBank,vf2d{4*24,32*24},false}); + units.push_back({UnitType::Turret,vf2d{42*24,42*24},false}); + units.push_back({UnitType::LeftShifter,vf2d{42*24,44*24},false}); + units.push_back({UnitType::LeftShifter,vf2d{42*24,44*24},false}); + units.push_back({UnitType::Corrupter,vf2d{42*24,44*24},false}); + units.push_back({UnitType::RightShifter,vf2d{42*24,44*24},false}); + units.push_back({UnitType::RightShifter,vf2d{45*24,41*24},false}); + units.push_back({UnitType::RAMBank,vf2d{44*24,44*24},false}); } } - #pragma endregion +#pragma endregion +#pragma region Stage 6 + { + //Stage 6 data. + LevelName stage=STAGE6; + levelData[stage].name=stage; + levelData[stage].cameraStart={96,96}; + levelData[stage].worldZoom={1,1}; + levelData[stage].size={48,48}; + levelData[stage].levelColor=DARK_GREY; + levelData[stage].bgm=Sound::BOSS1; + levelData[stage].scenarioIndex=int(stage); + levelData[stage].availableMemory=640; + levelData[stage].player_starting_resources={5,5,5,5,5}; + levelData[stage].enemy_starting_resources={5,5,5,5,5}; + { + std::vector&units=levelData[stage].unitPlacement; + std::vector&collectionPoints=levelData[stage].cpPlacement; + + units.push_back({UnitType::RAMBank,vf2d{4*24,4*24},true}); + for(int i=0;i<5;i++){ + units.push_back({UnitType::MemoryAllocator,vf2d{4*24,6*24},true}); + } + + std::vectorpositions={ + {{8,1},{10,1},{32,12},{20,32},{9,1},{1,7},{16,16} + ,{36,1},{1,3},{1,6},{1,11},{1,22},{6,16},{1,32}} + }; + std::vectortypes={ + {MemoryType::HEALTH,MemoryType::HEALTH,MemoryType::HEALTH,MemoryType::HEALTH,MemoryType::PROCEDURE, + MemoryType::PROCEDURE,MemoryType::PROCEDURE,MemoryType::PROCEDURE,MemoryType::RANGE, + MemoryType::ATKSPD,MemoryType::MOVESPD,MemoryType::RANGE,MemoryType::ATKSPD,MemoryType::MOVESPD,} + }; + if(positions.size()!=types.size()){ + throw; + } + while(positions.size()>0){ + int randomIndex=rand()%positions.size(); + int randomIndex2=rand()%types.size(); + float finalDir=0; + if(positions[randomIndex].xpositions[randomIndex].x){ + finalDir=PI; + }else{ + finalDir=PI/2; + } + } + collectionPoints.push_back(CPData{positions[randomIndex]*24,finalDir,types[randomIndex2]}); + collectionPoints.push_back(CPData{(levelData[stage].size-positions[randomIndex]-vf2d{1,1})*24,float(finalDir+PI),types[randomIndex2]}); + positions.erase(positions.begin()+randomIndex); + types.erase(types.begin()+randomIndex2); + } + collectionPoints.push_back(CPData{{8*24,1*24},0,MemoryType::HEALTH}); + collectionPoints.push_back(CPData{{10*24,1*24},0,MemoryType::HEALTH}); + collectionPoints.push_back(CPData{{32*24,12*24},0,MemoryType::HEALTH}); + collectionPoints.push_back(CPData{{20*24,32*24},0,MemoryType::HEALTH}); + collectionPoints.push_back(CPData{{9*24,1*24},0,MemoryType::PROCEDURE}); + collectionPoints.push_back(CPData{{1*24,7*24},-PI/2,MemoryType::PROCEDURE}); + collectionPoints.push_back(CPData{{16*24,16*24},0,MemoryType::PROCEDURE}); + collectionPoints.push_back(CPData{{36*24,1*24},-PI/2,MemoryType::PROCEDURE}); + collectionPoints.push_back(CPData{{1*24,3*24},-PI/2,MemoryType::RANGE}); + collectionPoints.push_back(CPData{{1*24,6*24},-PI/2,MemoryType::ATKSPD}); + collectionPoints.push_back(CPData{{1*24,11*24},-PI/2,MemoryType::MOVESPD}); + collectionPoints.push_back(CPData{{1*24,22*24},-PI/2,MemoryType::RANGE}); + collectionPoints.push_back(CPData{{6*24,16*24},-PI/2,MemoryType::ATKSPD}); + collectionPoints.push_back(CPData{{1*24,32*24},-PI/2,MemoryType::MOVESPD}); + collectionPoints.push_back(CPData{{(48-1)*24,(48-4)*24},PI/2,MemoryType::RANGE}); + collectionPoints.push_back(CPData{{(48-1)*24,(48-7)*24},PI/2,MemoryType::ATKSPD}); + collectionPoints.push_back(CPData{{(48-1)*24,(48-12)*24},PI/2,MemoryType::MOVESPD}); + collectionPoints.push_back(CPData{{(48-1)*24,(48-23)*24},PI/2,MemoryType::RANGE}); + collectionPoints.push_back(CPData{{(48-6)*24,(48-17)*24},PI/2,MemoryType::ATKSPD}); + collectionPoints.push_back(CPData{{(48-1)*24,(48-33)*24},PI/2,MemoryType::MOVESPD}); + + collectionPoints.push_back(CPData{{(48-8)*24,(48-2)*24},PI,MemoryType::HEALTH}); + collectionPoints.push_back(CPData{{(48-10)*24,(48-2)*24},PI,MemoryType::HEALTH}); + collectionPoints.push_back(CPData{{(48-32)*24,(48-13)*24},PI,MemoryType::HEALTH}); + collectionPoints.push_back(CPData{{(48-20)*24,(48-33)*24},PI,MemoryType::HEALTH}); + collectionPoints.push_back(CPData{{(48-9)*24,(48-2)*24},PI,MemoryType::PROCEDURE}); + collectionPoints.push_back(CPData{{(48-1)*24,(48-8)*24},PI/2,MemoryType::PROCEDURE}); + collectionPoints.push_back(CPData{{(48-16)*24,(48-17)*24},PI,MemoryType::PROCEDURE}); + collectionPoints.push_back(CPData{{(48-36)*24,(48-2)*24},PI/2,MemoryType::PROCEDURE}); + + for(int i=0;i<5;i++){ + units.push_back({UnitType::MemoryAllocator,vf2d{44*24,44*24},false}); + } + units.push_back({UnitType::Turret,vf2d{42*24,42*24},false}); + units.push_back({UnitType::LeftShifter,vf2d{42*24,44*24},false}); + units.push_back({UnitType::LeftShifter,vf2d{42*24,44*24},false}); + units.push_back({UnitType::Corrupter,vf2d{42*24,44*24},false}); + units.push_back({UnitType::RightShifter,vf2d{42*24,44*24},false}); + units.push_back({UnitType::RightShifter,vf2d{45*24,41*24},false}); + units.push_back({UnitType::RAMBank,vf2d{44*24,44*24},false}); + } + } +#pragma endregion } bool VirusAttack::OnUserCreate(){ @@ -241,7 +411,8 @@ bool VirusAttack::OnUserCreate(){ InitializeScenarios(); InitializeLevelData(); - LoadLevel(STAGE1); + LoadLevel(STAGE5); + levelToLoad=STAGE5; return true; } @@ -384,6 +555,7 @@ void VirusAttack::InitializeSounds(){ LoadSound(Sound::DEAD1,"dead1.mp3"); LoadSound(Sound::DEAD2,"dead2.mp3"); LoadSound(Sound::DEAD3,"dead3.mp3"); + LoadSound(Sound::WIND,"wind.mp3"); } bool VirusAttack::UnitCreationClickHandled(){ @@ -561,6 +733,18 @@ void VirusAttack::HandleRightClickMove(){ } void VirusAttack::CollisionChecking(std::shared_ptru,std::shared_ptru2){ + if(u->GetPos().x<0){ + u->SetPos({0,u->GetPos().y}); + } + if(u->GetPos().x>WORLD_SIZE.x*CONSTANT::TILE_SIZE.x){ + u->SetPos({float(WORLD_SIZE.x*CONSTANT::TILE_SIZE.x),u->GetPos().y}); + } + if(u->GetPos().y<0){ + u->SetPos({u->GetPos().y,0}); + } + if(u->GetPos().y>WORLD_SIZE.y*CONSTANT::TILE_SIZE.y){ + u->SetPos({u->GetPos().x,float(WORLD_SIZE.y*CONSTANT::TILE_SIZE.y)}); + } if(u!=u2&&geom2d::overlaps(geom2d::circle(u->GetPos(),u->GetUnitSize().x/2),geom2d::circle(u2->GetPos(),u2->GetUnitSize().x/2))){ geom2d::linecollisionLine(u->GetPos(),u2->GetPos()+vf2d{0.001,0.001}); float maxDist=u->GetUnitSize().x/2+u2->GetUnitSize().x/2; @@ -928,7 +1112,7 @@ bool VirusAttack::OnUserUpdate(float fElapsedTime){ } } u->AttemptAttack(u,closestUnit,units,debuffIcons,IMAGES,SOUNDS); - u->_Update(this,SOUNDS,player_resources,enemy_resources,queuedUnits,resourceGainTimer,resourceGainIcons,IMAGES); + u->_Update(this,SOUNDS,player_resources,enemy_resources,queuedUnits,resourceGainTimer,resourceGainIcons,IMAGES,flags); } std::erase_if(units,[&](std::shared_ptru){