From 5566eced77f01ebcc28743dbe9e7e59485a37132 Mon Sep 17 00:00:00 2001 From: sigonasr2 Date: Sat, 1 Jul 2023 20:47:18 -0700 Subject: [PATCH] Consolidated jump and shoot animations for monsters into MonsterData. --- Crawler/BulletTypes.h | 6 ---- Crawler/Monster.cpp | 61 ++++------------------------------------- Crawler/Monster.h | 10 +++++-- Crawler/MonsterData.cpp | 47 +++++++++++++++++++++++++++---- Crawler/Player.cpp | 2 +- Crawler/Version.h | 2 +- Crawler/monSlimeA.cpp | 7 +++++ 7 files changed, 64 insertions(+), 71 deletions(-) create mode 100644 Crawler/monSlimeA.cpp diff --git a/Crawler/BulletTypes.h b/Crawler/BulletTypes.h index 542efa8c..c41c53eb 100644 --- a/Crawler/BulletTypes.h +++ b/Crawler/BulletTypes.h @@ -1,12 +1,6 @@ #pragma once #include "Bullet.h" -struct GenericBullet:public Bullet{ - GenericBullet(vf2d pos,vf2d vel,float radius,int damage,Pixel col=WHITE); - GenericBullet(vf2d pos,vf2d vel,float radius,int damage,AnimationState animation,bool hitsMultiple=false,float lifetime=INFINITE,bool rotatesWithAngle=false,Pixel col=WHITE); - void Update(float fElapsedTime)override; -}; - struct EnergyBolt:public Bullet{ float lastParticleSpawn=0; EnergyBolt(vf2d pos,vf2d vel,float radius,int damage,Pixel col=WHITE); diff --git a/Crawler/Monster.cpp b/Crawler/Monster.cpp index d5662717..39b833fa 100644 --- a/Crawler/Monster.cpp +++ b/Crawler/Monster.cpp @@ -12,33 +12,6 @@ INCLUDE_DAMAGENUMBER_LIST INCLUDE_game INCLUDE_BULLET_LIST -MonsterData::MonsterData(){} -MonsterData::MonsterData(MonsterName type,int hp,int atk,std::vectoranimations,float moveSpd,float size,MonsterStrategy strategy,int collisionDmg): - type(type),hp(hp),atk(atk),moveSpd(moveSpd),size(size),strategy(strategy),animations(animations),collisionDmg(collisionDmg){ -} -int MonsterData::GetHealth(){ - return hp; -} -int MonsterData::GetAttack(){ - return atk; -} -float MonsterData::GetMoveSpdMult(){ - return moveSpd; -} -float MonsterData::GetSizeMult(){ - return size; -} -int MonsterData::GetCollisionDmg(){ - return collisionDmg; -} -MonsterName MonsterData::GetType(){ - return type; -} -MonsterStrategy MonsterData::GetAIStrategy(){ - return strategy; -} - -Monster::Monster(){} Monster::Monster(vf2d pos,MonsterData data): pos(pos),hp(data.GetHealth()),maxhp(data.GetHealth()),atk(data.GetAttack()),moveSpd(data.GetMoveSpdMult()),size(data.GetSizeMult()),strategy(data.GetAIStrategy()),type(data.GetType()){ bool firstAnimation=true; @@ -81,36 +54,10 @@ void Monster::UpdateAnimation(AnimationState state){ animation.ChangeState(internal_animState,state); } void Monster::PerformJumpAnimation(){ - switch(type){ - case SLIME_GREEN:{ - animation.ChangeState(internal_animState,AnimationState::GREEN_SLIME_JUMP); - }break; - case SLIME_BLUE:{ - animation.ChangeState(internal_animState,AnimationState::BLUE_SLIME_JUMP); - }break; - case SLIME_RED:{ - animation.ChangeState(internal_animState,AnimationState::RED_SLIME_JUMP); - }break; - case SLIME_YELLOW:{ - animation.ChangeState(internal_animState,AnimationState::YELLOW_SLIME_JUMP); - }break; - } + animation.ChangeState(internal_animState,MONSTER_DATA[type].GetJumpAnimation()); } void Monster::PerformShootAnimation(){ - switch(type){ - case SLIME_GREEN:{ - animation.ChangeState(internal_animState,AnimationState::GREEN_SLIME_SPIT); - }break; - case SLIME_BLUE:{ - animation.ChangeState(internal_animState,AnimationState::BLUE_SLIME_SPIT); - }break; - case SLIME_RED:{ - animation.ChangeState(internal_animState,AnimationState::RED_SLIME_SPIT); - }break; - case SLIME_YELLOW:{ - animation.ChangeState(internal_animState,AnimationState::YELLOW_SLIME_SPIT); - }break; - } + animation.ChangeState(internal_animState,MONSTER_DATA[type].GetShootAnimation()); } bool Monster::SetX(float x){ vf2d newPos={x,pos.y}; @@ -207,7 +154,9 @@ bool Monster::Update(float fElapsedTime){ queueShotTimer-=fElapsedTime; if(queueShotTimer<0){ queueShotTimer=0; - BULLET_LIST.push_back(std::make_unique(Bullet(pos+vf2d{0,-4},geom2d::line(pos+vf2d{0,-4},game->GetPlayer().GetPos()).vector().norm()*24*3.f,2,GetAttack(),{75/2,162/2,225/2}))); + { + BULLET_LIST.push_back(std::make_unique(Bullet(pos + vf2d{ 0,-4 }, geom2d::line(pos + vf2d{ 0,-4 }, game->GetPlayer().GetPos()).vector().norm() * 24 * 3.f, 2, GetAttack(), { 75 / 2,162 / 2,225 / 2 }))); + } } } geom2d::line line(pos,game->GetPlayer().GetPos()); diff --git a/Crawler/Monster.h b/Crawler/Monster.h index d3f2094b..1d32b8cf 100644 --- a/Crawler/Monster.h +++ b/Crawler/Monster.h @@ -32,10 +32,13 @@ struct MonsterData{ MonsterStrategy strategy; MonsterName type; int collisionDmg; + AnimationState jumpAnimation=AnimationState::WARRIOR_IDLE_S; + AnimationState shootAnimation=AnimationState::WARRIOR_IDLE_S; public: MonsterData(); //When specifying animations, the first one will become the default animation. The last becomes the death animation. - MonsterData(MonsterName type,int hp,int atk,std::vectoranimations,float moveSpd=1.0f,float size=1.0f,MonsterStrategy strategy=RUN_TOWARDS,int collisionDmg=0); + MonsterData(MonsterName type,int hp,int atk,std::vectoranimations,float moveSpd=1.0f,float size=1.0f,MonsterStrategy strategy=RUN_TOWARDS,int collisionDmg=0 + ,AnimationState jumpAnimation=AnimationState::WARRIOR_IDLE_S,AnimationState shootAnimation=AnimationState::WARRIOR_IDLE_S); int GetHealth(); int GetAttack(); float GetMoveSpdMult(); @@ -43,6 +46,8 @@ struct MonsterData{ MonsterName GetType(); MonsterStrategy GetAIStrategy(); int GetCollisionDmg(); + AnimationState GetJumpAnimation(); + AnimationState GetShootAnimation(); std::vectorGetAnimations(){ return animations; } @@ -73,8 +78,9 @@ struct Monster{ AnimationState GetDeathAnimationName(); bool hasHitPlayer=false; bool canMove=true; //Set to false when stuck due to collisions. +protected: public: - Monster(); + Monster()=delete; Monster(vf2d pos,MonsterData data); vf2d&GetPos(); int GetHealth(); diff --git a/Crawler/MonsterData.cpp b/Crawler/MonsterData.cpp index ac14bcde..68f638f7 100644 --- a/Crawler/MonsterData.cpp +++ b/Crawler/MonsterData.cpp @@ -2,9 +2,46 @@ #include "Monster.h" #include "Animation.h" + std::mapMONSTER_DATA={ - {SLIME_GREEN,MonsterData(MonsterName::SLIME_GREEN,10,5,{{AnimationState::GREEN_SLIME_IDLE,AnimationState::GREEN_SLIME_JUMP,AnimationState::GREEN_SLIME_ROLL,AnimationState::GREEN_SLIME_DIE,AnimationState::GREEN_SLIME_SPIT}},1.1f,0.8f,MonsterStrategy::RUN_TOWARDS,5)}, - {SLIME_BLUE,MonsterData(MonsterName::SLIME_BLUE,30,10,{{AnimationState::BLUE_SLIME_IDLE,AnimationState::BLUE_SLIME_JUMP,AnimationState::BLUE_SLIME_ROLL,AnimationState::BLUE_SLIME_DIE,AnimationState::BLUE_SLIME_SPIT}},0.8f,1.0f,MonsterStrategy::SHOOT_AFAR)}, - {SLIME_RED,MonsterData(MonsterName::SLIME_RED,25,10,{{AnimationState::RED_SLIME_IDLE,AnimationState::RED_SLIME_JUMP,AnimationState::RED_SLIME_ROLL,AnimationState::RED_SLIME_DIE,AnimationState::RED_SLIME_SPIT}},0.95f,1.2f,MonsterStrategy::RUN_TOWARDS,10)}, - {SLIME_YELLOW,MonsterData(MonsterName::SLIME_YELLOW,175,10,{{AnimationState::YELLOW_SLIME_IDLE,AnimationState::YELLOW_SLIME_JUMP,AnimationState::YELLOW_SLIME_ROLL,AnimationState::YELLOW_SLIME_DIE,AnimationState::YELLOW_SLIME_SPIT}},0.4f,1.6f,MonsterStrategy::RUN_TOWARDS,15)}, -}; \ No newline at end of file + {SLIME_GREEN,MonsterData(MonsterName::SLIME_GREEN,10,5,{{AnimationState::GREEN_SLIME_IDLE,AnimationState::GREEN_SLIME_JUMP,AnimationState::GREEN_SLIME_ROLL,AnimationState::GREEN_SLIME_DIE,AnimationState::GREEN_SLIME_SPIT}},1.1f,0.8f,MonsterStrategy::RUN_TOWARDS,5,AnimationState::GREEN_SLIME_JUMP,AnimationState::GREEN_SLIME_SPIT)}, + {SLIME_BLUE,MonsterData(MonsterName::SLIME_BLUE,30,10,{{AnimationState::BLUE_SLIME_IDLE,AnimationState::BLUE_SLIME_JUMP,AnimationState::BLUE_SLIME_ROLL,AnimationState::BLUE_SLIME_DIE,AnimationState::BLUE_SLIME_SPIT}},0.8f,1.0f,MonsterStrategy::SHOOT_AFAR,0,AnimationState::BLUE_SLIME_JUMP,AnimationState::BLUE_SLIME_SPIT)}, + {SLIME_RED,MonsterData(MonsterName::SLIME_RED,25,10,{{AnimationState::RED_SLIME_IDLE,AnimationState::RED_SLIME_JUMP,AnimationState::RED_SLIME_ROLL,AnimationState::RED_SLIME_DIE,AnimationState::RED_SLIME_SPIT}},0.95f,1.2f,MonsterStrategy::RUN_TOWARDS,10,AnimationState::RED_SLIME_JUMP,AnimationState::RED_SLIME_SPIT)}, + {SLIME_YELLOW,MonsterData(MonsterName::SLIME_YELLOW,175,10,{{AnimationState::YELLOW_SLIME_IDLE,AnimationState::YELLOW_SLIME_JUMP,AnimationState::YELLOW_SLIME_ROLL,AnimationState::YELLOW_SLIME_DIE,AnimationState::YELLOW_SLIME_SPIT}},0.4f,1.6f,MonsterStrategy::RUN_TOWARDS,15,AnimationState::YELLOW_SLIME_JUMP,AnimationState::YELLOW_SLIME_SPIT)}, +}; + + +MonsterData::MonsterData(){} +MonsterData::MonsterData(MonsterName type,int hp,int atk,std::vectoranimations,float moveSpd,float size,MonsterStrategy strategy,int collisionDmg + ,AnimationState jumpAnimation,AnimationState shootAnimation): + type(type),hp(hp),atk(atk),moveSpd(moveSpd),size(size),strategy(strategy),animations(animations),collisionDmg(collisionDmg) + ,jumpAnimation(jumpAnimation),shootAnimation(shootAnimation){ +} +int MonsterData::GetHealth(){ + return hp; +} +int MonsterData::GetAttack(){ + return atk; +} +float MonsterData::GetMoveSpdMult(){ + return moveSpd; +} +float MonsterData::GetSizeMult(){ + return size; +} +int MonsterData::GetCollisionDmg(){ + return collisionDmg; +} +MonsterName MonsterData::GetType(){ + return type; +} +MonsterStrategy MonsterData::GetAIStrategy(){ + return strategy; +} + +AnimationState MonsterData::GetJumpAnimation(){ + return jumpAnimation; +} +AnimationState MonsterData::GetShootAnimation(){ + return shootAnimation; +} \ No newline at end of file diff --git a/Crawler/Player.cpp b/Crawler/Player.cpp index 7852852c..520691ff 100644 --- a/Crawler/Player.cpp +++ b/Crawler/Player.cpp @@ -414,7 +414,7 @@ void Player::Update(float fElapsedTime){ UpdateAnimation(AnimationState::WARRIOR_SWINGSONICSWORD_S); }break; } - PLAYER_BULLET_LIST.push_back(std::make_unique(Bullet(pos,bulletVel,30,GetAttack()*8,AnimationState::SONICSLASH,true,2.25,true))); + PLAYER_BULLET_LIST.push_back(std::make_unique(pos,bulletVel,30,GetAttack()*8,AnimationState::SONICSLASH,true,2.25,true)); game->SetupWorldShake(0.5); }break; case THIEF:{ diff --git a/Crawler/Version.h b/Crawler/Version.h index 98e0410a..2a169220 100644 --- a/Crawler/Version.h +++ b/Crawler/Version.h @@ -2,7 +2,7 @@ #define VERSION_MAJOR 0 #define VERSION_MINOR 2 #define VERSION_PATCH 0 -#define VERSION_BUILD 347 +#define VERSION_BUILD 352 #define stringify(a) stringify_(a) #define stringify_(a) #a diff --git a/Crawler/monSlimeA.cpp b/Crawler/monSlimeA.cpp new file mode 100644 index 00000000..693df678 --- /dev/null +++ b/Crawler/monSlimeA.cpp @@ -0,0 +1,7 @@ +#include "MonsterType.h" + +monSlimeA::monSlimeA(vf2d pos,MonsterData data) + :Monster(pos,data){ + jumpAnimation=AnimationState::GREEN_SLIME_JUMP; + shootAnimation=AnimationState::GREEN_SLIME_SPIT; +}