mirror of
https://github.com/luksamuk/engine-psx.git
synced 2025-04-28 13:28:02 +03:00
Add animation angle snapping
This commit is contained in:
parent
564429104d
commit
32a38deb2e
1 changed files with 28 additions and 1 deletions
29
src/player.c
29
src/player.c
|
@ -1205,10 +1205,37 @@ player_update(Player *player)
|
|||
player->ev_ceil2 = (CollisionEvent){ 0 };
|
||||
}
|
||||
|
||||
static int32_t
|
||||
_snap_angle(int32_t angle)
|
||||
{
|
||||
// Snap angle to nearest quarter.
|
||||
// These angles work somewhat like floor collision modes,
|
||||
// and floor/ceiling angles take precedence as well, but they're
|
||||
// a bit more complex since we also need to leverage diagonal angles.
|
||||
/* if((angle >= 0xf00) || (angle <= 0x100)) */
|
||||
/* return 0x0; */
|
||||
if((angle > 0x100) && (angle < 0x300))
|
||||
return 0x200;
|
||||
if((angle >= 0x300) && (angle <= 0x500))
|
||||
return 0x400;
|
||||
if((angle > 0x500) && (angle < 0x700))
|
||||
return 0x600;
|
||||
if((angle >= 0x700) && (angle <= 0x900))
|
||||
return 0x800;
|
||||
if((angle > 0x900) && (angle < 0xa38))
|
||||
return 0x938;
|
||||
if((angle >= 0xa38) && (angle <= 0xd00))
|
||||
return 0xc00;
|
||||
if((angle > 0xd00) && (angle < 0xf00))
|
||||
return 0xe00;
|
||||
return 0x00;
|
||||
}
|
||||
|
||||
void
|
||||
player_draw(Player *player, VECTOR *pos)
|
||||
{
|
||||
uint8_t is_rolling = (player_get_current_animation_hash(player) == ANIM_ROLLING);
|
||||
int32_t anim_angle = -_snap_angle(player->angle);
|
||||
// if iframes, do not show for every 4 frames
|
||||
if(player->cur_anim && ((player->iframes >> 2) % 2) == 0) {
|
||||
chara_draw_gte(&player->chara,
|
||||
|
@ -1216,7 +1243,7 @@ player_draw(Player *player, VECTOR *pos)
|
|||
(int16_t)(pos->vx >> 12),
|
||||
(int16_t)(pos->vy >> 12) + (is_rolling ? 4 : 0),
|
||||
player->anim_dir < 0,
|
||||
(is_rolling ? 0 : -player->angle));
|
||||
(is_rolling ? 0 : anim_angle));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue