Add in Scenario framework.

master
sigonasr2 1 year ago
parent 12a21881e1
commit 64f6b44994
  1. 1
      olcCodeJam2023Entry/Level.h
  2. 101
      olcCodeJam2023Entry/Scenario.cpp
  3. 76
      olcCodeJam2023Entry/Scenario.h
  4. 15
      olcCodeJam2023Entry/VirusAttack.cpp
  5. 3
      olcCodeJam2023Entry/VirusAttack.h

@ -38,6 +38,7 @@ struct Level{
std::vector<UnitData>unitPlacement;
std::vector<CPData>cpPlacement;
Sound bgm=Sound::COSMOS;
int scenarioIndex=0;
vf2d cameraStart={96,96};
vf2d worldZoom={1,1};
Pixel levelColor=DARK_GREEN;

@ -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;
}
};

@ -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();
};

@ -14,11 +14,13 @@
#include "olcUTIL_Geometry2D.h"
#include "util.h"
#include "Level.h"
#include "Scenario.h"
#include "VirusAttack.h"
VirusAttack*game;
std::vector<std::unique_ptr<Renderable>>IMAGES;
std::vector<std::unique_ptr<Audio>>SOUNDS;
std::vector<std::unique_ptr<Scenario>>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<Stage1>());
SCENARIOS.emplace_back(std::make_unique<Stage2>());
SCENARIOS.emplace_back(std::make_unique<Stage3>());
SCENARIOS.emplace_back(std::make_unique<Stage4>());
SCENARIOS.emplace_back(std::make_unique<Stage5>());
SCENARIOS.emplace_back(std::make_unique<Stage6>());
SCENARIOS.emplace_back(std::make_unique<Stage7>());
SCENARIOS.emplace_back(std::make_unique<Stage8>());
}
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);

@ -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="";

Loading…
Cancel
Save