Compare commits
2 Commits
62f5fe938e
...
7188e6541e
Author | SHA1 | Date |
---|---|---|
sigonasr2 | 7188e6541e | 1 year ago |
sigonasr2 | 2b36a0cc9e | 1 year ago |
@ -1,442 +0,0 @@ |
||||
#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; |
||||
} |
@ -1,50 +0,0 @@ |
||||
#pragma once |
||||
#include "VirusAttack.h" |
||||
#include "olcUTIL_Camera2D.h" |
||||
|
||||
class Scenario{ |
||||
public: |
||||
Scenario(VirusAttack*game); |
||||
virtual void Start(); |
||||
void _Update(); |
||||
virtual void Update()=0; |
||||
void _Draw(); |
||||
virtual void Draw()=0; |
||||
void DisplayDialog(std::string dialogText,bool spooky=false); |
||||
void SetObjective(std::string objective); |
||||
void SetupCameraTarget(vf2d pos); |
||||
void MoveCamera(); |
||||
virtual bool MissionCompleted()=0; |
||||
virtual void NextLevel(); |
||||
protected: |
||||
VirusAttack*game; |
||||
int state=0; |
||||
Textbox dialog; |
||||
float initialWaitTimer=3; |
||||
utils::Camera2D camera; |
||||
vf2d cameraTargetPos={}; |
||||
bool missionCompleted=false; |
||||
float waitToContinueTimer=0; |
||||
float missionCompletedTimer=0; |
||||
}; |
||||
|
||||
#define SetupStage(StageClass) \ |
||||
class StageClass:public Scenario{ \
|
||||
public: \
|
||||
StageClass(VirusAttack*game); \
|
||||
void Start()override; \
|
||||
void Update()override; \
|
||||
bool MissionCompleted()override; \
|
||||
void Draw()override; \
|
||||
void NextLevel()override; \
|
||||
}; |
||||
|
||||
SetupStage(Stage1) |
||||
SetupStage(Stage2) |
||||
SetupStage(Stage3) |
||||
SetupStage(Stage4) |
||||
SetupStage(Stage5) |
||||
SetupStage(Stage6) |
||||
SetupStage(Stage7) |
||||
SetupStage(Stage8) |
||||
|
@ -1,2 +1,2 @@ |
||||
~\Documents\emsdk\emsdk_env.ps1 activate latest |
||||
em++ -std=c++20 -s ALLOW_MEMORY_GROWTH=1 -s MAX_WEBGL_VERSION=2 -s MIN_WEBGL_VERSION=2 -s USE_LIBPNG=1 -s USE_SDL_MIXER=2 -sSTACK_SIZE=5MB $(Get-ChildItem *.cpp) soloud.o -o pge.html --preload-file assets |
||||
em++ -std=c++20 -O2 -s ALLOW_MEMORY_GROWTH=1 -s MAX_WEBGL_VERSION=2 -s MIN_WEBGL_VERSION=2 -s USE_LIBPNG=1 -s USE_SDL_MIXER=2 -sSTACK_SIZE=10MB $(Get-ChildItem *.cpp) soloud.o -o pge.html --preload-file assets |
Before Width: | Height: | Size: 16 MiB After Width: | Height: | Size: 23 MiB |
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Binary file not shown.
Loading…
Reference in new issue