You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
VirusAttack/olcCodeJam2023Entry/Scenario.cpp

124 lines
3.2 KiB

#include "Scenario.h"
#include "TileManager.h"
Scenario::Scenario(VirusAttack*game)
:game(game){
dialog.SetVisible(false);
}
void Scenario::Start(){}
void Scenario::_Update(){
initialWaitTimer=std::max(0.f,initialWaitTimer-game->GetElapsedTime());
Update();
}
void Scenario::_Draw(){
if(game->objective.length()>0){
game->DrawShadowStringDecal({4,24},"Objective:");
game->DrawShadowStringDecal({6,36},game->objective);
}
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());
}
Stage1::Stage1(VirusAttack*game)
:Scenario(game){}
void Stage1::Start(){
game->unitMetersGreyedOut=true;
game->playerInControl=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. Make sure there's always 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;
}
}
void Stage1::Draw(){
dialog.UpdateAndDraw({24,64},game,game->player_resources,game->IMAGES,game->GetTotalUsedMemory(),game->currentLevel->availableMemory);
}