Added cutscene flag triggering

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
master
sigonasr2 2 years ago
parent caaee07b89
commit 5fcdbc1b80
  1. BIN
      C++ProjectTemplate
  2. 33
      cutscene.h
  3. 21
      flags.h
  4. 41
      main.cpp

Binary file not shown.

@ -15,7 +15,8 @@ enum class ActionType{
NONE, NONE,
PAN_CAMERA, PAN_CAMERA,
CREATE_OBJECTS, CREATE_OBJECTS,
CLEANUP CLEANUP,
SET_FLAG_WHEN_CUTSCENE_ENDS
}; };
class CutsceneAction{ class CutsceneAction{
@ -70,6 +71,24 @@ class PanCamera:public CutsceneAction{
} }
}; };
class SetFlagWhenCutsceneEnds:public CutsceneAction{
private:
Flag flag;
bool val;
public:
SetFlagWhenCutsceneEnds(Flag flag,bool val=true) {
this->flag=flag;
this->val=val;
}
ActionType GetActionType() override{return ActionType::SET_FLAG_WHEN_CUTSCENE_ENDS;}
Flag GetCutsceneEndingFlag() {
return flag;
}
bool GetCutsceneEndingVal() {
return val;
}
};
/* /*
To use this class, specify multiple actions back-to-back, filling their appropriate arguments. To use this class, specify multiple actions back-to-back, filling their appropriate arguments.
@ -83,6 +102,8 @@ class Cutscene{
std::vector<CutsceneAction*> actions; std::vector<CutsceneAction*> actions;
bool actionIsActive=false; bool actionIsActive=false;
std::vector<Object*>cutsceneObjs; std::vector<Object*>cutsceneObjs;
Flag storedFlag=Flag::NONE;
bool storedVal=true;
public: public:
template <class T> template <class T>
Cutscene(std::initializer_list<T> actions) { Cutscene(std::initializer_list<T> actions) {
@ -135,4 +156,14 @@ class Cutscene{
} }
cutsceneObjs.clear(); cutsceneObjs.clear();
} }
void SetupEndingCutsceneFlag(Flag flag,bool val=true) {
storedFlag=flag;
storedVal=val;
}
Flag GetEndingCutsceneFlag() {
return storedFlag;
}
bool GetEndingCutsceneVal() {
return storedVal;
}
}; };

@ -1,8 +1,15 @@
namespace Flag{ enum class Flag:int{
enum{ NONE,
TEST_FLAG1, TEST_FLAG1,
TEST_FLAG2, TEST_FLAG2,
TEST_FLAG3, TEST_FLAG3,
NONE, };
};
template <typename Enumeration>
auto flagint(Enumeration const value)
-> typename std::underlying_type<Enumeration>::type
{
return static_cast<typename std::underlying_type<Enumeration>::type>(value);
} }

@ -75,8 +75,8 @@ class Object{
Pixel color=WHITE; Pixel color=WHITE;
vd2d originPoint={0,0}; vd2d originPoint={0,0};
bool drawn=false; bool drawn=false;
int disableFlag; Flag disableFlag=Flag::NONE;
int enableFlag; Flag enableFlag=Flag::NONE;
int objArrElement; //Which element in the object array this object is located in. For sorting purposes. int objArrElement; //Which element in the object array this object is located in. For sorting purposes.
bool temp=false; //If set to true, it's marked for deletion after cutscene handling. bool temp=false; //If set to true, it's marked for deletion after cutscene handling.
//animationSpd is how long to wait before switching frames. //animationSpd is how long to wait before switching frames.
@ -135,6 +135,7 @@ public:
Cutscene*TestCutscene; Cutscene*TestCutscene;
Cutscene*CurrentCutscene=nullptr; Cutscene*CurrentCutscene=nullptr;
ActionType CurrentAction=ActionType::NONE; ActionType CurrentAction=ActionType::NONE;
double CUTSCENE_FADE_VALUE=0;
bool MOUSE_PRESSED_DOWN=false,MOUSE_DOWN=false,MOUSE_RELEASED=false; //TODO Implement Mouse things. bool MOUSE_PRESSED_DOWN=false,MOUSE_DOWN=false,MOUSE_RELEASED=false; //TODO Implement Mouse things.
@ -164,9 +165,9 @@ public:
SetupAnimations(); SetupAnimations();
SetupObjectInfo(); SetupObjectInfo();
GAME_FLAGS[Flag::TEST_FLAG1]=true; SetGameFlag(Flag::TEST_FLAG1,false);
GAME_FLAGS[Flag::TEST_FLAG2]=false; SetGameFlag(Flag::TEST_FLAG2,false);
GAME_FLAGS[Flag::TEST_FLAG3]=true; SetGameFlag(Flag::TEST_FLAG3,false);
additionalChars[0x391]={0,0}; additionalChars[0x391]={0,0};
additionalChars[0x392]={8,0}; additionalChars[0x392]={8,0};
@ -181,6 +182,7 @@ public:
LoadMap(MAP_ONETT); LoadMap(MAP_ONETT);
TestCutscene=new Cutscene({ TestCutscene=new Cutscene({
(CutsceneAction*)new SetFlagWhenCutsceneEnds(Flag::TEST_FLAG1),
(CutsceneAction*)new PanCamera({128,128},BOTH), (CutsceneAction*)new PanCamera({128,128},BOTH),
(CutsceneAction*)new PanCamera({128,0},BOTH), (CutsceneAction*)new PanCamera({128,0},BOTH),
(CutsceneAction*)new CreateObjects({ (CutsceneAction*)new CreateObjects({
@ -195,8 +197,6 @@ in some form or capacity or another. Even though it
goes on a very long time, I hope you can understand this is only for testing purposes! goes on a very long time, I hope you can understand this is only for testing purposes!
)");*/ )");*/
StartCutscene(TestCutscene);
return true; return true;
} }
@ -258,7 +258,15 @@ goes on a very long time, I hope you can understand this is only for testing pur
CurrentCutscene->LockAction(); CurrentCutscene->LockAction();
} }
if (!GetGameFlag(Flag::TEST_FLAG1)) {
StartCutscene(TestCutscene);
}
switch (CurrentAction) { switch (CurrentAction) {
case ActionType::SET_FLAG_WHEN_CUTSCENE_ENDS:{
CurrentCutscene->SetupEndingCutsceneFlag(((SetFlagWhenCutsceneEnds*)CurrentCutscene->GetAction())->GetCutsceneEndingFlag(),((SetFlagWhenCutsceneEnds*)CurrentCutscene->GetAction())->GetCutsceneEndingVal());
CurrentCutscene->AdvanceAction();
}break;
case ActionType::PAN_CAMERA:{ case ActionType::PAN_CAMERA:{
if (MoveCameraTowardsPoint((PanCamera*)CurrentCutscene->GetAction())) { if (MoveCameraTowardsPoint((PanCamera*)CurrentCutscene->GetAction())) {
CurrentCutscene->AdvanceAction(); CurrentCutscene->AdvanceAction();
@ -279,10 +287,12 @@ goes on a very long time, I hope you can understand this is only for testing pur
} }
CurrentCutscene->CleanupCutscene(); CurrentCutscene->CleanupCutscene();
CurrentCutscene->ResetCutscene(); CurrentCutscene->ResetCutscene();
SetGameFlag(CurrentCutscene->GetEndingCutsceneFlag(),CurrentCutscene->GetEndingCutsceneVal());
CurrentCutscene=nullptr; CurrentCutscene=nullptr;
StartCutscene(TestCutscene); CurrentAction=ActionType::NONE;
}break; }break;
} }
switch (GAME_STATE) { switch (GAME_STATE) {
case GameState::TILE_SELECT:{ case GameState::TILE_SELECT:{
@ -614,6 +624,7 @@ goes on a very long time, I hope you can understand this is only for testing pur
DrawStringPropDecal({6,6},messageBoxText); DrawStringPropDecal({6,6},messageBoxText);
} }
SetDrawTarget(layer::INTERFACE); SetDrawTarget(layer::INTERFACE);
FillRectDecal({0,0},{WIDTH,HEIGHT},Pixel(0,0,0,(int)CUTSCENE_FADE_VALUE));
}; };
void DrawFancyStringDecal(const olc::vf2d& pos, const std::wstring& sText, const Pixel col = olc::WHITE, const olc::vf2d& scale = { 1.0f, 1.0f }) { void DrawFancyStringDecal(const olc::vf2d& pos, const std::wstring& sText, const Pixel col = olc::WHITE, const olc::vf2d& scale = { 1.0f, 1.0f }) {
@ -705,12 +716,12 @@ goes on a very long time, I hope you can understand this is only for testing pur
bool enabled=true; bool enabled=true;
if (OBJ_INFO[id]->disableFlag!=Flag::NONE) { if (OBJ_INFO[id]->disableFlag!=Flag::NONE) {
if (GAME_FLAGS[OBJ_INFO[id]->disableFlag]) { if (GetGameFlag(OBJ_INFO[id]->disableFlag)) {
enabled=false; enabled=false;
} }
} }
if (OBJ_INFO[id]->enableFlag!=Flag::NONE) { if (OBJ_INFO[id]->enableFlag!=Flag::NONE) {
if (!GAME_FLAGS[OBJ_INFO[id]->enableFlag]) { if (!GetGameFlag(OBJ_INFO[id]->enableFlag)) {
enabled=false; enabled=false;
} }
} }
@ -836,7 +847,7 @@ goes on a very long time, I hope you can understand this is only for testing pur
return new Object(id,OBJ_INFO[id]->name,pos,OBJ_INFO[id]->spr,OBJ_INFO[id]->scale,OBJ_INFO[id]->color,OBJ_INFO[id]->animationSpd); return new Object(id,OBJ_INFO[id]->name,pos,OBJ_INFO[id]->spr,OBJ_INFO[id]->scale,OBJ_INFO[id]->color,OBJ_INFO[id]->animationSpd);
} }
Object*CreateObjectInfo(Reference ref,std::string name,vd2d pos,std::string spriteFileName,int sprWidth,vd2d scale={1,1},Pixel tint=WHITE,int enableFlag=Flag::NONE,int disableFlag=Flag::NONE,int animationDelay=1) { Object*CreateObjectInfo(Reference ref,std::string name,vd2d pos,std::string spriteFileName,int sprWidth,vd2d scale={1,1},Pixel tint=WHITE,Flag enableFlag=Flag::NONE,Flag disableFlag=Flag::NONE,int animationDelay=1) {
if (!ANIMATIONS.count(spriteFileName)) { if (!ANIMATIONS.count(spriteFileName)) {
ANIMATIONS[spriteFileName] = new Animation(SPRITES[spriteFileName]=CreateSprite(spriteFileName),32); ANIMATIONS[spriteFileName] = new Animation(SPRITES[spriteFileName]=CreateSprite(spriteFileName),32);
} }
@ -1270,6 +1281,14 @@ goes on a very long time, I hope you can understand this is only for testing pur
} }
return reachedPosition; return reachedPosition;
} }
void SetGameFlag(Flag flag,bool val) {
GAME_FLAGS[flagint(flag)]=val;
}
bool GetGameFlag(Flag flag) {
return GAME_FLAGS[flagint(flag)];
}
}; };

Loading…
Cancel
Save