diff --git a/C++ProjectTemplate b/C++ProjectTemplate index efaa788..b26ef83 100755 Binary files a/C++ProjectTemplate and b/C++ProjectTemplate differ diff --git a/cutscene.h b/cutscene.h index 740f911..cdc1de3 100644 --- a/cutscene.h +++ b/cutscene.h @@ -22,8 +22,8 @@ enum class ActionType{ PAN_CAMERA_ASYNC, FADE_ASYNC, DIALOG_ASYNC, - MOVE_CUTSCENE_OBJ_ASYNC - //TODO: Change Sprites Action Type. + MOVE_CUTSCENE_OBJ_ASYNC, + MODIFY_OBJECT, }; class CutsceneAction{ @@ -44,6 +44,7 @@ class Cleanup:public CutsceneAction{ }; class Object; +class Animation; class CreateObjects:public CutsceneAction{ protected: @@ -204,6 +205,46 @@ class DialogBoxAsync:public DialogBox{ 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. diff --git a/main.cpp b/main.cpp index 5b52d88..b3f19ab 100644 --- a/main.cpp +++ b/main.cpp @@ -70,15 +70,16 @@ class Animation{ }; class Object{ + private: + vd2d scale={1,1}; public: int id; Animation*spr; vd2d pos; int frameIndex=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; - vd2d scale={1,1}; Pixel color=WHITE; vd2d originPoint={0,0}; bool drawn=false; @@ -101,6 +102,9 @@ class Object{ this->scale=scale; this->originPoint={spr->width/2*scale.x,(spr->spr->sprite->height-4)*scale.y}; } + vd2d GetScale() { + return scale; + } }; class SeasonI : public PixelGameEngine @@ -198,11 +202,13 @@ public: }), (CutsceneAction*)new Fade(true), (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 MoveCutsceneObject(1,{80,64}), - (CutsceneAction*)new DialogBox(R"(Hello! -This is a test message that lets us trigger straight from a cutscene! Cool!)"),}); + (CutsceneAction*)new DialogBoxAsync(R"(Hello! +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! This is a rather long message, but I hope it reaches you well 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:{ for (auto&obj:((CreateObjects*)CurrentCutscene->GetAction())->GetObjects()) { 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(); }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()); CurrentCutscene->AdvanceAction(); }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;idrawn&&obj->pos.y+obj->originPoint.y>(y+yTileOffset)*32&&obj->pos.y+obj->originPoint.y<=(y+yTileOffset+1)*32) { obj->drawn=true; 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;xname,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) {