Testing cutscene event triggers

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
master
sigonasr2 2 years ago
parent 74e328c8f0
commit 4d2f6ddcb7
  1. BIN
      C++ProjectTemplate
  2. 9
      cutscene.h
  3. 86
      main.cpp
  4. 2
      pixelGameEngine.h

Binary file not shown.

@ -20,7 +20,7 @@ enum class ActionType{
class CutsceneAction{
public:
virtual ActionType GetActionType()=0;
virtual ActionType GetActionType(){};
};
class Cleanup:public CutsceneAction{
@ -42,7 +42,9 @@ class CreateObjects:public CutsceneAction{
}
}
ActionType GetActionType() override{return ActionType::CREATE_OBJECTS;}
std::vector<Object*> GetObjects();
std::vector<Object*> GetObjects() {
return objs;
};
};
class PanCamera:public CutsceneAction{
@ -94,6 +96,9 @@ class Cutscene{
}
this->actions.push_back(new Cleanup());
}
CutsceneAction*GetAction(){
return actions[actionMarker];
}
ActionType CurrentAction(){
if (!actionIsActive&&actionMarker<actions.size()) {
return actions[actionMarker]->GetActionType();

@ -132,6 +132,8 @@ public:
bool messageBoxLoad=false; //Set to true when ready to load a message in.
std::map<int,vi2d> additionalChars;
Cutscene*TestCutscene;
Cutscene*CurrentCutscene=nullptr;
ActionType CurrentAction=ActionType::NONE;
bool MOUSE_PRESSED_DOWN=false,MOUSE_DOWN=false,MOUSE_RELEASED=false; //TODO Implement Mouse things.
@ -179,9 +181,11 @@ public:
TestCutscene=new Cutscene({
(CutsceneAction*)new PanCamera({128,128},BOTH),
(CutsceneAction*)new PanCamera({128,128},BOTH),
(CutsceneAction*)new PanCamera({128,0},BOTH),
(CutsceneAction*)new CreateObjects({
new Object(PLAYER,"player",{64,64},ANIMATIONS["player.png"],{1,1},MAGENTA)
new Object(PLAYER,"player",{64,64},ANIMATIONS["player.png"],{1,1},MAGENTA),
new Object(PLAYER,"player",{136,136},ANIMATIONS["player.png"],{1,1},RED),
new Object(PLAYER,"player",{96,96},ANIMATIONS["player.png"],{1,1},DARK_GREEN),
}),});
/*DisplayMessageBox(R"(Hello World!
@ -190,6 +194,8 @@ 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;
}
@ -246,6 +252,26 @@ goes on a very long time, I hope you can understand this is only for testing pur
}
}
if (GetCurrentCutsceneAction()!=ActionType::NONE) {
CurrentAction=GetCurrentCutsceneAction();
CurrentCutscene->LockAction();
}
switch (CurrentAction) {
case ActionType::PAN_CAMERA:{
if (MoveCameraTowardsPoint((PanCamera*)CurrentCutscene->GetAction())) {
CurrentCutscene->AdvanceAction();
}
}break;
case ActionType::CREATE_OBJECTS:{
for (auto&obj:((CreateObjects*)CurrentCutscene->GetAction())->GetObjects()) {
obj->temp=true;
AddObjectToWorld(obj);
}
CurrentCutscene->AdvanceAction();
}break;
}
switch (GAME_STATE) {
case GameState::TILE_SELECT:{
if (!TabHeld()) {
@ -792,6 +818,8 @@ goes on a very long time, I hope you can understand this is only for testing pur
return SPRITES[spriteName];
}
//You're probably trying to add an object to the world. Use this function inside of AddObjectToWorld(CreateObject(...))
//You only need to use this function if you want to create an object from pre-defined OBJ_INFO variables.
Object*CreateObject(int id,vd2d pos) {
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);
}
@ -1082,7 +1110,7 @@ goes on a very long time, I hope you can understand this is only for testing pur
void AddObjectToWorld(Object*obj) {
std::vector<Object*>::const_iterator it = OBJECTS.begin();
if (obj->id==PLAYER) {
if (obj->id==PLAYER&&!obj->temp) {
PLAYER_OBJ=obj;
}
bool inserted=false;
@ -1187,13 +1215,63 @@ goes on a very long time, I hope you can understand this is only for testing pur
}break;
}
}
void StartCutscene(Cutscene*cutscene) {
CurrentCutscene=cutscene;
}
ActionType GetCurrentCutsceneAction() {
return (CurrentCutscene==nullptr)?ActionType::NONE:CurrentCutscene->CurrentAction();
}
bool MoveCameraTowardsPoint(PanCamera*pan,bool secondRun=false) {
bool reachedPosition=true;
if (pan->GetPriorityDirection()==HORZ_FIRST||pan->GetPriorityDirection()==BOTH) {
if (cameraPos.x!=pan->GetCameraTargetPos().x) {
if (cameraPos.x<pan->GetCameraTargetPos().x) {
cameraPos.x+=pan->GetCameraSpeed();
if (cameraPos.x>pan->GetCameraTargetPos().x) {
cameraPos.x=pan->GetCameraTargetPos().x;
}
} else {
cameraPos.x-=pan->GetCameraSpeed();
if (cameraPos.x<pan->GetCameraTargetPos().x) {
cameraPos.x=pan->GetCameraTargetPos().x;
}
}
reachedPosition=false;
} else
if (!secondRun&&pan->GetPriorityDirection()!=BOTH) {
MoveCameraTowardsPoint(pan,true);
}
}
if (pan->GetPriorityDirection()==VERT_FIRST||pan->GetPriorityDirection()==BOTH) {
if (cameraPos.y!=pan->GetCameraTargetPos().y) {
if (cameraPos.y<pan->GetCameraTargetPos().y) {
cameraPos.y+=pan->GetCameraSpeed();
if (cameraPos.y>pan->GetCameraTargetPos().y) {
cameraPos.y=pan->GetCameraTargetPos().y;
}
} else {
cameraPos.y-=pan->GetCameraSpeed();
if (cameraPos.y<pan->GetCameraTargetPos().y) {
cameraPos.y=pan->GetCameraTargetPos().y;
}
}
reachedPosition=false;
} else
if (!secondRun&&pan->GetPriorityDirection()!=BOTH) {
MoveCameraTowardsPoint(pan,true);
}
}
return reachedPosition;
}
};
int main()
{
SeasonI demo;
if (demo.Construct(WIDTH, HEIGHT, 4, 4))
if (demo.Construct(WIDTH, HEIGHT, 4, 4,false,false,true))
demo.Start();
return 0;

@ -3554,7 +3554,7 @@ namespace olc
nLastFPS = nFrameCount;
fFrameTimer -= 1.0f;
std::string sTitle = "OneLoneCoder.com - Pixel Game Engine - " + sAppName + " - FPS: " + std::to_string(nFrameCount);
platform->SetWindowTitle(sTitle);
platform->SetWindowTitle("sTitle");
nFrameCount = 0;
}
}

Loading…
Cancel
Save