Player animations more or less under control now. Moved to a toggle animation speed system instead

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
master
sigonasr2 2 years ago
parent 173cc0410d
commit c3e3ececcc
  1. BIN
      C++ProjectTemplate
  2. 1
      SeasonI.h
  3. 7
      assets/maps/map0
  4. 16
      assets/maps/newmap_5
  5. 40
      main.cpp
  6. 80
      object.h

Binary file not shown.

@ -71,6 +71,7 @@ class SeasonI:public PixelGameEngine{
bool LeftReleased();
bool RightReleased();
bool PlayerCanMove();
bool NPCCanMove();
void UpdatePlayerTrail(vd2d newMovement,Direction newFacingDir);
void SetupRollingHitpointCounters();
void AdvanceMessageBox();

@ -88,6 +88,13 @@ OBJECT192.000000;320.000000;90
OBJECT96.000000;320.000000;90
OBJECT160.000000;384.000000;90
OBJECT96.000000;416.000000;159
OBJECT448.000000;640.000000;16
OBJECT352.000000;640.000000;16
OBJECT544.000000;640.000000;16
OBJECT448.000000;704.000000;16
OBJECT352.000000;704.000000;16
OBJECT544.000000;704.000000;16
OBJECT448.000000;768.000000;16
ENCOUNTER64.000000;512.000000;90;2
ENCOUNTER192.000000;352.000000;100;1
ENCOUNTER480.000000;160.000000;100;3

@ -4,16 +4,16 @@
????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
??????????????????93;393;3??93:3:3:3;3??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
??????????0717??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
????????????????????????93??;3??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
????????????????????????????????15??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
??????????????????????065656565616??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
??????????????????????9256??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
????????????????????????56??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
????????????????????92??56??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
????????????????????????56??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????

@ -49,6 +49,7 @@ class DamageNumber{
};
int frameCount=0;
int partyTrailStepCount=0;
float elapsedTime=0;
const float TARGET_RATE = 1/60.0;
int MAP_WIDTH=-1;
@ -428,13 +429,13 @@ void SeasonI::SetupAnimations() {
}
void SeasonI::SetupObjectInfo() {
CreateObjectInfo(new NPC_Obj(PLAYER,"player",{0,0},nullptr,{2,2},WHITE,32),"player.png",{32,32});
CreateObjectInfo(new NPC_Obj(NESS,"Ness",{0,0},nullptr,{1,1},YELLOW,32),"player.png",{32,32});
CreateObjectInfo(new NPC_Obj(PAULA,"Paula",{0,0},nullptr,{1,1},MAGENTA,32),"player.png",{32,32});
CreateObjectInfo(new NPC_Obj(JEFF,"Jeff",{0,0},nullptr,{1,1},DARK_GREEN,32),"player.png",{32,32});
CreateObjectInfo(new NPC_Obj(ANNA,"Anna",{0,0},nullptr,{1,1},DARK_MAGENTA,32),"player.png",{32,32});
CreateObjectInfo(new NPC_Obj(KING,"King",{0,0},nullptr,{1,1},GREY,32),"player.png",{32,32});
CreateObjectInfo(new NPC_Obj(POO,"Poo",{0,0},nullptr,{1,1},DARK_GREY,32),"player.png",{32,32});
CreateObjectInfo(new NPC_Obj(PLAYER,"player",{0,0},nullptr,{2,2},WHITE,16),"player.png",{32,32});
CreateObjectInfo(new NPC_Obj(NESS,"Ness",{0,0},nullptr,{1,1},YELLOW,14),"player.png",{32,32});
CreateObjectInfo(new NPC_Obj(PAULA,"Paula",{0,0},nullptr,{1,1},MAGENTA,13),"player.png",{32,32});
CreateObjectInfo(new NPC_Obj(JEFF,"Jeff",{0,0},nullptr,{1,1},DARK_GREEN,15),"player.png",{32,32});
CreateObjectInfo(new NPC_Obj(ANNA,"Anna",{0,0},nullptr,{1,1},DARK_MAGENTA,12),"player.png",{32,32});
CreateObjectInfo(new NPC_Obj(KING,"King",{0,0},nullptr,{1,1},GREY,10),"player.png",{32,32});
CreateObjectInfo(new NPC_Obj(POO,"Poo",{0,0},nullptr,{1,1},DARK_GREY,17),"player.png",{32,32});
CreateObjectInfo(new NPC_Obj(NPC1,"npc1",{0,0},nullptr,{1,1},RED,60),"player.png",{32,32},Flag::NONE,Flag::NONE);
CreateObjectInfo(new NPC_Obj(NPC2,"npc2",{0,0},nullptr,{1,1},GREEN,2),"player.png",{32,32},Flag::NONE,Flag::NONE);
CreateObjectInfo(new NPC_Obj(NPC3,"npc3",{0,0},nullptr,{2,2},BLUE,20),"player.png",{32,32},Flag::NONE,Flag::NONE);
@ -444,7 +445,7 @@ void SeasonI::SetupObjectInfo() {
CreateObjectInfo(new NPC_Obj(NPC7,"npc7",{0,0},nullptr,{2,2},BLUE,20),"player.png",{32,32},Flag::NONE,Flag::NONE);
CreateObjectInfo(new NPC_Obj(NPC8,"npc8",{0,0},nullptr,{2,2},BLUE,20),"player.png",{32,32},Flag::NONE,Flag::NONE);
CreateObjectInfo(new NPC_Obj(NPC9,"npc9",{0,0},nullptr,{2,2},BLUE,20),"player.png",{32,32},Flag::NONE,Flag::NONE);
CreateObjectInfo(new NPC_Obj(NPC10,"npc10",{0,0},nullptr,{2,2},BLUE,20),"player.png",{32,32},Flag::NONE,Flag::NONE);
CreateObjectInfo(new NPC_Obj(NPC10,"npc10",{0,0},nullptr,{2,2},CYAN,20,false,{moveTime:180,moveFreq:60,moveSpd:1}),"player.png",{32,32},Flag::NONE,Flag::NONE);
CreateObjectInfo(new NPC_Obj(NPC11,"npc11",{0,0},nullptr,{2,2},BLUE,20),"player.png",{32,32},Flag::NONE,Flag::NONE);
CreateObjectInfo(new NPC_Obj(NPC12,"npc12",{0,0},nullptr,{2,2},BLUE,20),"player.png",{32,32},Flag::NONE,Flag::NONE);
CreateObjectInfo(new NPC_Obj(NPC13,"npc13",{0,0},nullptr,{2,2},BLUE,20),"player.png",{32,32},Flag::NONE,Flag::NONE);
@ -1071,7 +1072,7 @@ bool SeasonI::GetGameFlag(Flag flag) {
}
Object*SeasonI::CreateObject(int id,vd2d pos) {
return OBJ_INFO[id]->CreateType(id,OBJ_INFO[id]->name,pos,OBJ_INFO[id]->spr,OBJ_INFO[id]->GetScale(),OBJ_INFO[id]->color,OBJ_INFO[id]->animationSpd);
return OBJ_INFO[id]->CreateType(id,OBJ_INFO[id]->name,pos,OBJ_INFO[id]->spr,OBJ_INFO[id]->GetScale(),OBJ_INFO[id]->color,OBJ_INFO[id]->animationSpd,OBJ_INFO[id]->temp,OBJ_INFO[id]->extraData);
}
Object*SeasonI::AddObjectToWorld(Object*obj) {
@ -1189,10 +1190,13 @@ bool SeasonI::OnUserUpdate(float fElapsedTime)
void SeasonI::updateGame(){
frameCount++;
for (auto obj:OBJECTS) {
if (obj->animationSpd!=0&&obj->frameCount++>obj->animationSpd) {
if (obj->animated&&obj->animationSpd!=0&&obj->frameCount++>obj->animationSpd) {
obj->frameCount=0;
obj->frameIndex++;
}
if (NPCCanMove()) {
obj->Update();
}
}
if (!messageBoxVisible&&INTERACTION_MESSAGES.size()>0) {
@ -1270,7 +1274,7 @@ void SeasonI::updateGame(){
if (PlayerCanMove()) {
bool moved=false;
vd2d movementComponents = {0,0};
Direction facingDir=Direction::SOUTH;
Direction facingDir=(Direction)PARTY_MEMBER_OBJ[0]->animationSubIndex;
if (UpHeld()) {
movementComponents.y-=1;
facingDir=Direction::NORTH;
@ -1313,7 +1317,7 @@ void SeasonI::updateGame(){
}
PARTY_MEMBER_OBJ[0]->animationSubIndex=(int)facingDir;
if (movementComponents.mag()>0) {
PARTY_MEMBER_OBJ[0]->frameIndex+=frameCount%PARTY_MEMBER_OBJ[0]->originalAnimationSpd==0;
PARTY_MEMBER_OBJ[0]->frameIndex+=frameCount%PARTY_MEMBER_OBJ[0]->animationSpd==0;
if (PARTY_MEMBER_OBJ[0]->SmoothMove(movementComponents)) {
UpdatePlayerTrail(movementComponents,facingDir);
for (int i=0;i<CURRENT_MAP->triggers.size();i++) {
@ -1920,6 +1924,11 @@ void SeasonI::keyUpdates() {
case GameState::GAME_WORLD:{
if (GetKey(F5).bPressed) {
GAME_STATE=GameState::EDITOR;
for (int i=0;i<OBJECTS.size();i++) {
if (!OBJECTS[i]->enc) {
OBJECTS[i]->SetPos(OBJECTS[i]->GetStartPos());
}
}
} else
if (PlayerCanMove()&&ACTIONKEYPRESSED) {
GAME_STATE=GameState::OVERWORLD_MENU;
@ -3931,16 +3940,21 @@ bool SeasonI::PlayerCanMove(){
return GAME_STATE==GameState::GAME_WORLD&&BATTLE_ENCOUNTER==nullptr&&!IsTextEntryEnabled()&&!messageBoxVisible&&PARTY_MEMBER_OBJ[0]!=nullptr&&CurrentCutscene==nullptr;
}
bool SeasonI::NPCCanMove(){
return GAME_STATE==GameState::GAME_WORLD&&BATTLE_ENCOUNTER==nullptr&&!IsTextEntryEnabled()&&!messageBoxVisible;
}
void SeasonI::UpdatePlayerTrail(vd2d newMovement,Direction newFacingDir) {
for (int i=PARTY_TRAIL_LENGTH-1;i>0;i--) {
partyTrail[i]=partyTrail[i-1];
}
partyTrailStepCount++;
partyTrail[0]={{PARTY_MEMBER_OBJ[0]->GetPos().x-newMovement.x+PARTY_MEMBER_OBJ[0]->spr->sprSize.x*0.5*(PARTY_MEMBER_OBJ[0]->GetScale().x-1),
PARTY_MEMBER_OBJ[0]->GetPos().y-newMovement.y+(PARTY_MEMBER_OBJ[0]->spr->sprSize.y-4)*(PARTY_MEMBER_OBJ[0]->GetScale().y-1)},newFacingDir};
for (int i=1;i<PARTY_MEMBER_COUNT;i++) {
PARTY_MEMBER_OBJ[i]->SetPos(partyTrail[PARTY_TRAIL_LENGTH*((double)i/4)].first);
PARTY_MEMBER_OBJ[i]->animationSubIndex=(int)partyTrail[PARTY_TRAIL_LENGTH*((double)i/4)].second;
PARTY_MEMBER_OBJ[i]->frameIndex+=(int)(PARTY_TRAIL_LENGTH*((double)i/4))%PARTY_MEMBER_OBJ[i]->originalAnimationSpd==0;
PARTY_MEMBER_OBJ[i]->frameIndex+=partyTrailStepCount%PARTY_MEMBER_OBJ[i]->animationSpd==0;
}
}

@ -27,6 +27,7 @@ class Object{
private:
vd2d scale={1,1};
vd2d pos;
vd2d startPos; //Where the object was first located. The object will be put back here if we enter the editor.
public:
int id;
Animation*spr;
@ -35,6 +36,7 @@ class Object{
int frameCount=0;
int animationSpd=12; //How many frames to wait between each frame. Setting to 0 pauses the animation.
std::string name;
bool animated=true;
Pixel color=WHITE;
vd2d originPoint={0,0};
bool drawn=false;
@ -57,7 +59,8 @@ class Object{
Object(int id,std::string name,int gridx,int gridy,Animation*spr,vd2d scale={1,1},Pixel color=WHITE,int animationSpd=1,bool temp=false,ObjectExtraData data={moveTime:0,moveFreq:0,moveSpd:0})
:Object(id,name,{gridx*32-(spr->sprSize.x*0.5)*(scale.x-1),gridy*32-(spr->sprSize.y-4)*(scale.y-1)},spr,scale,color,animationSpd,temp,data) {}
Object(int id,std::string name,vd2d pos,Animation*spr,vd2d scale={1,1},Pixel color=WHITE,int animationSpd=1,bool temp=false,ObjectExtraData data={moveTime:0,moveFreq:0,moveSpd:0})
:spr(spr),pos(pos),id(id),name(name),color(color),animationSpd(animationSpd),temp(temp),extraData(data) {
:spr(spr),pos(pos),id(id),name(name),color(color),animationSpd(animationSpd),temp(temp),extraData(data),startPos(pos) {
printf("Extra data:%d %d %lf\n",extraData.moveFreq,extraData.moveTime,extraData.moveSpd);
SetScale(scale);
}
virtual Object* CreateType(int id,std::string name,vd2d pos,Animation*spr,vd2d scale={1,1},Pixel color=WHITE,int animationSpd=1,bool temp=false,ObjectExtraData data={moveTime:0,moveFreq:0,moveSpd:0})=0;
@ -66,7 +69,7 @@ class Object{
virtual void ChoiceMade(int choice)=0;
virtual void DialogClosed()=0;
virtual void ShoppingCompleted()=0;
virtual void Update(float fElapsedTime)=0;
virtual void Update()=0;
void SetScale(vd2d scale) {
this->scale=scale;
if (spr!=nullptr) {
@ -79,6 +82,10 @@ class Object{
vd2d GetPos() {
return pos;
}
//Get where the object was first located. The object will be put back here if we enter the editor.
vd2d GetStartPos() {
return startPos;
}
void Move(vd2d move);
void SetPos(vd2d pos) {
Move(pos-this->pos);
@ -183,46 +190,49 @@ class Standard_Obj : public Object{
void DialogClosed()override{};
void ChoiceMade(int choice)override{};
void ShoppingCompleted()override{};
void Update(float fElapsedTime)override{};
void Update()override{};
};
class NPC_Obj : public Standard_Obj{
float remainingMoveTime=0;
Direction moveDir=Direction::SOUTH;
public:
int originalAnimationSpd=0;
NPC_Obj(int id,std::string name,vd2d pos,Animation*spr,vd2d scale={1,1},Pixel color=WHITE,int animationSpd=1,bool temp=false)\
:Standard_Obj(id,name,pos,spr,scale,color,animationSpd,temp),originalAnimationSpd(animationSpd){
animationSpd=0;
NPC_Obj(int id,std::string name,vd2d pos,Animation*spr,vd2d scale={1,1},Pixel color=WHITE,int animationSpd=1,bool temp=false,ObjectExtraData data={moveTime:0,moveFreq:0,moveSpd:0})
:Standard_Obj(id,name,pos,spr,scale,color,animationSpd,temp,data){
animated=false;
frameIndex=0;
}
void Update(float fElapsedTime)override{
if (rand()%extraData.moveFreq==0) {
remainingMoveTime=extraData.moveTime;
moveDir=(Direction)(rand()%4);
}
if (remainingMoveTime>0) {
vd2d moveVector;
animationSubIndex=(int)moveDir;
animationSpd=originalAnimationSpd;
switch (moveDir) {
case Direction::SOUTH:{
moveVector={0,1};
}break;
case Direction::EAST:{
moveVector={1,0};
}break;
case Direction::WEST:{
moveVector={-1,0};
}break;
case Direction::NORTH:{
moveVector={0,-1};
}break;
Object* CreateType(int id,std::string name,vd2d pos,Animation*spr,vd2d scale={1,1},Pixel color=WHITE,int animationSpd=1,bool temp=false,ObjectExtraData data={moveTime:0,moveFreq:0,moveSpd:0})override{
return new NPC_Obj(id,name,pos,spr,scale,color,animationSpd,temp,data);
}
void Update()override{
if (extraData.moveFreq>0) {
if (remainingMoveTime>0) {
vd2d moveVector;
animationSubIndex=(int)moveDir;
switch (moveDir) {
case Direction::SOUTH:{
moveVector={0,1};
}break;
case Direction::EAST:{
moveVector={1,0};
}break;
case Direction::WEST:{
moveVector={-1,0};
}break;
case Direction::NORTH:{
moveVector={0,-1};
}break;
}
animated=SmoothMove(moveVector*extraData.moveSpd);
remainingMoveTime--;
} else {
if (rand()%extraData.moveFreq==0) {
remainingMoveTime=extraData.moveTime;
moveDir=(Direction)(rand()%4);
}
animated=false;
}
SmoothMove(moveVector*extraData.moveSpd);
remainingMoveTime-=fElapsedTime;
} else {
animationSpd=0;
}
}
};
@ -235,7 +245,7 @@ class TrashCan_Obj : public Object{
void DialogClosed()override{};
void ChoiceMade(int choice)override{};
void ShoppingCompleted()override{};
void Update(float fElapsedTime)override{};
void Update()override{};
};
extern int MESSAGE_BOX_DIALOG_ANSWER;
@ -262,7 +272,7 @@ class Shopkeeper_Obj : public Object{
>0:Please take a look through our wares.\
>1:What would you like to sell?\
>2:Are you okay?<";
void Update(float fElapsedTime)override{};
void Update()override{};
Interaction Interact()override{
if (GAME->GetGameFlag(Flag::SHOPKEER_BRANCH1)) {
GAME_FLAGS[(int)Flag::SHOPKEER_BRANCH1]=false;

Loading…
Cancel
Save