Setup Scenario structures.

CorrectiveAction
sigonasr2 1 year ago
parent 1074d4a59a
commit d61b647fda
  1. 3
      olcCodeJam2023Entry/Level.h
  2. 22
      olcCodeJam2023Entry/Scenario.cpp
  3. 20
      olcCodeJam2023Entry/Scenario.h
  4. 18
      olcCodeJam2023Entry/VirusAttack.cpp
  5. 6
      olcCodeJam2023Entry/VirusAttack.h
  6. 2
      olcCodeJam2023Entry/olcCodeJam2023Entry.vcxproj
  7. 6
      olcCodeJam2023Entry/olcCodeJam2023Entry.vcxproj.filters

@ -3,6 +3,8 @@
#include "Unit.h" #include "Unit.h"
#include "CollectionPoint.h" #include "CollectionPoint.h"
class Scenario;
enum LevelName{ enum LevelName{
STAGE1, STAGE1,
STAGE2, STAGE2,
@ -37,6 +39,7 @@ struct Level{
std::vector<UnitData>unitPlacement; std::vector<UnitData>unitPlacement;
std::vector<CPData>cpPlacement; std::vector<CPData>cpPlacement;
Sound bgm=Sound::COSMOS; Sound bgm=Sound::COSMOS;
Scenario*scenario;
vf2d cameraStart={96,96}; vf2d cameraStart={96,96};
vf2d worldZoom={1,1}; vf2d worldZoom={1,1};
Pixel levelColor=DARK_GREEN; Pixel levelColor=DARK_GREEN;

@ -0,0 +1,22 @@
#include "Scenario.h"
Scenario::Scenario(VirusAttack*game)
:game(game){}
void Scenario::_Update(){
Update();
}
void Scenario::_Draw(){
Draw();
}
Stage1::Stage1(VirusAttack*game)
:Scenario(game){}
void Stage1::Update(){
}
void Stage1::Draw(){
}

@ -0,0 +1,20 @@
#pragma once
#include "VirusAttack.h"
class Scenario{
VirusAttack*game;
public:
Scenario(VirusAttack*game);
void _Update();
virtual void Update()=0;
void _Draw();
virtual void Draw()=0;
protected:
};
class Stage1:public Scenario{
public:
Stage1(VirusAttack*game);
void Update()override;
void Draw()override;
};

@ -13,8 +13,7 @@
#include "olcUTIL_Geometry2D.h" #include "olcUTIL_Geometry2D.h"
#include "TileManager.h" #include "TileManager.h"
#include "util.h" #include "util.h"
#include "Scenario.h"
#include "VirusAttack.h"
VirusAttack::VirusAttack() VirusAttack::VirusAttack()
{ {
@ -72,6 +71,7 @@ void VirusAttack::InitializeLevelData(){
LevelName stage=STAGE1; LevelName stage=STAGE1;
levelData[stage].cameraStart={96,96}; levelData[stage].cameraStart={96,96};
levelData[stage].worldZoom={1,1}; levelData[stage].worldZoom={1,1};
levelData[stage].scenario=scenarios[0];
levelData[stage].levelColor=DARK_RED; levelData[stage].levelColor=DARK_RED;
levelData[stage].size={64,64}; levelData[stage].size={64,64};
levelData[stage].bgm=Sound::BOSS2; levelData[stage].bgm=Sound::BOSS2;
@ -112,6 +112,7 @@ void VirusAttack::InitializeLevelData(){
levelData[stage].cameraStart={96,96}; levelData[stage].cameraStart={96,96};
levelData[stage].worldZoom={1,1}; levelData[stage].worldZoom={1,1};
levelData[stage].size={16,16}; levelData[stage].size={16,16};
levelData[stage].scenario=scenarios[1];
levelData[stage].levelColor=DARK_GREEN; levelData[stage].levelColor=DARK_GREEN;
levelData[stage].bgm=Sound::COSMOS; levelData[stage].bgm=Sound::COSMOS;
levelData[stage].player_starting_resources={10,10,10,10,10}; levelData[stage].player_starting_resources={10,10,10,10,10};
@ -155,6 +156,7 @@ bool VirusAttack::OnUserCreate(){
InitializeSounds(); InitializeSounds();
InitializeGUIs(); InitializeGUIs();
InitializeScenarios();
InitializeLevelData(); InitializeLevelData();
LoadLevel(STAGE1); LoadLevel(STAGE1);
@ -243,6 +245,11 @@ void VirusAttack::InitializeGUIs(){
memoryGuardButton=new QuickGUI::ImageButton(platformCreationList,*IMAGES[MEMORY_GUARD],{0.25,0.25},{float(ScreenWidth()-48),48.f+32*3},{20,20}); memoryGuardButton=new QuickGUI::ImageButton(platformCreationList,*IMAGES[MEMORY_GUARD],{0.25,0.25},{float(ScreenWidth()-48),48.f+32*3},{20,20});
} }
void VirusAttack::InitializeScenarios(){
scenarios.emplace_back(new Stage1(this));
scenarios.emplace_back(new Stage1(this));
}
void VirusAttack::InitializeSounds(){ void VirusAttack::InitializeSounds(){
int soundIndex=0; int soundIndex=0;
auto LoadSound=[&](Sound sound,std::string soundFilename){ auto LoadSound=[&](Sound sound,std::string soundFilename){
@ -654,6 +661,7 @@ bool VirusAttack::OnUserUpdate(float fElapsedTime){
HandleRightClickMove(); HandleRightClickMove();
HandlePanAndZoom(fElapsedTime); HandlePanAndZoom(fElapsedTime);
HandleMinimapClick(); HandleMinimapClick();
currentLevel->scenario->_Update();
AL.vecPos=game.ScreenToWorld(GetScreenSize()/2); AL.vecPos=game.ScreenToWorld(GetScreenSize()/2);
AL.fSoundFXVolume=std::min(1.f,game.GetWorldScale().x); AL.fSoundFXVolume=std::min(1.f,game.GetWorldScale().x);
AL.OnUserUpdate(fElapsedTime); AL.OnUserUpdate(fElapsedTime);
@ -765,6 +773,7 @@ bool VirusAttack::OnUserUpdate(float fElapsedTime){
DrawResourceBar(fElapsedTime); DrawResourceBar(fElapsedTime);
DrawDecal({float(ScreenWidth()-74-IMAGES[GUIDE]->Sprite()->width*0.75),float(ScreenHeight()+6-IMAGES[GUIDE]->Sprite()->height*0.75)},IMAGES[GUIDE]->Decal(),{0.75,0.75}); DrawDecal({float(ScreenWidth()-74-IMAGES[GUIDE]->Sprite()->width*0.75),float(ScreenHeight()+6-IMAGES[GUIDE]->Sprite()->height*0.75)},IMAGES[GUIDE]->Decal(),{0.75,0.75});
DrawMinimap(); DrawMinimap();
currentLevel->scenario->_Draw();
unitCreationBox.UpdateAndDraw(GetMousePos()+vi2d{8,-28},this,player_resources,IMAGES); unitCreationBox.UpdateAndDraw(GetMousePos()+vi2d{8,-28},this,player_resources,IMAGES);
testBox.UpdateAndDraw(GetMousePos()-testBox.GetSize()/2,this,player_resources,IMAGES); testBox.UpdateAndDraw(GetMousePos()-testBox.GetSize()/2,this,player_resources,IMAGES);
@ -1030,6 +1039,11 @@ void VirusAttack::CalculateUsedMemory(){
} }
} }
bool VirusAttack::OnUserDestroy(){
std::for_each(scenarios.begin(),scenarios.end(),[](auto&scenario){delete scenario;});
return true;
}
int main() int main()
{ {
VirusAttack app; VirusAttack app;

@ -1,3 +1,4 @@
#pragma once
#include "olcPixelGameEngine.h" #include "olcPixelGameEngine.h"
#include "olcSoundWaveEngine.h" #include "olcSoundWaveEngine.h"
#include "olcPGEX_TransformedView.h" #include "olcPGEX_TransformedView.h"
@ -15,6 +16,8 @@
#include "Textbox.h" #include "Textbox.h"
#include "Level.h" #include "Level.h"
class Scenario;
struct Letter{ struct Letter{
vf2d pos; vf2d pos;
float spd; float spd;
@ -35,6 +38,7 @@ private:
std::vector<std::unique_ptr<DeathAnimation>>deathAnimations; std::vector<std::unique_ptr<DeathAnimation>>deathAnimations;
std::vector<DebuffIcon>debuffIcons; std::vector<DebuffIcon>debuffIcons;
std::vector<ResourceGainIcon>resourceGainIcons; std::vector<ResourceGainIcon>resourceGainIcons;
std::vector<Scenario*>scenarios;
std::map<Image,std::unique_ptr<Renderable>>IMAGES; std::map<Image,std::unique_ptr<Renderable>>IMAGES;
std::map<Sound,std::unique_ptr<Audio>>SOUNDS; std::map<Sound,std::unique_ptr<Audio>>SOUNDS;
@ -111,6 +115,7 @@ private:
int GetEnemyUsedMemory(); int GetEnemyUsedMemory();
void DrawSystemMemoryBar(float fElapsedTime); void DrawSystemMemoryBar(float fElapsedTime);
void CalculateUsedMemory(); void CalculateUsedMemory();
void InitializeScenarios();
public: public:
VirusAttack(); VirusAttack();
@ -119,4 +124,5 @@ public:
bool OnUserCreate() override; bool OnUserCreate() override;
bool OnUserUpdate(float fElapsedTime) override; bool OnUserUpdate(float fElapsedTime) override;
bool OnUserDestroy() override;
}; };

@ -159,6 +159,7 @@
<ClInclude Include="resource.h" /> <ClInclude Include="resource.h" />
<ClInclude Include="resource1.h" /> <ClInclude Include="resource1.h" />
<ClInclude Include="Resources.h" /> <ClInclude Include="Resources.h" />
<ClInclude Include="Scenario.h" />
<ClInclude Include="Sound.h" /> <ClInclude Include="Sound.h" />
<ClInclude Include="Textbox.h" /> <ClInclude Include="Textbox.h" />
<ClInclude Include="TileManager.h" /> <ClInclude Include="TileManager.h" />
@ -171,6 +172,7 @@
<ClCompile Include="Constant.cpp" /> <ClCompile Include="Constant.cpp" />
<ClCompile Include="DeathAnimations.cpp" /> <ClCompile Include="DeathAnimations.cpp" />
<ClCompile Include="DebuffIcon.cpp" /> <ClCompile Include="DebuffIcon.cpp" />
<ClCompile Include="Scenario.cpp" />
<ClCompile Include="Textbox.cpp" /> <ClCompile Include="Textbox.cpp" />
<ClCompile Include="TileManager.cpp" /> <ClCompile Include="TileManager.cpp" />
<ClCompile Include="Unit.cpp" /> <ClCompile Include="Unit.cpp" />

@ -96,6 +96,9 @@
<ClInclude Include="Level.h"> <ClInclude Include="Level.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="Scenario.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="VirusAttack.cpp"> <ClCompile Include="VirusAttack.cpp">
@ -125,6 +128,9 @@
<ClCompile Include="Textbox.cpp"> <ClCompile Include="Textbox.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="Scenario.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ResourceCompile Include="olcCodeJam2023Entry.rc"> <ResourceCompile Include="olcCodeJam2023Entry.rc">

Loading…
Cancel
Save