Add Player Ladder, Crouch, and Swim transitions
parent
9c2e21f4d2
commit
c0aa37886f
|
@ -4,13 +4,16 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "raymath.h"
|
#include "raymath.h"
|
||||||
|
|
||||||
#define N_PLAYER_SPRITES 4
|
#define N_PLAYER_SPRITES 7
|
||||||
enum PlayerSpriteEnum
|
enum PlayerSpriteEnum
|
||||||
{
|
{
|
||||||
SPR_PLAYER_STAND = 0,
|
SPR_PLAYER_STAND = 0,
|
||||||
SPR_PLAYER_RUN,
|
SPR_PLAYER_RUN,
|
||||||
SPR_PLAYER_JUMP,
|
SPR_PLAYER_JUMP,
|
||||||
SPR_PLAYER_FALL,
|
SPR_PLAYER_FALL,
|
||||||
|
SPR_PLAYER_LADDER,
|
||||||
|
SPR_PLAYER_CROUCH,
|
||||||
|
SPR_PLAYER_SWIM,
|
||||||
};
|
};
|
||||||
|
|
||||||
static SpriteRenderInfo_t player_sprite_map[N_PLAYER_SPRITES] = {0};
|
static SpriteRenderInfo_t player_sprite_map[N_PLAYER_SPRITES] = {0};
|
||||||
|
@ -20,10 +23,17 @@ static unsigned int player_sprite_transition_func(Entity_t* ent)
|
||||||
CTransform_t* p_ctrans = get_component(ent, CTRANSFORM_COMP_T);
|
CTransform_t* p_ctrans = get_component(ent, CTRANSFORM_COMP_T);
|
||||||
CMovementState_t* p_move = get_component(ent, CMOVEMENTSTATE_T);
|
CMovementState_t* p_move = get_component(ent, CMOVEMENTSTATE_T);
|
||||||
CSprite_t* p_spr = get_component(ent, CSPRITE_T);
|
CSprite_t* p_spr = get_component(ent, CSPRITE_T);
|
||||||
|
CPlayerState_t* p_plr = get_component(ent, CPLAYERSTATE_T);
|
||||||
if (p_ctrans->velocity.x > 0) p_spr->flip_x = true;
|
if (p_ctrans->velocity.x > 0) p_spr->flip_x = true;
|
||||||
else if (p_ctrans->velocity.x < 0) p_spr->flip_x = false;
|
else if (p_ctrans->velocity.x < 0) p_spr->flip_x = false;
|
||||||
|
|
||||||
if (p_move->ground_state & 1)
|
if (p_move->ground_state & 1)
|
||||||
|
{
|
||||||
|
if (p_plr->is_crouch)
|
||||||
|
{
|
||||||
|
return SPR_PLAYER_CROUCH;
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
if (Vector2LengthSqr(p_ctrans->velocity) > 1000.0f)
|
if (Vector2LengthSqr(p_ctrans->velocity) > 1000.0f)
|
||||||
{
|
{
|
||||||
|
@ -31,6 +41,15 @@ static unsigned int player_sprite_transition_func(Entity_t* ent)
|
||||||
}
|
}
|
||||||
return SPR_PLAYER_STAND;
|
return SPR_PLAYER_STAND;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else if (p_plr->ladder_state)
|
||||||
|
{
|
||||||
|
return SPR_PLAYER_LADDER;
|
||||||
|
}
|
||||||
|
else if (p_move->water_state & 1)
|
||||||
|
{
|
||||||
|
return SPR_PLAYER_SWIM;
|
||||||
|
}
|
||||||
return (p_ctrans->velocity.y < 0) ? SPR_PLAYER_JUMP : SPR_PLAYER_FALL;
|
return (p_ctrans->velocity.y < 0) ? SPR_PLAYER_JUMP : SPR_PLAYER_FALL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue