From: Lukas Krickl Date: Tue, 14 Oct 2025 04:18:20 +0000 (+0200) Subject: player: Added basic walking animation X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=9f5da34edd4c8c3e7f55ec71045c2c501b0ad320;p=gbrg%2F.git player: Added basic walking animation --- diff --git a/src/player.s b/src/player.s index ff211da..4b512b4 100644 --- a/src/player.s +++ b/src/player.s @@ -1,5 +1,6 @@ #define PLAYER_SPEED 0xE0 #define PISTOL_TILE 0x86 +#define PLAYER_WALKING_TILE 0x8E ; sets up the player actor player_init: @@ -254,13 +255,41 @@ player_try_move: player_draw: ld a, 2 call oamalloc - + + ; was any direction pressed this frame? + ld a, [curr_inputs] + and a, BTNUP | BTNDOWN | BTNLEFT | BTNRIGHT + jp nz, @walking + + ; idle sprite ld de, player ld b, PLAYER_SPRITE_IDLE1 ld c, 0 ld a, 3 call actor_draw - + + jp @weapon +@walking: + + ld de, player + ld b, PLAYER_WALKING_TILE + + ld a, [animation_frame] + cp a, 1 + jr z, @flip REL + + ld c, 0 + ld a, 3 + jr @no_flip REL + +@flip: + ld c, OAM_FXFLIP + ld a, 4 +@no_flip: + + call actor_draw + +@weapon: ; TODO: draw based on player weapon type ld de, player ld b, PISTOL_TILE diff --git a/src/update.s b/src/update.s index 1c08a84..1636850 100644 --- a/src/update.s +++ b/src/update.s @@ -22,7 +22,25 @@ update_game: ld h, a call_hl + call update_anim_timer + ret + + ; updates the global animation timer + ; and the animation frame +update_anim_timer: + ld a, [animation_timer] + inc a + and a, 0x1F ; max timer + ld [animation_timer], a + ; bail if no overflow + ret nz + +@tick_frame: + ld a, [animation_frame] + xor a, 1 + ld [animation_frame], a + ret new_game: ld de, l_main_menu diff --git a/src/wram.s b/src/wram.s index 55f6414..a3aa92b 100644 --- a/src/wram.s +++ b/src/wram.s @@ -54,6 +54,12 @@ empty_oam: .adv oamsize scroll_y: .adv 1 scroll_x: .adv 1 + ; global animation timer + ; increments from 0-30 +animation_timer: .adv 1 + ; global animation frame + ; either 0 or 1 +animation_frame: .adv 1 ; 16 bit srand seed ; seed must never be 0