generated from sigonasr2/CPlusPlusProjectTemplate
parent
768b010016
commit
74e328c8f0
Binary file not shown.
@ -0,0 +1,115 @@ |
||||
#include "pixelGameEngine.h" |
||||
#include <cstdarg> |
||||
|
||||
#define CAMERA_MOVESPD 5 |
||||
|
||||
using namespace olc; |
||||
|
||||
enum PriorityDirection{ |
||||
HORZ_FIRST, |
||||
VERT_FIRST, |
||||
BOTH |
||||
}; |
||||
|
||||
enum class ActionType{ |
||||
NONE, |
||||
PAN_CAMERA, |
||||
CREATE_OBJECTS, |
||||
CLEANUP |
||||
}; |
||||
|
||||
class CutsceneAction{ |
||||
public: |
||||
virtual ActionType GetActionType()=0; |
||||
}; |
||||
|
||||
class Cleanup:public CutsceneAction{ |
||||
public: |
||||
ActionType GetActionType() override{return ActionType::CLEANUP;} |
||||
}; |
||||
|
||||
class Object; |
||||
|
||||
class CreateObjects:public CutsceneAction{ |
||||
private: |
||||
std::vector<Object*>objs; |
||||
public: |
||||
template <class T> |
||||
CreateObjects(std::initializer_list<T> objs) { |
||||
for( auto elem : objs ) |
||||
{ |
||||
this->objs.push_back(elem); |
||||
} |
||||
} |
||||
ActionType GetActionType() override{return ActionType::CREATE_OBJECTS;} |
||||
std::vector<Object*> GetObjects(); |
||||
}; |
||||
|
||||
class PanCamera:public CutsceneAction{ |
||||
private: |
||||
vd2d targetPos; |
||||
PriorityDirection dir; |
||||
double cameraSpd; |
||||
public: |
||||
PanCamera(vd2d targetPos,PriorityDirection dir,double cameraSpd=CAMERA_MOVESPD) { |
||||
this->targetPos=targetPos; |
||||
this->dir=dir; |
||||
this->cameraSpd=cameraSpd; |
||||
} |
||||
ActionType GetActionType() override{return ActionType::PAN_CAMERA;} |
||||
vd2d GetCameraTargetPos() { |
||||
return targetPos; |
||||
} |
||||
PriorityDirection GetPriorityDirection() { |
||||
return dir; |
||||
} |
||||
double GetCameraSpeed() { |
||||
return cameraSpd; |
||||
} |
||||
}; |
||||
|
||||
/*
|
||||
To use this class, specify multiple actions back-to-back, filling their appropriate arguments. |
||||
|
||||
In responsive events, poll what CurrentAction() is, and if it's suitable, then use LockAction() |
||||
to lock the event and perform whatever actions are required. When the cutscene action is complete, |
||||
you can advance the action using AdvanceAction(). |
||||
*/ |
||||
class Cutscene{ |
||||
private: |
||||
int actionMarker=0; |
||||
std::vector<CutsceneAction*> actions; |
||||
bool actionIsActive=false; |
||||
public: |
||||
template <class T> |
||||
Cutscene(std::initializer_list<T> actions) { |
||||
AddAction(actions); |
||||
}; |
||||
template <class T> |
||||
void AddAction( std::initializer_list<T> actions ) |
||||
{ |
||||
for( auto elem : actions ) |
||||
{ |
||||
this->actions.push_back(elem); |
||||
} |
||||
this->actions.push_back(new Cleanup()); |
||||
} |
||||
ActionType CurrentAction(){ |
||||
if (!actionIsActive&&actionMarker<actions.size()) { |
||||
return actions[actionMarker]->GetActionType(); |
||||
} else { |
||||
return ActionType::NONE; |
||||
} |
||||
} |
||||
void LockAction() { |
||||
actionIsActive=true; |
||||
} |
||||
void AdvanceAction(){ |
||||
actionIsActive=false; |
||||
actionMarker++; |
||||
} |
||||
void ResetCutscene(){ |
||||
actionMarker=0; |
||||
actionIsActive=false; |
||||
} |
||||
}; |
Loading…
Reference in new issue