Add Object modifying

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
master
sigonasr2 2 years ago
parent 267310efd8
commit ec34c66382
  1. BIN
      C++ProjectTemplate
  2. 45
      cutscene.h
  3. 36
      main.cpp

Binary file not shown.

@ -22,8 +22,8 @@ enum class ActionType{
PAN_CAMERA_ASYNC, PAN_CAMERA_ASYNC,
FADE_ASYNC, FADE_ASYNC,
DIALOG_ASYNC, DIALOG_ASYNC,
MOVE_CUTSCENE_OBJ_ASYNC MOVE_CUTSCENE_OBJ_ASYNC,
//TODO: Change Sprites Action Type. MODIFY_OBJECT,
}; };
class CutsceneAction{ class CutsceneAction{
@ -44,6 +44,7 @@ class Cleanup:public CutsceneAction{
}; };
class Object; class Object;
class Animation;
class CreateObjects:public CutsceneAction{ class CreateObjects:public CutsceneAction{
protected: protected:
@ -204,6 +205,46 @@ class DialogBoxAsync:public DialogBox{
ActionType GetActionType() override{return ActionType::DIALOG_ASYNC;} ActionType GetActionType() override{return ActionType::DIALOG_ASYNC;}
}; };
class ModifyObject:public CutsceneAction{
protected:
int objID;
vd2d scale;
Pixel col;
Animation*spr;
int animationFrame; //Defaults to -1, meaning don't touch the animation frame at all.
int animationSpd; //How many frames to wait between each animation frame. Setting to 0 pauses the animation.
public:
ModifyObject(int objID,Animation*spr,vd2d scale={1,1},Pixel col=WHITE,int animationFrame=-1,int animationSpd=12) {
this->objID=objID;
this->scale=scale;
this->col=col;
this->spr=spr;
this->animationFrame=animationFrame;
this->animationSpd=animationSpd;
}
ActionType GetActionType() override{return ActionType::MODIFY_OBJECT;}
int GetCutsceneObjID(){
return objID;
}
vd2d GetObjScale() {
return scale;
}
Pixel GetObjCol() {
return col;
}
Animation*GetObjSpr() {
return spr;
}
//Defaults to -1, meaning don't touch the animation frame at all.
int GetFrameIndex() {
return animationFrame;
}
//How many frames to wait between each animation frame. Setting to 0 pauses the animation.
int GetAnimationSpeed() {
return animationSpd;
}
};
/* /*
To use this class, specify multiple actions back-to-back, filling their appropriate arguments. To use this class, specify multiple actions back-to-back, filling their appropriate arguments.

@ -70,15 +70,16 @@ class Animation{
}; };
class Object{ class Object{
private:
vd2d scale={1,1};
public: public:
int id; int id;
Animation*spr; Animation*spr;
vd2d pos; vd2d pos;
int frameIndex=0; int frameIndex=0;
int frameCount=0; int frameCount=0;
int animationSpd=12; //How many frames to wait between each frame. int animationSpd=12; //How many frames to wait between each frame. Setting to 0 pauses the animation.
std::string name; std::string name;
vd2d scale={1,1};
Pixel color=WHITE; Pixel color=WHITE;
vd2d originPoint={0,0}; vd2d originPoint={0,0};
bool drawn=false; bool drawn=false;
@ -101,6 +102,9 @@ class Object{
this->scale=scale; this->scale=scale;
this->originPoint={spr->width/2*scale.x,(spr->spr->sprite->height-4)*scale.y}; this->originPoint={spr->width/2*scale.x,(spr->spr->sprite->height-4)*scale.y};
} }
vd2d GetScale() {
return scale;
}
}; };
class SeasonI : public PixelGameEngine class SeasonI : public PixelGameEngine
@ -198,11 +202,13 @@ public:
}), }),
(CutsceneAction*)new Fade(true), (CutsceneAction*)new Fade(true),
(CutsceneAction*)new SetFlagWhenCutsceneEnds(Flag::TEST_FLAG1), (CutsceneAction*)new SetFlagWhenCutsceneEnds(Flag::TEST_FLAG1),
(CutsceneAction*)new PanCamera({128,128},BOTH), (CutsceneAction*)new PanCamera({128,128},BOTH,1),
(CutsceneAction*)new MoveCutsceneObjectAsync(1,{80,64},5),
(CutsceneAction*)new PanCamera({64,0},BOTH), (CutsceneAction*)new PanCamera({64,0},BOTH),
(CutsceneAction*)new MoveCutsceneObject(1,{80,64}), (CutsceneAction*)new DialogBoxAsync(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!)"),}); (CutsceneAction*)new ModifyObject(0,ANIMATIONS["player.png"],{5,5},MAGENTA),
(CutsceneAction*)new MoveCutsceneObject(1,{320,64},1),});
/*DisplayMessageBox(R"(Hello World! /*DisplayMessageBox(R"(Hello World!
This is a rather long message, but I hope it reaches you well This is a rather long message, but I hope it reaches you well
in some form or capacity or another. Even though it in some form or capacity or another. Even though it
@ -298,7 +304,7 @@ 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(CurrentCutscene->AddCutsceneObject(new Object(obj->id,obj->name,obj->pos,obj->spr,obj->scale,obj->color,obj->animationSpd,true))); AddObjectToWorld(CurrentCutscene->AddCutsceneObject(new Object(obj->id,obj->name,obj->pos,obj->spr,obj->GetScale(),obj->color,obj->animationSpd,true)));
} }
CurrentCutscene->AdvanceAction(); CurrentCutscene->AdvanceAction();
}break; }break;
@ -346,6 +352,18 @@ goes on a very long time, I hope you can understand this is only for testing pur
DisplayMessageBox(((DialogBox*)CurrentCutscene->GetAction())->GetMessage()); DisplayMessageBox(((DialogBox*)CurrentCutscene->GetAction())->GetMessage());
CurrentCutscene->AdvanceAction(); CurrentCutscene->AdvanceAction();
}break; }break;
case ActionType::MODIFY_OBJECT:{
ModifyObject*action=(ModifyObject*)CurrentCutscene->GetAction();
Object*obj=CurrentCutscene->GetCutsceneObjects()[action->GetCutsceneObjID()];
obj->SetScale(action->GetObjScale());
obj->color=action->GetObjCol();
obj->spr=action->GetObjSpr();
if (action->GetFrameIndex()!=-1) {
obj->frameIndex=action->GetFrameIndex();
}
obj->animationSpd=action->GetAnimationSpeed();
CurrentCutscene->AdvanceAction();
}break;
} }
for (int i=0;i<CUTSCENE_QUEUE.size();i++) { for (int i=0;i<CUTSCENE_QUEUE.size();i++) {
@ -625,7 +643,7 @@ goes on a very long time, I hope you can understand this is only for testing pur
if (!obj->drawn&&obj->pos.y+obj->originPoint.y>(y+yTileOffset)*32&&obj->pos.y+obj->originPoint.y<=(y+yTileOffset+1)*32) { if (!obj->drawn&&obj->pos.y+obj->originPoint.y>(y+yTileOffset)*32&&obj->pos.y+obj->originPoint.y<=(y+yTileOffset+1)*32) {
obj->drawn=true; obj->drawn=true;
SetDrawTarget(layer::DYNAMIC); SetDrawTarget(layer::DYNAMIC);
DrawPartialDecal(obj->pos-cameraPos,obj->spr->spr,{(obj->frameIndex%obj->spr->frames)*obj->spr->width,0},{obj->spr->width,obj->spr->spr->sprite->height},obj->scale,obj->color); DrawPartialDecal(obj->pos-cameraPos,obj->spr->spr,{(obj->frameIndex%obj->spr->frames)*obj->spr->width,0},{obj->spr->width,obj->spr->spr->sprite->height},obj->GetScale(),obj->color);
} }
} }
for (int x=-1;x<WIDTH/32+2;x++) { for (int x=-1;x<WIDTH/32+2;x++) {
@ -928,7 +946,7 @@ goes on a very long time, I hope you can understand this is only for testing pur
//You're probably trying to add an object to the world. Use this function inside of AddObjectToWorld(CreateObject(...)) //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. //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) { 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); return new Object(id,OBJ_INFO[id]->name,pos,OBJ_INFO[id]->spr,OBJ_INFO[id]->GetScale(),OBJ_INFO[id]->color,OBJ_INFO[id]->animationSpd);
} }
Object*CreateObjectInfo(Reference ref,std::string name,vd2d pos,std::string spriteFileName,int sprWidth,vd2d scale={1,1},Pixel tint=WHITE,Flag enableFlag=Flag::NONE,Flag disableFlag=Flag::NONE,int animationDelay=1) { Object*CreateObjectInfo(Reference ref,std::string name,vd2d pos,std::string spriteFileName,int sprWidth,vd2d scale={1,1},Pixel tint=WHITE,Flag enableFlag=Flag::NONE,Flag disableFlag=Flag::NONE,int animationDelay=1) {

Loading…
Cancel
Save