generated from AMay/CPlusPlusProjectTemplate
Async cutscene triggers implemented
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
7c5600bb01
commit
267310efd8
Binary file not shown.
77
SeasonI.code-workspace
Normal file
77
SeasonI.code-workspace
Normal file
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
58
cutscene.h
58
cutscene.h
@ -1,5 +1,4 @@
|
||||
#include "pixelGameEngine.h"
|
||||
#include <cstdarg>
|
||||
|
||||
#define CAMERA_MOVESPD 5
|
||||
|
||||
@ -19,12 +18,24 @@ enum class ActionType{
|
||||
SET_FLAG_WHEN_CUTSCENE_ENDS,
|
||||
FADE,
|
||||
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{
|
||||
bool queued=false; //Set to true when added to action asynchronous queue.
|
||||
public:
|
||||
virtual ActionType GetActionType(){};
|
||||
bool InQueue() {
|
||||
return queued;
|
||||
}
|
||||
void SetQueued(bool queued=true) {
|
||||
this->queued=queued;
|
||||
}
|
||||
};
|
||||
|
||||
class Cleanup:public CutsceneAction{
|
||||
@ -35,7 +46,7 @@ class Cleanup:public CutsceneAction{
|
||||
class Object;
|
||||
|
||||
class CreateObjects:public CutsceneAction{
|
||||
private:
|
||||
protected:
|
||||
std::vector<Object*>objs;
|
||||
public:
|
||||
template <class T>
|
||||
@ -52,7 +63,7 @@ class CreateObjects:public CutsceneAction{
|
||||
};
|
||||
|
||||
class PanCamera:public CutsceneAction{
|
||||
private:
|
||||
protected:
|
||||
vd2d targetPos;
|
||||
PriorityDirection dir;
|
||||
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{
|
||||
private:
|
||||
protected:
|
||||
int objID;
|
||||
vd2d targetPos;
|
||||
double moveSpd;
|
||||
@ -101,6 +119,13 @@ class MoveCutsceneObject:public CutsceneAction{
|
||||
PriorityDirection GetMovement() {
|
||||
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{
|
||||
@ -122,7 +147,7 @@ class SetFlagWhenCutsceneEnds:public CutsceneAction{
|
||||
};
|
||||
|
||||
class Fade:public CutsceneAction{
|
||||
private:
|
||||
protected:
|
||||
bool fadeIn=true; //If false, it fades out instead.
|
||||
double fadeSpd=0;
|
||||
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{
|
||||
private:
|
||||
protected:
|
||||
std::string message;
|
||||
bool messageBoxVisible=false;
|
||||
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.
|
||||
|
||||
@ -212,6 +253,9 @@ class Cutscene{
|
||||
void ResetCutscene(){
|
||||
actionMarker=0;
|
||||
actionIsActive=false;
|
||||
for (auto&action:actions) {
|
||||
action->SetQueued(false);
|
||||
}
|
||||
}
|
||||
Object*AddCutsceneObject(Object*obj) {
|
||||
this->cutsceneObjs.push_back(obj);
|
||||
|
||||
71
main.cpp
71
main.cpp
@ -18,6 +18,13 @@
|
||||
#define TILEMAP_EDITOR_DRAW_MULT 0.4375
|
||||
#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;
|
||||
|
||||
namespace layer{
|
||||
@ -136,6 +143,7 @@ public:
|
||||
Cutscene*CurrentCutscene=nullptr;
|
||||
ActionType CurrentAction=ActionType::NONE;
|
||||
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.
|
||||
@ -195,7 +203,6 @@ public:
|
||||
(CutsceneAction*)new MoveCutsceneObject(1,{80,64}),
|
||||
(CutsceneAction*)new DialogBox(R"(Hello!
|
||||
This is a test message that lets us trigger straight from a cutscene! Cool!)"),});
|
||||
|
||||
/*DisplayMessageBox(R"(Hello World!
|
||||
This is a rather long message, but I hope it reaches you well
|
||||
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);
|
||||
} else {
|
||||
Clear(BLANK);
|
||||
}
|
||||
}
|
||||
SetDrawTarget(layer::HIGH);
|
||||
Clear(BLANK);
|
||||
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();
|
||||
}
|
||||
}break;
|
||||
case ActionType::PAN_CAMERA_ASYNC:{
|
||||
AddAsyncCutsceneAction(PanCameraAsync);
|
||||
}break;
|
||||
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())) {
|
||||
CurrentCutscene->AdvanceAction();
|
||||
}
|
||||
}break;
|
||||
case ActionType::MOVE_CUTSCENE_OBJ_ASYNC:{
|
||||
AddAsyncCutsceneAction(MoveCutsceneObjectAsync);
|
||||
}break;
|
||||
case ActionType::CREATE_OBJECTS:{
|
||||
for (auto&obj:((CreateObjects*)CurrentCutscene->GetAction())->GetObjects()) {
|
||||
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();
|
||||
}break;
|
||||
case ActionType::CLEANUP:{
|
||||
for (int i=0;i<OBJECTS.size();i++) {
|
||||
if (OBJECTS[i]->temp) {
|
||||
OBJECTS.erase(OBJECTS.begin()+i--);
|
||||
if (CUTSCENE_QUEUE.size()==0) {
|
||||
for (int i=0;i<OBJECTS.size();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;
|
||||
case ActionType::FADE:{
|
||||
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;
|
||||
case ActionType::FADE_ASYNC:{
|
||||
AddAsyncCutsceneAction(FadeAsync);
|
||||
}break;
|
||||
case ActionType::DIALOG:{
|
||||
if (!((DialogBox*)CurrentCutscene->GetAction())->MessageHasBeenShown()) {
|
||||
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();
|
||||
}
|
||||
}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…
x
Reference in New Issue
Block a user