Added Warrior swing sword animation
This commit is contained in:
parent
5be3d2679c
commit
4b98518fcf
@ -8,4 +8,5 @@ enum AnimationState{
|
||||
RED_SLIME_IDLE,RED_SLIME_ROLL,RED_SLIME_JUMP,RED_SLIME_SPIT,RED_SLIME_DIE,
|
||||
YELLOW_SLIME_IDLE,YELLOW_SLIME_ROLL,YELLOW_SLIME_JUMP,YELLOW_SLIME_SPIT,YELLOW_SLIME_DIE,
|
||||
GROUND_SLAM_ATTACK_BACK,GROUND_SLAM_ATTACK_FRONT,
|
||||
SWINGSWORD_S,SWINGSWORD_E,SWINGSWORD_N,SWINGSWORD_W,
|
||||
};
|
@ -47,6 +47,10 @@ bool Crawler::OnUserCreate(){
|
||||
player.AddAnimation(AnimationState::IDLE_E);
|
||||
player.AddAnimation(AnimationState::IDLE_S);
|
||||
player.AddAnimation(AnimationState::IDLE_W);
|
||||
player.AddAnimation(AnimationState::SWINGSWORD_E);
|
||||
player.AddAnimation(AnimationState::SWINGSWORD_S);
|
||||
player.AddAnimation(AnimationState::SWINGSWORD_N);
|
||||
player.AddAnimation(AnimationState::SWINGSWORD_W);
|
||||
view=TileTransformedView{GetScreenSize(),{1,1}};
|
||||
|
||||
player.SetPos({4*24,4*24});
|
||||
@ -148,6 +152,23 @@ void Crawler::InitializeAnimations(){
|
||||
Animate2D::FrameSequence pl_idle_n;
|
||||
pl_idle_n.AddFrame({&GFX_Pl_Sheet,{vi2d{0,1}*24,{24,24}}});
|
||||
ANIMATION_DATA[AnimationState::IDLE_N]=pl_idle_n;
|
||||
Animate2D::FrameSequence pl_swing_s(0.05),pl_swing_n(0.05),pl_swing_e(0.05),pl_swing_w(0.05);
|
||||
for (int i=0;i<4;i++){
|
||||
pl_swing_s.AddFrame({&GFX_Pl_Sheet,{vi2d{4+i,0}*24,{24,24}}});
|
||||
}
|
||||
for (int i=0;i<4;i++){
|
||||
pl_swing_n.AddFrame({&GFX_Pl_Sheet,{vi2d{4+i,1}*24,{24,24}}});
|
||||
}
|
||||
for (int i=0;i<4;i++){
|
||||
pl_swing_w.AddFrame({&GFX_Pl_Sheet,{vi2d{4+i,2}*24,{24,24}}});
|
||||
}
|
||||
for (int i=0;i<4;i++){
|
||||
pl_swing_e.AddFrame({&GFX_Pl_Sheet,{vi2d{4+i,3}*24,{24,24}}});
|
||||
}
|
||||
ANIMATION_DATA[AnimationState::SWINGSWORD_N]=pl_swing_n;
|
||||
ANIMATION_DATA[AnimationState::SWINGSWORD_E]=pl_swing_e;
|
||||
ANIMATION_DATA[AnimationState::SWINGSWORD_S]=pl_swing_s;
|
||||
ANIMATION_DATA[AnimationState::SWINGSWORD_W]=pl_swing_w;
|
||||
//Load slime animations.
|
||||
for(int slime=0;slime<4;slime++){
|
||||
for(int state=0;state<5;state++){
|
||||
@ -211,7 +232,9 @@ void Crawler::HandleUserInput(float fElapsedTime){
|
||||
player.SetX(WORLD_SIZE.x*24-12);
|
||||
}
|
||||
player.SetFacingDirection(RIGHT);
|
||||
player.UpdateAnimation(AnimationState::WALK_E);
|
||||
if(player.GetState()==State::NORMAL){
|
||||
player.UpdateAnimation(AnimationState::WALK_E);
|
||||
}
|
||||
setIdleAnimation=false;
|
||||
}
|
||||
if(LeftHeld()){
|
||||
@ -222,7 +245,9 @@ void Crawler::HandleUserInput(float fElapsedTime){
|
||||
}
|
||||
if(setIdleAnimation){
|
||||
player.SetFacingDirection(LEFT);
|
||||
player.UpdateAnimation(AnimationState::WALK_W);
|
||||
if(player.GetState()==State::NORMAL){
|
||||
player.UpdateAnimation(AnimationState::WALK_W);
|
||||
}
|
||||
}
|
||||
setIdleAnimation=false;
|
||||
}
|
||||
@ -234,7 +259,9 @@ void Crawler::HandleUserInput(float fElapsedTime){
|
||||
}
|
||||
if(setIdleAnimation){
|
||||
player.SetFacingDirection(UP);
|
||||
player.UpdateAnimation(AnimationState::WALK_N);
|
||||
if(player.GetState()==State::NORMAL){
|
||||
player.UpdateAnimation(AnimationState::WALK_N);
|
||||
}
|
||||
}
|
||||
setIdleAnimation=false;
|
||||
}
|
||||
@ -246,57 +273,90 @@ void Crawler::HandleUserInput(float fElapsedTime){
|
||||
}
|
||||
if(setIdleAnimation){
|
||||
player.SetFacingDirection(DOWN);
|
||||
player.UpdateAnimation(AnimationState::WALK_S);
|
||||
if(player.GetState()==State::NORMAL){
|
||||
player.UpdateAnimation(AnimationState::WALK_S);
|
||||
}
|
||||
}
|
||||
setIdleAnimation=false;
|
||||
}
|
||||
}
|
||||
if(UpReleased()){
|
||||
player.SetLastReleasedMovementKey(UP);
|
||||
if(RightHeld()){
|
||||
player.UpdateAnimation(AnimationState::WALK_E);
|
||||
} else
|
||||
if(DownHeld()){
|
||||
player.UpdateAnimation(AnimationState::WALK_S);
|
||||
} else
|
||||
if(LeftHeld()){
|
||||
player.UpdateAnimation(AnimationState::WALK_W);
|
||||
if(player.GetState()==State::NORMAL){
|
||||
if(RightHeld()){
|
||||
player.UpdateAnimation(AnimationState::WALK_E);
|
||||
} else
|
||||
if(DownHeld()){
|
||||
player.UpdateAnimation(AnimationState::WALK_S);
|
||||
} else
|
||||
if(LeftHeld()){
|
||||
player.UpdateAnimation(AnimationState::WALK_W);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(RightReleased()){
|
||||
player.SetLastReleasedMovementKey(RIGHT);
|
||||
if(UpHeld()){
|
||||
player.UpdateAnimation(AnimationState::WALK_N);
|
||||
} else
|
||||
if(DownHeld()){
|
||||
player.UpdateAnimation(AnimationState::WALK_S);
|
||||
} else
|
||||
if(LeftHeld()){
|
||||
player.UpdateAnimation(AnimationState::WALK_W);
|
||||
if(player.GetState()==State::NORMAL){
|
||||
if(UpHeld()){
|
||||
player.UpdateAnimation(AnimationState::WALK_N);
|
||||
} else
|
||||
if(DownHeld()){
|
||||
player.UpdateAnimation(AnimationState::WALK_S);
|
||||
} else
|
||||
if(LeftHeld()){
|
||||
player.UpdateAnimation(AnimationState::WALK_W);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(LeftReleased()){
|
||||
player.SetLastReleasedMovementKey(LEFT);
|
||||
if(RightHeld()){
|
||||
player.UpdateAnimation(AnimationState::WALK_E);
|
||||
} else
|
||||
if(DownHeld()){
|
||||
player.UpdateAnimation(AnimationState::WALK_S);
|
||||
} else
|
||||
if(UpHeld()){
|
||||
player.UpdateAnimation(AnimationState::WALK_N);
|
||||
if(player.GetState()==State::NORMAL){
|
||||
if(RightHeld()){
|
||||
player.UpdateAnimation(AnimationState::WALK_E);
|
||||
} else
|
||||
if(DownHeld()){
|
||||
player.UpdateAnimation(AnimationState::WALK_S);
|
||||
} else
|
||||
if(UpHeld()){
|
||||
player.UpdateAnimation(AnimationState::WALK_N);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(DownReleased()){
|
||||
player.SetLastReleasedMovementKey(DOWN);
|
||||
if(RightHeld()){
|
||||
player.UpdateAnimation(AnimationState::WALK_E);
|
||||
} else
|
||||
if(UpHeld()){
|
||||
player.UpdateAnimation(AnimationState::WALK_N);
|
||||
} else
|
||||
if(LeftHeld()){
|
||||
player.UpdateAnimation(AnimationState::WALK_W);
|
||||
if(player.GetState()==State::NORMAL){
|
||||
if(RightHeld()){
|
||||
player.UpdateAnimation(AnimationState::WALK_E);
|
||||
} else
|
||||
if(UpHeld()){
|
||||
player.UpdateAnimation(AnimationState::WALK_N);
|
||||
} else
|
||||
if(LeftHeld()){
|
||||
player.UpdateAnimation(AnimationState::WALK_W);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(player.GetState()==State::SWING_SWORD){
|
||||
setIdleAnimation=false;
|
||||
switch(player.GetFacingDirection()){
|
||||
case UP:{
|
||||
player.UpdateAnimation(AnimationState::SWINGSWORD_N);
|
||||
}break;
|
||||
case DOWN:{
|
||||
player.UpdateAnimation(AnimationState::SWINGSWORD_S);
|
||||
}break;
|
||||
case LEFT:{
|
||||
player.UpdateAnimation(AnimationState::SWINGSWORD_W);
|
||||
}break;
|
||||
case RIGHT:{
|
||||
player.UpdateAnimation(AnimationState::SWINGSWORD_E);
|
||||
}break;
|
||||
}
|
||||
player.SetSwordSwingTimer(player.GetSwordSwingTimer()-fElapsedTime);
|
||||
if(player.GetSwordSwingTimer()<=0){
|
||||
player.SetSwordSwingTimer(0);
|
||||
player.SetState(State::NORMAL);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -176,10 +176,38 @@ void Player::Update(float fElapsedTime){
|
||||
}
|
||||
if(closest!=nullptr&&closest->Hurt(atk)){
|
||||
attack_cooldown_timer=ATTACK_COOLDOWN;
|
||||
swordSwingTimer=0.2;
|
||||
SetState(State::SWING_SWORD);
|
||||
switch(facingDirection){
|
||||
case DOWN:{
|
||||
UpdateAnimation(AnimationState::SWINGSWORD_S);
|
||||
}break;
|
||||
case RIGHT:{
|
||||
UpdateAnimation(AnimationState::SWINGSWORD_E);
|
||||
}break;
|
||||
case LEFT:{
|
||||
UpdateAnimation(AnimationState::SWINGSWORD_W);
|
||||
}break;
|
||||
case UP:{
|
||||
UpdateAnimation(AnimationState::SWINGSWORD_N);
|
||||
}break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
float Player::GetSwordSwingTimer(){
|
||||
return swordSwingTimer;
|
||||
}
|
||||
|
||||
void Player::SetSwordSwingTimer(float val){
|
||||
swordSwingTimer=val;
|
||||
}
|
||||
|
||||
void Player::SetState(State newState){
|
||||
state=newState;
|
||||
}
|
||||
|
||||
vf2d Player::GetVelocity(){
|
||||
return vel;
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include "State.h"
|
||||
|
||||
struct Player{
|
||||
friend class Crawler;
|
||||
private:
|
||||
int hp=100,maxhp=hp;
|
||||
int atk=10;
|
||||
@ -22,20 +23,29 @@ private:
|
||||
float spin_angle=0;
|
||||
float lastAnimationFlip=0;
|
||||
float groundSlamCooldown=0;
|
||||
float swordSwingTimer=0;
|
||||
State state=State::NORMAL;
|
||||
Animate2D::Animation<AnimationState>animation;
|
||||
Animate2D::AnimationState internal_animState;
|
||||
Key lastReleasedMovementKey;
|
||||
Key facingDirection;
|
||||
void AddAnimation(AnimationState state);
|
||||
void Update(float fElapsedTime);
|
||||
void SetSwordSwingTimer(float val);
|
||||
void SetState(State newState);
|
||||
void SetFacingDirection(Key direction);
|
||||
void SetLastReleasedMovementKey(Key k);
|
||||
void Spin(float duration,float spinSpd);
|
||||
void SetX(float x);
|
||||
void SetY(float y);
|
||||
void SetZ(float z);
|
||||
void SetPos(vf2d pos);
|
||||
protected:
|
||||
public:
|
||||
Player();
|
||||
Player(vf2d pos);
|
||||
const static float GROUND_SLAM_SPIN_TIME;
|
||||
const static float GROUND_SLAM_COOLDOWN;
|
||||
void SetX(float x);
|
||||
void SetY(float y);
|
||||
void SetZ(float z);
|
||||
void SetPos(vf2d pos);
|
||||
vf2d&GetPos();
|
||||
float GetX();
|
||||
float GetY();
|
||||
@ -48,19 +58,14 @@ public:
|
||||
float GetAttackRangeMult();
|
||||
float GetSpinAngle();
|
||||
State GetState();
|
||||
void SetFacingDirection(Key direction);
|
||||
Key GetFacingDirection();
|
||||
vf2d GetVelocity();
|
||||
|
||||
void Hurt(int damage);
|
||||
|
||||
void Spin(float duration,float spinSpd);
|
||||
void Update(float fElapsedTime);
|
||||
void AddAnimation(AnimationState state);
|
||||
void UpdateAnimation(AnimationState animState);
|
||||
Animate2D::Frame GetFrame();
|
||||
void SetLastReleasedMovementKey(Key k);
|
||||
Key GetLastReleasedMovementKey();
|
||||
float GetSwordSwingTimer();
|
||||
|
||||
float GetGroundSlamCooldown();
|
||||
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
enum State{
|
||||
NORMAL,
|
||||
SWING_SWORD,
|
||||
SPIN,
|
||||
MOVE_TOWARDS,
|
||||
MOVE_AWAY,
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 13 KiB |
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user