Async cutscene triggers implemented

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
master
sigonasr2 2 years ago
parent 7c5600bb01
commit 267310efd8
  1. BIN
      C++ProjectTemplate
  2. 77
      SeasonI.code-workspace
  3. 58
      cutscene.h
  4. 71
      main.cpp

Binary file not shown.

@ -0,0 +1,77 @@
{
"folders": [
{
"path": "."
},
{
"path": "../Seasons-Of-Loneliness"
}
],
"settings": {
"files.associations": {
"map1": "plaintext",
"*.tcc": "cpp",
"istream": "cpp",
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"cctype": "cpp",
"chrono": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"codecvt": "cpp",
"compare": "cpp",
"concepts": "cpp",
"condition_variable": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"list": "cpp",
"map": "cpp",
"string": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"random": "cpp",
"ratio": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"fstream": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"limits": "cpp",
"mutex": "cpp",
"new": "cpp",
"numbers": "cpp",
"ostream": "cpp",
"semaphore": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"stop_token": "cpp",
"streambuf": "cpp",
"thread": "cpp",
"cinttypes": "cpp",
"typeinfo": "cpp",
"pixelgameengine.h": "c",
"animations.h": "c"
}
}
}

@ -1,5 +1,4 @@
#include "pixelGameEngine.h" #include "pixelGameEngine.h"
#include <cstdarg>
#define CAMERA_MOVESPD 5 #define CAMERA_MOVESPD 5
@ -19,12 +18,24 @@ enum class ActionType{
SET_FLAG_WHEN_CUTSCENE_ENDS, SET_FLAG_WHEN_CUTSCENE_ENDS,
FADE, FADE,
DIALOG, DIALOG,
MOVE_CUTSCENE_OBJ MOVE_CUTSCENE_OBJ,
PAN_CAMERA_ASYNC,
FADE_ASYNC,
DIALOG_ASYNC,
MOVE_CUTSCENE_OBJ_ASYNC
//TODO: Change Sprites Action Type.
}; };
class CutsceneAction{ class CutsceneAction{
bool queued=false; //Set to true when added to action asynchronous queue.
public: public:
virtual ActionType GetActionType(){}; virtual ActionType GetActionType(){};
bool InQueue() {
return queued;
}
void SetQueued(bool queued=true) {
this->queued=queued;
}
}; };
class Cleanup:public CutsceneAction{ class Cleanup:public CutsceneAction{
@ -35,7 +46,7 @@ class Cleanup:public CutsceneAction{
class Object; class Object;
class CreateObjects:public CutsceneAction{ class CreateObjects:public CutsceneAction{
private: protected:
std::vector<Object*>objs; std::vector<Object*>objs;
public: public:
template <class T> template <class T>
@ -52,7 +63,7 @@ class CreateObjects:public CutsceneAction{
}; };
class PanCamera:public CutsceneAction{ class PanCamera:public CutsceneAction{
private: protected:
vd2d targetPos; vd2d targetPos;
PriorityDirection dir; PriorityDirection dir;
double cameraSpd; double cameraSpd;
@ -74,8 +85,15 @@ class PanCamera:public CutsceneAction{
} }
}; };
class PanCameraAsync:public PanCamera{
public:
PanCameraAsync(vd2d targetPos,PriorityDirection dir,double cameraSpd=CAMERA_MOVESPD)
:PanCamera(targetPos,dir,cameraSpd){}
ActionType GetActionType() override{return ActionType::PAN_CAMERA_ASYNC;}
};
class MoveCutsceneObject:public CutsceneAction{ class MoveCutsceneObject:public CutsceneAction{
private: protected:
int objID; int objID;
vd2d targetPos; vd2d targetPos;
double moveSpd; double moveSpd;
@ -101,6 +119,13 @@ class MoveCutsceneObject:public CutsceneAction{
PriorityDirection GetMovement() { PriorityDirection GetMovement() {
return dir; return dir;
} }
};
class MoveCutsceneObjectAsync:public MoveCutsceneObject{
public:
MoveCutsceneObjectAsync(int objID,vd2d targetPos,double moveSpd=CAMERA_MOVESPD,PriorityDirection dir=BOTH)
:MoveCutsceneObject(objID,targetPos,moveSpd){}
ActionType GetActionType() override{return ActionType::MOVE_CUTSCENE_OBJ_ASYNC;}
}; };
class SetFlagWhenCutsceneEnds:public CutsceneAction{ class SetFlagWhenCutsceneEnds:public CutsceneAction{
@ -122,7 +147,7 @@ class SetFlagWhenCutsceneEnds:public CutsceneAction{
}; };
class Fade:public CutsceneAction{ class Fade:public CutsceneAction{
private: protected:
bool fadeIn=true; //If false, it fades out instead. bool fadeIn=true; //If false, it fades out instead.
double fadeSpd=0; double fadeSpd=0;
public: public:
@ -141,8 +166,16 @@ class Fade:public CutsceneAction{
} }
}; };
class FadeAsync:public Fade{
public:
//If false, it fades out instead.
FadeAsync(bool fadeIn=false,double fadeSpd=4)
:Fade(fadeIn,fadeSpd){}
ActionType GetActionType() override{return ActionType::FADE_ASYNC;}
};
class DialogBox:public CutsceneAction{ class DialogBox:public CutsceneAction{
private: protected:
std::string message; std::string message;
bool messageBoxVisible=false; bool messageBoxVisible=false;
public: public:
@ -163,6 +196,14 @@ class DialogBox:public CutsceneAction{
} }
}; };
class DialogBoxAsync:public DialogBox{
public:
//If false, it fades out instead.
DialogBoxAsync(std::string message)
:DialogBox(message){}
ActionType GetActionType() override{return ActionType::DIALOG_ASYNC;}
};
/* /*
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.
@ -212,6 +253,9 @@ class Cutscene{
void ResetCutscene(){ void ResetCutscene(){
actionMarker=0; actionMarker=0;
actionIsActive=false; actionIsActive=false;
for (auto&action:actions) {
action->SetQueued(false);
}
} }
Object*AddCutsceneObject(Object*obj) { Object*AddCutsceneObject(Object*obj) {
this->cutsceneObjs.push_back(obj); this->cutsceneObjs.push_back(obj);

@ -18,6 +18,13 @@
#define TILEMAP_EDITOR_DRAW_MULT 0.4375 #define TILEMAP_EDITOR_DRAW_MULT 0.4375
#define TILEMAP_EDITOR_TILESIZE (32*TILEMAP_EDITOR_DRAW_MULT) #define TILEMAP_EDITOR_TILESIZE (32*TILEMAP_EDITOR_DRAW_MULT)
#define AddAsyncCutsceneAction(AsyncClass) \
if (!((AsyncClass*)CurrentCutscene->GetAction())->InQueue()) { \
CUTSCENE_QUEUE.push_back(CurrentCutscene->GetAction()); \
} \
((AsyncClass*)CurrentCutscene->GetAction())->SetQueued(); \
CurrentCutscene->AdvanceAction(); \
using namespace olc; using namespace olc;
namespace layer{ namespace layer{
@ -136,6 +143,7 @@ public:
Cutscene*CurrentCutscene=nullptr; Cutscene*CurrentCutscene=nullptr;
ActionType CurrentAction=ActionType::NONE; ActionType CurrentAction=ActionType::NONE;
double CUTSCENE_FADE_VALUE=0; double CUTSCENE_FADE_VALUE=0;
std::vector<CutsceneAction*>CUTSCENE_QUEUE;
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.
@ -195,7 +203,6 @@ public:
(CutsceneAction*)new MoveCutsceneObject(1,{80,64}), (CutsceneAction*)new MoveCutsceneObject(1,{80,64}),
(CutsceneAction*)new DialogBox(R"(Hello! (CutsceneAction*)new DialogBox(R"(Hello!
This is a test message that lets us trigger straight from a cutscene! Cool!)"),}); This is a test message that lets us trigger straight from a cutscene! Cool!)"),});
/*DisplayMessageBox(R"(Hello World! /*DisplayMessageBox(R"(Hello World!
This is a rather long message, but I hope it reaches you well This is a rather long message, but I hope it reaches you well
in some form or capacity or another. Even though it in some form or capacity or another. Even though it
@ -220,7 +227,7 @@ goes on a very long time, I hope you can understand this is only for testing pur
Clear(MAGENTA); Clear(MAGENTA);
} else { } else {
Clear(BLANK); Clear(BLANK);
} }
SetDrawTarget(layer::HIGH); SetDrawTarget(layer::HIGH);
Clear(BLANK); Clear(BLANK);
SetDrawTarget(layer::DYNAMIC); SetDrawTarget(layer::DYNAMIC);
@ -277,11 +284,17 @@ goes on a very long time, I hope you can understand this is only for testing pur
CurrentCutscene->AdvanceAction(); CurrentCutscene->AdvanceAction();
} }
}break; }break;
case ActionType::PAN_CAMERA_ASYNC:{
AddAsyncCutsceneAction(PanCameraAsync);
}break;
case ActionType::MOVE_CUTSCENE_OBJ:{ case ActionType::MOVE_CUTSCENE_OBJ:{
if (MoveObjectTowardsPoint(CurrentCutscene->GetCutsceneObjects()[((MoveCutsceneObject*)CurrentCutscene->GetAction())->GetObjectID()],((MoveCutsceneObject*)CurrentCutscene->GetAction())->GetTargetPos(),((MoveCutsceneObject*)CurrentCutscene->GetAction())->GetMovement(),((MoveCutsceneObject*)CurrentCutscene->GetAction())->GetMoveSpd())) { if (MoveObjectTowardsPoint(CurrentCutscene->GetCutsceneObjects()[((MoveCutsceneObject*)CurrentCutscene->GetAction())->GetObjectID()],((MoveCutsceneObject*)CurrentCutscene->GetAction())->GetTargetPos(),((MoveCutsceneObject*)CurrentCutscene->GetAction())->GetMovement(),((MoveCutsceneObject*)CurrentCutscene->GetAction())->GetMoveSpd())) {
CurrentCutscene->AdvanceAction(); CurrentCutscene->AdvanceAction();
} }
}break; }break;
case ActionType::MOVE_CUTSCENE_OBJ_ASYNC:{
AddAsyncCutsceneAction(MoveCutsceneObjectAsync);
}break;
case ActionType::CREATE_OBJECTS:{ case ActionType::CREATE_OBJECTS:{
for (auto&obj:((CreateObjects*)CurrentCutscene->GetAction())->GetObjects()) { for (auto&obj:((CreateObjects*)CurrentCutscene->GetAction())->GetObjects()) {
obj->temp=true; obj->temp=true;
@ -290,16 +303,18 @@ goes on a very long time, I hope you can understand this is only for testing pur
CurrentCutscene->AdvanceAction(); CurrentCutscene->AdvanceAction();
}break; }break;
case ActionType::CLEANUP:{ case ActionType::CLEANUP:{
for (int i=0;i<OBJECTS.size();i++) { if (CUTSCENE_QUEUE.size()==0) {
if (OBJECTS[i]->temp) { for (int i=0;i<OBJECTS.size();i++) {
OBJECTS.erase(OBJECTS.begin()+i--); if (OBJECTS[i]->temp) {
OBJECTS.erase(OBJECTS.begin()+i--);
}
} }
CurrentCutscene->CleanupCutscene();
CurrentCutscene->ResetCutscene();
SetGameFlag(CurrentCutscene->GetEndingCutsceneFlag(),CurrentCutscene->GetEndingCutsceneVal());
CurrentCutscene=nullptr;
CurrentAction=ActionType::NONE;
} }
CurrentCutscene->CleanupCutscene();
CurrentCutscene->ResetCutscene();
SetGameFlag(CurrentCutscene->GetEndingCutsceneFlag(),CurrentCutscene->GetEndingCutsceneVal());
CurrentCutscene=nullptr;
CurrentAction=ActionType::NONE;
}break; }break;
case ActionType::FADE:{ case ActionType::FADE:{
if (((Fade*)CurrentCutscene->GetAction())->FadeIn()&&CUTSCENE_FADE_VALUE>0) { if (((Fade*)CurrentCutscene->GetAction())->FadeIn()&&CUTSCENE_FADE_VALUE>0) {
@ -315,6 +330,9 @@ goes on a very long time, I hope you can understand this is only for testing pur
} }
} }
}break; }break;
case ActionType::FADE_ASYNC:{
AddAsyncCutsceneAction(FadeAsync);
}break;
case ActionType::DIALOG:{ case ActionType::DIALOG:{
if (!((DialogBox*)CurrentCutscene->GetAction())->MessageHasBeenShown()) { if (!((DialogBox*)CurrentCutscene->GetAction())->MessageHasBeenShown()) {
DisplayMessageBox(((DialogBox*)CurrentCutscene->GetAction())->GetMessage()); DisplayMessageBox(((DialogBox*)CurrentCutscene->GetAction())->GetMessage());
@ -324,6 +342,39 @@ goes on a very long time, I hope you can understand this is only for testing pur
CurrentCutscene->AdvanceAction(); CurrentCutscene->AdvanceAction();
} }
}break; }break;
case ActionType::DIALOG_ASYNC:{
DisplayMessageBox(((DialogBox*)CurrentCutscene->GetAction())->GetMessage());
CurrentCutscene->AdvanceAction();
}break;
}
for (int i=0;i<CUTSCENE_QUEUE.size();i++) {
switch (CUTSCENE_QUEUE[i]->GetActionType()) {
case ActionType::PAN_CAMERA_ASYNC:{
if (MoveCameraTowardsPoint((PanCameraAsync*)CUTSCENE_QUEUE[i])) {
CUTSCENE_QUEUE.erase(CUTSCENE_QUEUE.begin()+i--);
}
}break;
case ActionType::MOVE_CUTSCENE_OBJ_ASYNC:{
if (MoveObjectTowardsPoint(CurrentCutscene->GetCutsceneObjects()[((MoveCutsceneObjectAsync*)CUTSCENE_QUEUE[i])->GetObjectID()],((MoveCutsceneObjectAsync*)CUTSCENE_QUEUE[i])->GetTargetPos(),((MoveCutsceneObjectAsync*)CUTSCENE_QUEUE[i])->GetMovement(),((MoveCutsceneObjectAsync*)CUTSCENE_QUEUE[i])->GetMoveSpd())) {
CUTSCENE_QUEUE.erase(CUTSCENE_QUEUE.begin()+i--);
}
}break;
case ActionType::FADE_ASYNC:{
if (((FadeAsync*)CUTSCENE_QUEUE[i])->FadeIn()&&CUTSCENE_FADE_VALUE>0) {
CUTSCENE_FADE_VALUE=std::clamp(CUTSCENE_FADE_VALUE-((FadeAsync*)CUTSCENE_QUEUE[i])->GetFadeSpd(),0.0,255.0);
if (CUTSCENE_FADE_VALUE==0) {
CUTSCENE_QUEUE.erase(CUTSCENE_QUEUE.begin()+i--);
}
} else
if (!((FadeAsync*)CUTSCENE_QUEUE[i])->FadeIn()&&CUTSCENE_FADE_VALUE<255) {
CUTSCENE_FADE_VALUE=std::clamp(CUTSCENE_FADE_VALUE+((FadeAsync*)CUTSCENE_QUEUE[i])->GetFadeSpd(),0.0,255.0);
if (CUTSCENE_FADE_VALUE==255) {
CUTSCENE_QUEUE.erase(CUTSCENE_QUEUE.begin()+i--);
}
}
}break;
}
} }

Loading…
Cancel
Save