From 64f6b44994ea36cc964b0578497c37c057e75fe7 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Sun, 3 Sep 2023 01:54:07 -0500 Subject: [PATCH] Add in Scenario framework. --- olcCodeJam2023Entry/Level.h | 1 + olcCodeJam2023Entry/Scenario.cpp | 101 ++++++++++++++++++++++++++++ olcCodeJam2023Entry/Scenario.h | 76 +++++++++++++++++++++ olcCodeJam2023Entry/VirusAttack.cpp | 15 +++++ olcCodeJam2023Entry/VirusAttack.h | 3 +- 5 files changed, 195 insertions(+), 1 deletion(-) diff --git a/olcCodeJam2023Entry/Level.h b/olcCodeJam2023Entry/Level.h index 7be9b4a..74a42da 100644 --- a/olcCodeJam2023Entry/Level.h +++ b/olcCodeJam2023Entry/Level.h @@ -38,6 +38,7 @@ struct Level{ std::vectorunitPlacement; std::vectorcpPlacement; Sound bgm=Sound::COSMOS; + int scenarioIndex=0; vf2d cameraStart={96,96}; vf2d worldZoom={1,1}; Pixel levelColor=DARK_GREEN; diff --git a/olcCodeJam2023Entry/Scenario.cpp b/olcCodeJam2023Entry/Scenario.cpp index e69de29..9aa6e8a 100644 --- a/olcCodeJam2023Entry/Scenario.cpp +++ b/olcCodeJam2023Entry/Scenario.cpp @@ -0,0 +1,101 @@ +#include "Scenario.h" +#include "VirusAttack.h" + +extern VirusAttack*game; + +Scenario::Scenario(){} +Scenario::~Scenario(){}; +void Scenario::_Start(){ + state=0; + camera=utils::Camera2D{game->gametv.GetWorldOffset(),game->currentLevel->cameraStart}; + camera.SetLazyFollowRate(2); + camera.SetMode(utils::Camera2D::Mode::LazyFollow); + targetPos={96,96}; + box.SetVisible(false); + initialWaitTime=3; + camera.SetTarget(targetPos); + Start(); +} +void Scenario::Start(){}; +void Scenario::_Update(){ + initialWaitTime=std::max(0.f,initialWaitTime-game->GetElapsedTime()); + if(initialWaitTime==0){ + Update(); + } +}; +void Scenario::Update(){}; +Stage1::Stage1(){} +void Stage1::Start(){ + game->unitMetersGreyedOut=true; + game->playerInControl=false; +}; +void Stage1::Update(){ + switch(state){ + case 0:{ + + }break; + } +}; +Stage2::Stage2(){} +void Stage2::Start(){}; +void Stage2::Update(){ + switch(state){ + case 0:{ + + }break; + } +}; +Stage3::Stage3(){} +void Stage3::Start(){}; +void Stage3::Update(){ + switch(state){ + case 0:{ + + }break; + } +}; +Stage4::Stage4(){} +void Stage4::Start(){}; +void Stage4::Update(){ + switch(state){ + case 0:{ + + }break; + } +}; +Stage5::Stage5(){} +void Stage5::Start(){}; +void Stage5::Update(){ + switch(state){ + case 0:{ + + }break; + } +}; +Stage6::Stage6(){} +void Stage6::Start(){}; +void Stage6::Update(){ + switch(state){ + case 0:{ + + }break; + } +}; +Stage7::Stage7(){} +void Stage7::Start(){}; +void Stage7::Update(){ + switch(state){ + case 0:{ + + }break; + } +}; +Stage8::Stage8(){} +void Stage8::Start(){}; +void Stage8::Update(){ + switch(state){ + case 0:{ + + }break; + } +}; \ No newline at end of file diff --git a/olcCodeJam2023Entry/Scenario.h b/olcCodeJam2023Entry/Scenario.h index e69de29..8cbd455 100644 --- a/olcCodeJam2023Entry/Scenario.h +++ b/olcCodeJam2023Entry/Scenario.h @@ -0,0 +1,76 @@ +#pragma once +#include "olcUTIL_Camera2D.h" +#include "Textbox.h" + +class Scenario{ +public: + Scenario(); + virtual~Scenario(); + void _Start(); + virtual void Start(); + void _Update(); +protected: + virtual void Update(); + int state=0; + utils::Camera2D camera; + vf2d targetPos; + Textbox box; + float initialWaitTime=3; +}; + +class Stage1:public Scenario{ +public: + Stage1(); +protected: + void Start(); + void Update(); +}; +class Stage2:public Scenario{ +public: + Stage2(); +protected: + void Start(); + void Update(); +}; +class Stage3:public Scenario{ +public: + Stage3(); +protected: + void Start(); + void Update(); +}; +class Stage4:public Scenario{ +public: + Stage4(); +protected: + void Start(); + void Update(); +}; +class Stage5:public Scenario{ +public: + Stage5(); +protected: + void Start(); + void Update(); +}; +class Stage6:public Scenario{ +public: + Stage6(); +protected: + void Start(); + void Update(); +}; +class Stage7:public Scenario{ +public: + Stage7(); +protected: + void Start(); + void Update(); +}; +class Stage8:public Scenario{ +public: + Stage8(); +protected: + void Start(); + void Update(); +}; \ No newline at end of file diff --git a/olcCodeJam2023Entry/VirusAttack.cpp b/olcCodeJam2023Entry/VirusAttack.cpp index 741c009..f4a1302 100644 --- a/olcCodeJam2023Entry/VirusAttack.cpp +++ b/olcCodeJam2023Entry/VirusAttack.cpp @@ -14,11 +14,13 @@ #include "olcUTIL_Geometry2D.h" #include "util.h" #include "Level.h" +#include "Scenario.h" #include "VirusAttack.h" VirusAttack*game; std::vector>IMAGES; std::vector>SOUNDS; +std::vector>SCENARIOS; VirusAttack::VirusAttack() { @@ -102,6 +104,7 @@ void VirusAttack::InitializeLevelData(){ levelData[stage].levelColor=DARK_RED; levelData[stage].size={24,24}; levelData[stage].bgm=Sound::GRAVITY; + levelData[stage].scenarioIndex=int(stage); levelData[stage].player_starting_resources={500,500,500,500,500}; levelData[stage].enemy_starting_resources={0,0,0,0,0}; { @@ -124,6 +127,7 @@ void VirusAttack::InitializeLevelData(){ levelData[stage].size={16,16}; levelData[stage].levelColor=DARK_GREEN; levelData[stage].bgm=Sound::GRAVITY; + levelData[stage].scenarioIndex=int(stage); levelData[stage].player_starting_resources={10,10,10,10,10}; levelData[stage].enemy_starting_resources={0,0,0,0,0}; { @@ -174,6 +178,7 @@ void VirusAttack::LoadLevel(LevelName level){ Level&selectedLevel=levelData[level]; currentLevel=&selectedLevel; + currentScenario=currentLevel->scenarioIndex; WORLD_SIZE=selectedLevel.size; @@ -230,6 +235,7 @@ void VirusAttack::LoadLevel(LevelName level){ randomBackgroundOffset={util::random(128),util::random(128)}; objective=""; + SCENARIOS[currentScenario]->_Start(); } void VirusAttack::InitializeGUIs(){ @@ -265,6 +271,14 @@ void VirusAttack::InitializeGUIs(){ } void VirusAttack::InitializeScenarios(){ + SCENARIOS.emplace_back(std::make_unique()); + SCENARIOS.emplace_back(std::make_unique()); + SCENARIOS.emplace_back(std::make_unique()); + SCENARIOS.emplace_back(std::make_unique()); + SCENARIOS.emplace_back(std::make_unique()); + SCENARIOS.emplace_back(std::make_unique()); + SCENARIOS.emplace_back(std::make_unique()); + SCENARIOS.emplace_back(std::make_unique()); } void VirusAttack::InitializeSounds(){ @@ -769,6 +783,7 @@ bool VirusAttack::OnUserUpdate(float fElapsedTime){ HandlePanAndZoom(fElapsedTime); HandleMinimapClick(); } + SCENARIOS[currentScenario]->_Update(); restartManager.Update(this); HandleRestartButton(fElapsedTime); PerformLevelTransition(fElapsedTime); diff --git a/olcCodeJam2023Entry/VirusAttack.h b/olcCodeJam2023Entry/VirusAttack.h index 71fd664..a20b6e7 100644 --- a/olcCodeJam2023Entry/VirusAttack.h +++ b/olcCodeJam2023Entry/VirusAttack.h @@ -26,7 +26,7 @@ struct Letter{ class VirusAttack : public olc::PixelGameEngine { -private: +public: #ifdef SPLASH_ENABLED SplashScreen splash; #endif @@ -109,6 +109,7 @@ private: float titleScreenY=-200; float textOrientationY=0; float textOrientationX=0; + int currentScenario=0; std::string objective="";