generated from sigonasr2/CPlusPlusProjectTemplate
Creation and deletion of objects in cutscenes successful.
Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
4d2f6ddcb7
commit
caaee07b89
Binary file not shown.
18
cutscene.h
18
cutscene.h
@ -82,6 +82,7 @@ class Cutscene{
|
|||||||
int actionMarker=0;
|
int actionMarker=0;
|
||||||
std::vector<CutsceneAction*> actions;
|
std::vector<CutsceneAction*> actions;
|
||||||
bool actionIsActive=false;
|
bool actionIsActive=false;
|
||||||
|
std::vector<Object*>cutsceneObjs;
|
||||||
public:
|
public:
|
||||||
template <class T>
|
template <class T>
|
||||||
Cutscene(std::initializer_list<T> actions) {
|
Cutscene(std::initializer_list<T> actions) {
|
||||||
@ -117,4 +118,21 @@ class Cutscene{
|
|||||||
actionMarker=0;
|
actionMarker=0;
|
||||||
actionIsActive=false;
|
actionIsActive=false;
|
||||||
}
|
}
|
||||||
|
Object*AddCutsceneObject(Object*obj) {
|
||||||
|
this->cutsceneObjs.push_back(obj);
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
std::vector<Object*> GetCutsceneObjects() {
|
||||||
|
return cutsceneObjs;
|
||||||
|
}
|
||||||
|
//Does things like reset cutscene flags and removing objects.
|
||||||
|
//
|
||||||
|
//MAKE SURE TO DELETE ALL OBJECTS IN THE OBJECTS WORLD ARRAY BEFORE CALLING THIS!
|
||||||
|
//THIS FUNCTION WILL DELETE THE POINTERS FOR YOU!
|
||||||
|
void CleanupCutscene() {
|
||||||
|
for (int i=0;i<cutsceneObjs.size();i++) {
|
||||||
|
delete cutsceneObjs[i];
|
||||||
|
}
|
||||||
|
cutsceneObjs.clear();
|
||||||
|
}
|
||||||
};
|
};
|
23
main.cpp
23
main.cpp
@ -80,7 +80,7 @@ class Object{
|
|||||||
int objArrElement; //Which element in the object array this object is located in. For sorting purposes.
|
int objArrElement; //Which element in the object array this object is located in. For sorting purposes.
|
||||||
bool temp=false; //If set to true, it's marked for deletion after cutscene handling.
|
bool temp=false; //If set to true, it's marked for deletion after cutscene handling.
|
||||||
//animationSpd is how long to wait before switching frames.
|
//animationSpd is how long to wait before switching frames.
|
||||||
Object(int id,std::string name,vd2d pos,Animation*spr,vd2d scale={1,1},Pixel color=WHITE,int animationSpd=1) {
|
Object(int id,std::string name,vd2d pos,Animation*spr,vd2d scale={1,1},Pixel color=WHITE,int animationSpd=1,bool temp=false) {
|
||||||
this->spr=spr;
|
this->spr=spr;
|
||||||
this->pos=pos;
|
this->pos=pos;
|
||||||
this->id=id;
|
this->id=id;
|
||||||
@ -88,6 +88,7 @@ class Object{
|
|||||||
this->color=color;
|
this->color=color;
|
||||||
this->animationSpd=animationSpd;
|
this->animationSpd=animationSpd;
|
||||||
SetScale(scale);
|
SetScale(scale);
|
||||||
|
this->temp=temp;
|
||||||
}
|
}
|
||||||
void SetScale(vd2d scale) {
|
void SetScale(vd2d scale) {
|
||||||
this->scale=scale;
|
this->scale=scale;
|
||||||
@ -266,10 +267,21 @@ goes on a very long time, I hope you can understand this is only for testing pur
|
|||||||
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;
|
||||||
AddObjectToWorld(obj);
|
AddObjectToWorld(CurrentCutscene->AddCutsceneObject(new Object(obj->id,obj->name,obj->pos,obj->spr,obj->scale,obj->color,obj->animationSpd,true)));
|
||||||
}
|
}
|
||||||
CurrentCutscene->AdvanceAction();
|
CurrentCutscene->AdvanceAction();
|
||||||
}break;
|
}break;
|
||||||
|
case ActionType::CLEANUP:{
|
||||||
|
for (int i=0;i<OBJECTS.size();i++) {
|
||||||
|
if (OBJECTS[i]->temp) {
|
||||||
|
OBJECTS.erase(OBJECTS.begin()+i--);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
CurrentCutscene->CleanupCutscene();
|
||||||
|
CurrentCutscene->ResetCutscene();
|
||||||
|
CurrentCutscene=nullptr;
|
||||||
|
StartCutscene(TestCutscene);
|
||||||
|
}break;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (GAME_STATE) {
|
switch (GAME_STATE) {
|
||||||
@ -1209,13 +1221,6 @@ goes on a very long time, I hope you can understand this is only for testing pur
|
|||||||
Draw({pos.x,pos.y+size.y-1},Pixel(77, 51, 125));
|
Draw({pos.x,pos.y+size.y-1},Pixel(77, 51, 125));
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlayCutscene(int scene) {
|
|
||||||
switch (scene) {
|
|
||||||
case cutscene::TEST_CUTSCENE:{
|
|
||||||
}break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void StartCutscene(Cutscene*cutscene) {
|
void StartCutscene(Cutscene*cutscene) {
|
||||||
CurrentCutscene=cutscene;
|
CurrentCutscene=cutscene;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user