#include "Scenario.h" #include "TileManager.h" Scenario::Scenario(VirusAttack*game) :game(game){ } void Scenario::Start(){} void Scenario::_Update(){ initialWaitTimer=std::max(0.f,initialWaitTimer-game->GetElapsedTime()); waitToContinueTimer=std::max(0.f,waitToContinueTimer-game->GetElapsedTime()); if(missionCompleted){ missionCompletedTimer+=game->GetElapsedTime(); if(game->GetKey(SPACE).bPressed){ NextLevel(); } } if(!missionCompleted&&MissionCompleted()){ missionCompleted=true; waitToContinueTimer=3; } Update(); } void Scenario::_Draw(){ if(game->objective.length()>0){ game->DrawShadowStringDecal({4,24},missionCompleted?"Objective Complete!":"Objective:",missionCompleted?GREEN:WHITE); vf2d textSize=game->GetTextSize(game->objective); game->DrawShadowStringDecal({6,36},game->objective,missionCompleted?GREEN:WHITE); if(missionCompleted&&initialWaitTimer==0){ game->FillRectDecal(vf2d{6,36}+vf2d{0,textSize.y/2-1},{textSize.x,3}); std::string continueText="< Press [Spacebar] to continue >"; vf2d textScale={2,3}; vf2d textSize=game->GetTextSizeProp(continueText)*textScale; game->DrawShadowStringPropDecal(game->GetScreenSize()/2-textSize/2+vf2d{0,72},continueText,{255,255,255,uint8_t(abs(sin(2*missionCompletedTimer))*255)},{0,0,0,uint8_t(abs(sin(2*missionCompletedTimer))*255)},textScale); } } Draw(); } void Scenario::DisplayDialog(std::string dialogText,bool spooky){ dialog.Initialize(dialogText,{24,64},"",spooky?game->IMAGES[SPOOK_HOODED_FIGURE].get():game->IMAGES[HOODED_FIGURE].get(),{378,28},game->SOUNDS[Sound::VOICEOVER].get()); } void Scenario::SetObjective(std::string objective){ game->objective=objective; } void Scenario::SetupCameraTarget(vf2d pos){ cameraTargetPos=pos; camera.SetTarget(cameraTargetPos); } void Scenario::MoveCamera(){ game->game.SetWorldOffset(camera.GetViewPosition()); camera.Update(game->GetElapsedTime()); } void Scenario::NextLevel(){} Stage1::Stage1(VirusAttack*game) :Scenario(game){} void Stage1::Start(){ state=0; missionCompleted=false; dialog.SetVisible(false); game->unitMetersGreyedOut=true; game->playerInControl=false; game->guideEnabled=false; camera=utils::Camera2D(game->GetScreenSize(),game->game.GetWorldOffset()); camera.SetLazyFollowRate(1); camera.SetMode(utils::Camera2D::Mode::LazyFollow); } void Stage1::Update(){ switch(state){ case 0:{ DisplayDialog("Hello Hacker, thank you for taking on this request for me."); if(dialog.bPressed){ dialog.SetVisible(false); state=1; } }break; case 1:{ DisplayDialog("It appears we have no time to waste, most sectors are already infected and it will just keep getting worse over time."); if(dialog.bPressed){ dialog.SetVisible(false); state=2; } }break; case 2:{ game->SOUNDS[Sound::PING]->PlayCentered(); SetupCameraTarget({320,320}); state=3; }break; case 3:{ for(int y=-1;y<=1;y++){ for(int x=-1;x<=1;x++){ vi2d basePos={320+x*96,320+y*96}; TileManager::visibleTiles[{basePos.x/96,basePos.y/96}]=30; } } MoveCamera(); if(camera.ReachedTarget()){ state=4; } }break; case 4:{ DisplayDialog("Your mission is to take out all the RAM banks from the system, this will stop any further creation and spread of viruses."); if(dialog.bPressed){ dialog.SetVisible(false); SetupCameraTarget({128,128}); state=5; } }break; case 5:{ MoveCamera(); if(camera.ReachedTarget()){ state=6; } }break; case 6:{ DisplayDialog("The yellow bars represent a unit's Health memory allocation. Eliminate it from enemies, and make sure you have at least 1 bit of it."); if(dialog.bPressed){ state=7; } }break; case 7:{ DisplayDialog("Drag over your target unit and then select a target location via right-click."); if(dialog.bPressed){ state=8; } }break; case 8:{ DisplayDialog("That should be all you need for now. I'll be back after my coffee break."); SetObjective("Defeat the RAM bank"); if(dialog.bPressed){ dialog.SetVisible(false); game->playerInControl=true; state=9; } }break; } } bool Stage1::MissionCompleted(){ for(auto&u:game->units){ if(!u->IsFriendly()&&u->IsRAMBank()){ return false; } } return true; } void Stage1::Draw(){ dialog.UpdateAndDraw({24,64},game,game->player_resources,game->IMAGES,game->GetTotalUsedMemory(),game->currentLevel->availableMemory); } void Stage1::NextLevel(){ game->levelToLoad=STAGE2; } Stage2::Stage2(VirusAttack*game) :Scenario(game){} void Stage2::Start(){ state=0; missionCompleted=false; dialog.SetVisible(false); game->unitMetersGreyedOut=true; game->limitedBuildOptions=true; game->guideEnabled=false; game->playerInControl=false; camera=utils::Camera2D(game->GetScreenSize(),game->game.GetWorldOffset()); camera.SetLazyFollowRate(1); camera.SetMode(utils::Camera2D::Mode::LazyFollow); } void Stage2::Update(){ switch(state){ case 0:{ DisplayDialog("I am the test dialog."); if(dialog.bPressed){ dialog.SetVisible(false); state=1; } }break; } } bool Stage2::MissionCompleted(){ for(auto&u:game->units){ if(!u->IsFriendly()&&u->IsRAMBank()){ return false; } } return true; } void Stage2::Draw(){ dialog.UpdateAndDraw({24,64},game,game->player_resources,game->IMAGES,game->GetTotalUsedMemory(),game->currentLevel->availableMemory); } void Stage2::NextLevel(){ game->levelToLoad=STAGE3; } Stage3::Stage3(VirusAttack*game) :Scenario(game){} void Stage3::Start(){ state=0; missionCompleted=false; dialog.SetVisible(false); game->unitMetersGreyedOut=false; game->limitedBuildOptions=true; game->guideEnabled=false; game->playerInControl=false; camera=utils::Camera2D(game->GetScreenSize(),game->game.GetWorldOffset()); camera.SetLazyFollowRate(1); camera.SetMode(utils::Camera2D::Mode::LazyFollow); } void Stage3::Update(){ switch(state){ case 0:{ DisplayDialog("I am the test dialog."); if(dialog.bPressed){ dialog.SetVisible(false); state=1; } }break; } } bool Stage3::MissionCompleted(){ for(auto&u:game->units){ if(!u->IsFriendly()&&u->IsRAMBank()){ return false; } } return true; } void Stage3::Draw(){ dialog.UpdateAndDraw({24,64},game,game->player_resources,game->IMAGES,game->GetTotalUsedMemory(),game->currentLevel->availableMemory); } void Stage3::NextLevel(){ game->levelToLoad=STAGE4; } Stage4::Stage4(VirusAttack*game) :Scenario(game){} void Stage4::Start(){ state=0; missionCompleted=false; dialog.SetVisible(false); game->unitMetersGreyedOut=false; game->limitedBuildOptions=false; game->guideEnabled=true; game->playerInControl=false; camera=utils::Camera2D(game->GetScreenSize(),game->game.GetWorldOffset()); camera.SetLazyFollowRate(1); camera.SetMode(utils::Camera2D::Mode::LazyFollow); } void Stage4::Update(){ switch(state){ case 0:{ DisplayDialog("I am the test dialog."); if(dialog.bPressed){ dialog.SetVisible(false); state=1; } }break; } } bool Stage4::MissionCompleted(){ for(auto&u:game->units){ if(!u->IsFriendly()&&u->IsRAMBank()){ return false; } } return true; } void Stage4::Draw(){ dialog.UpdateAndDraw({24,64},game,game->player_resources,game->IMAGES,game->GetTotalUsedMemory(),game->currentLevel->availableMemory); } void Stage4::NextLevel(){ game->levelToLoad=STAGE5; } Stage5::Stage5(VirusAttack*game) :Scenario(game){} void Stage5::Start(){ state=0; missionCompleted=false; dialog.SetVisible(false); game->unitMetersGreyedOut=false; game->limitedBuildOptions=false; game->guideEnabled=true; game->playerInControl=true; camera=utils::Camera2D(game->GetScreenSize(),game->game.GetWorldOffset()); camera.SetLazyFollowRate(1); camera.SetMode(utils::Camera2D::Mode::LazyFollow); } void Stage5::Update(){ switch(state){ case 0:{ SetObjective("Defeat all enemy units."); state=1; }break; } } bool Stage5::MissionCompleted(){ for(auto&u:game->units){ if(!u->IsFriendly()&&u->IsRAMBank()){ return false; } } return true; } void Stage5::Draw(){ dialog.UpdateAndDraw({24,64},game,game->player_resources,game->IMAGES,game->GetTotalUsedMemory(),game->currentLevel->availableMemory); } void Stage5::NextLevel(){ game->levelToLoad=STAGE6; } Stage6::Stage6(VirusAttack*game) :Scenario(game){} void Stage6::Start(){ state=0; missionCompleted=false; dialog.SetVisible(false); game->unitMetersGreyedOut=false; game->limitedBuildOptions=false; game->guideEnabled=true; game->playerInControl=true; camera=utils::Camera2D(game->GetScreenSize(),game->game.GetWorldOffset()); camera.SetLazyFollowRate(1); camera.SetMode(utils::Camera2D::Mode::LazyFollow); } void Stage6::Update(){ switch(state){ case 0:{ SetObjective("Defeat all enemy units."); state=1; }break; } } bool Stage6::MissionCompleted(){ for(auto&u:game->units){ if(!u->IsFriendly()&&u->IsRAMBank()){ return false; } } return true; } void Stage6::Draw(){ dialog.UpdateAndDraw({24,64},game,game->player_resources,game->IMAGES,game->GetTotalUsedMemory(),game->currentLevel->availableMemory); } void Stage6::NextLevel(){ game->levelToLoad=STAGE7; } Stage7::Stage7(VirusAttack*game) :Scenario(game){} void Stage7::Start(){ state=0; missionCompleted=false; dialog.SetVisible(false); game->unitMetersGreyedOut=false; game->limitedBuildOptions=false; game->guideEnabled=true; game->playerInControl=true; camera=utils::Camera2D(game->GetScreenSize(),game->game.GetWorldOffset()); camera.SetLazyFollowRate(1); camera.SetMode(utils::Camera2D::Mode::LazyFollow); } void Stage7::Update(){ switch(state){ case 0:{ SetObjective("Defeat all enemy units."); state=1; }break; } } bool Stage7::MissionCompleted(){ for(auto&u:game->units){ if(!u->IsFriendly()&&u->IsRAMBank()){ return false; } } return true; } void Stage7::Draw(){ dialog.UpdateAndDraw({24,64},game,game->player_resources,game->IMAGES,game->GetTotalUsedMemory(),game->currentLevel->availableMemory); } void Stage7::NextLevel(){ game->levelToLoad=STAGE8; } Stage8::Stage8(VirusAttack*game) :Scenario(game){} void Stage8::Start(){ state=0; missionCompleted=false; dialog.SetVisible(false); game->unitMetersGreyedOut=false; game->limitedBuildOptions=false; game->guideEnabled=true; game->playerInControl=true; camera=utils::Camera2D(game->GetScreenSize(),game->game.GetWorldOffset()); camera.SetLazyFollowRate(1); camera.SetMode(utils::Camera2D::Mode::LazyFollow); } void Stage8::Update(){ switch(state){ case 0:{ SetObjective("Defeat all enemy units."); state=1; }break; } } bool Stage8::MissionCompleted(){ for(auto&u:game->units){ if(!u->IsFriendly()&&u->IsRAMBank()){ return false; } } return true; } void Stage8::Draw(){ dialog.UpdateAndDraw({24,64},game,game->player_resources,game->IMAGES,game->GetTotalUsedMemory(),game->currentLevel->availableMemory); } void Stage8::NextLevel(){ game->state=GameState::COMPLETED; }