generated from sigonasr2/CPlusPlusProjectTemplate
Implemented object movement during cutscenes.
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
a89540ab70
commit
7c5600bb01
Binary file not shown.
30
cutscene.h
30
cutscene.h
@ -19,6 +19,7 @@ enum class ActionType{
|
|||||||
SET_FLAG_WHEN_CUTSCENE_ENDS,
|
SET_FLAG_WHEN_CUTSCENE_ENDS,
|
||||||
FADE,
|
FADE,
|
||||||
DIALOG,
|
DIALOG,
|
||||||
|
MOVE_CUTSCENE_OBJ
|
||||||
};
|
};
|
||||||
|
|
||||||
class CutsceneAction{
|
class CutsceneAction{
|
||||||
@ -73,6 +74,35 @@ class PanCamera:public CutsceneAction{
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class MoveCutsceneObject:public CutsceneAction{
|
||||||
|
private:
|
||||||
|
int objID;
|
||||||
|
vd2d targetPos;
|
||||||
|
double moveSpd;
|
||||||
|
PriorityDirection dir;
|
||||||
|
public:
|
||||||
|
MoveCutsceneObject(int objID,vd2d targetPos,double moveSpd=CAMERA_MOVESPD,PriorityDirection dir=BOTH) {
|
||||||
|
this->objID=objID;
|
||||||
|
this->targetPos=targetPos;
|
||||||
|
this->moveSpd=moveSpd;
|
||||||
|
this->dir=dir;
|
||||||
|
}
|
||||||
|
ActionType GetActionType() override{return ActionType::MOVE_CUTSCENE_OBJ;}
|
||||||
|
//Based on how they were created in the cutscene, an object ID starting from 0 indicating which object you want to manipulate.
|
||||||
|
int GetObjectID() {
|
||||||
|
return objID;
|
||||||
|
}
|
||||||
|
double GetMoveSpd() {
|
||||||
|
return moveSpd;
|
||||||
|
}
|
||||||
|
vd2d GetTargetPos() {
|
||||||
|
return targetPos;
|
||||||
|
}
|
||||||
|
PriorityDirection GetMovement() {
|
||||||
|
return dir;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
class SetFlagWhenCutsceneEnds:public CutsceneAction{
|
class SetFlagWhenCutsceneEnds:public CutsceneAction{
|
||||||
private:
|
private:
|
||||||
Flag flag;
|
Flag flag;
|
||||||
|
49
main.cpp
49
main.cpp
@ -192,6 +192,7 @@ public:
|
|||||||
(CutsceneAction*)new SetFlagWhenCutsceneEnds(Flag::TEST_FLAG1),
|
(CutsceneAction*)new SetFlagWhenCutsceneEnds(Flag::TEST_FLAG1),
|
||||||
(CutsceneAction*)new PanCamera({128,128},BOTH),
|
(CutsceneAction*)new PanCamera({128,128},BOTH),
|
||||||
(CutsceneAction*)new PanCamera({64,0},BOTH),
|
(CutsceneAction*)new PanCamera({64,0},BOTH),
|
||||||
|
(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!)"),});
|
||||||
|
|
||||||
@ -276,6 +277,11 @@ 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::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::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;
|
||||||
@ -1309,6 +1315,49 @@ goes on a very long time, I hope you can understand this is only for testing pur
|
|||||||
return reachedPosition;
|
return reachedPosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool MoveObjectTowardsPoint(Object*obj,vd2d targetPos,PriorityDirection dir,double moveSpd,bool secondRun=false) {
|
||||||
|
bool reachedPosition=true;
|
||||||
|
if (dir==HORZ_FIRST||dir==BOTH) {
|
||||||
|
if (obj->pos.x!=targetPos.x) {
|
||||||
|
if (obj->pos.x<targetPos.x) {
|
||||||
|
obj->pos.x+=moveSpd;
|
||||||
|
if (obj->pos.x>targetPos.x) {
|
||||||
|
obj->pos.x=targetPos.x;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
obj->pos.x-=moveSpd;
|
||||||
|
if (obj->pos.x<targetPos.x) {
|
||||||
|
obj->pos.x=targetPos.x;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
reachedPosition=false;
|
||||||
|
} else
|
||||||
|
if (!secondRun&&dir!=BOTH) {
|
||||||
|
MoveObjectTowardsPoint(obj,targetPos,dir,moveSpd,true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (dir==VERT_FIRST||dir==BOTH) {
|
||||||
|
if (obj->pos.y!=targetPos.y) {
|
||||||
|
if (obj->pos.y<targetPos.y) {
|
||||||
|
obj->pos.y+=moveSpd;
|
||||||
|
if (obj->pos.y>targetPos.y) {
|
||||||
|
obj->pos.y=targetPos.y;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
obj->pos.y-=moveSpd;
|
||||||
|
if (obj->pos.y<targetPos.y) {
|
||||||
|
obj->pos.y=targetPos.y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
reachedPosition=false;
|
||||||
|
} else
|
||||||
|
if (!secondRun&&dir!=BOTH) {
|
||||||
|
MoveObjectTowardsPoint(obj,targetPos,dir,moveSpd,true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return reachedPosition;
|
||||||
|
}
|
||||||
|
|
||||||
void SetGameFlag(Flag flag,bool val) {
|
void SetGameFlag(Flag flag,bool val) {
|
||||||
GAME_FLAGS[flagint(flag)]=val;
|
GAME_FLAGS[flagint(flag)]=val;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user