generated from sigonasr2/CPlusPlusProjectTemplate
Added cutscene flag triggering
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
caaee07b89
commit
5fcdbc1b80
Binary file not shown.
33
cutscene.h
33
cutscene.h
@ -15,7 +15,8 @@ enum class ActionType{
|
||||
NONE,
|
||||
PAN_CAMERA,
|
||||
CREATE_OBJECTS,
|
||||
CLEANUP
|
||||
CLEANUP,
|
||||
SET_FLAG_WHEN_CUTSCENE_ENDS
|
||||
};
|
||||
|
||||
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.
|
||||
|
||||
@ -83,6 +102,8 @@ class Cutscene{
|
||||
std::vector<CutsceneAction*> actions;
|
||||
bool actionIsActive=false;
|
||||
std::vector<Object*>cutsceneObjs;
|
||||
Flag storedFlag=Flag::NONE;
|
||||
bool storedVal=true;
|
||||
public:
|
||||
template <class T>
|
||||
Cutscene(std::initializer_list<T> actions) {
|
||||
@ -135,4 +156,14 @@ class Cutscene{
|
||||
}
|
||||
cutsceneObjs.clear();
|
||||
}
|
||||
void SetupEndingCutsceneFlag(Flag flag,bool val=true) {
|
||||
storedFlag=flag;
|
||||
storedVal=val;
|
||||
}
|
||||
Flag GetEndingCutsceneFlag() {
|
||||
return storedFlag;
|
||||
}
|
||||
bool GetEndingCutsceneVal() {
|
||||
return storedVal;
|
||||
}
|
||||
};
|
21
flags.h
21
flags.h
@ -1,8 +1,15 @@
|
||||
namespace Flag{
|
||||
enum{
|
||||
TEST_FLAG1,
|
||||
TEST_FLAG2,
|
||||
TEST_FLAG3,
|
||||
NONE,
|
||||
};
|
||||
enum class Flag:int{
|
||||
NONE,
|
||||
TEST_FLAG1,
|
||||
TEST_FLAG2,
|
||||
TEST_FLAG3,
|
||||
};
|
||||
|
||||
|
||||
|
||||
template <typename Enumeration>
|
||||
auto flagint(Enumeration const value)
|
||||
-> typename std::underlying_type<Enumeration>::type
|
||||
{
|
||||
return static_cast<typename std::underlying_type<Enumeration>::type>(value);
|
||||
}
|
41
main.cpp
41
main.cpp
@ -75,8 +75,8 @@ class Object{
|
||||
Pixel color=WHITE;
|
||||
vd2d originPoint={0,0};
|
||||
bool drawn=false;
|
||||
int disableFlag;
|
||||
int enableFlag;
|
||||
Flag disableFlag=Flag::NONE;
|
||||
Flag enableFlag=Flag::NONE;
|
||||
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.
|
||||
//animationSpd is how long to wait before switching frames.
|
||||
@ -135,6 +135,7 @@ public:
|
||||
Cutscene*TestCutscene;
|
||||
Cutscene*CurrentCutscene=nullptr;
|
||||
ActionType CurrentAction=ActionType::NONE;
|
||||
double CUTSCENE_FADE_VALUE=0;
|
||||
|
||||
|
||||
bool MOUSE_PRESSED_DOWN=false,MOUSE_DOWN=false,MOUSE_RELEASED=false; //TODO Implement Mouse things.
|
||||
@ -164,9 +165,9 @@ public:
|
||||
SetupAnimations();
|
||||
SetupObjectInfo();
|
||||
|
||||
GAME_FLAGS[Flag::TEST_FLAG1]=true;
|
||||
GAME_FLAGS[Flag::TEST_FLAG2]=false;
|
||||
GAME_FLAGS[Flag::TEST_FLAG3]=true;
|
||||
SetGameFlag(Flag::TEST_FLAG1,false);
|
||||
SetGameFlag(Flag::TEST_FLAG2,false);
|
||||
SetGameFlag(Flag::TEST_FLAG3,false);
|
||||
|
||||
additionalChars[0x391]={0,0};
|
||||
additionalChars[0x392]={8,0};
|
||||
@ -181,6 +182,7 @@ public:
|
||||
LoadMap(MAP_ONETT);
|
||||
|
||||
TestCutscene=new Cutscene({
|
||||
(CutsceneAction*)new SetFlagWhenCutsceneEnds(Flag::TEST_FLAG1),
|
||||
(CutsceneAction*)new PanCamera({128,128},BOTH),
|
||||
(CutsceneAction*)new PanCamera({128,0},BOTH),
|
||||
(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!
|
||||
)");*/
|
||||
|
||||
StartCutscene(TestCutscene);
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
if (!GetGameFlag(Flag::TEST_FLAG1)) {
|
||||
StartCutscene(TestCutscene);
|
||||
}
|
||||
|
||||
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:{
|
||||
if (MoveCameraTowardsPoint((PanCamera*)CurrentCutscene->GetAction())) {
|
||||
CurrentCutscene->AdvanceAction();
|
||||
@ -279,11 +287,13 @@ goes on a very long time, I hope you can understand this is only for testing pur
|
||||
}
|
||||
CurrentCutscene->CleanupCutscene();
|
||||
CurrentCutscene->ResetCutscene();
|
||||
SetGameFlag(CurrentCutscene->GetEndingCutsceneFlag(),CurrentCutscene->GetEndingCutsceneVal());
|
||||
CurrentCutscene=nullptr;
|
||||
StartCutscene(TestCutscene);
|
||||
CurrentAction=ActionType::NONE;
|
||||
}break;
|
||||
}
|
||||
|
||||
|
||||
switch (GAME_STATE) {
|
||||
case GameState::TILE_SELECT:{
|
||||
if (!TabHeld()) {
|
||||
@ -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);
|
||||
}
|
||||
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 }) {
|
||||
@ -705,12 +716,12 @@ goes on a very long time, I hope you can understand this is only for testing pur
|
||||
|
||||
bool enabled=true;
|
||||
if (OBJ_INFO[id]->disableFlag!=Flag::NONE) {
|
||||
if (GAME_FLAGS[OBJ_INFO[id]->disableFlag]) {
|
||||
if (GetGameFlag(OBJ_INFO[id]->disableFlag)) {
|
||||
enabled=false;
|
||||
}
|
||||
}
|
||||
if (OBJ_INFO[id]->enableFlag!=Flag::NONE) {
|
||||
if (!GAME_FLAGS[OBJ_INFO[id]->enableFlag]) {
|
||||
if (!GetGameFlag(OBJ_INFO[id]->enableFlag)) {
|
||||
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);
|
||||
}
|
||||
|
||||
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)) {
|
||||
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;
|
||||
}
|
||||
|
||||
void SetGameFlag(Flag flag,bool val) {
|
||||
GAME_FLAGS[flagint(flag)]=val;
|
||||
}
|
||||
|
||||
bool GetGameFlag(Flag flag) {
|
||||
return GAME_FLAGS[flagint(flag)];
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user