player: Added basic walking animation
authorLukas Krickl <lukas@krickl.dev>
Tue, 14 Oct 2025 04:18:20 +0000 (06:18 +0200)
committerLukas Krickl <lukas@krickl.dev>
Tue, 14 Oct 2025 04:18:20 +0000 (06:18 +0200)
src/player.s
src/update.s
src/wram.s

index ff211daa064cb281f92fa2f2413db58f44c5c09f..4b512b4b256145a547c84aaafa080cb86181440d 100644 (file)
@@ -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 
index 1c08a846581f58ca3ad64e531e7e26cb950522bc..16368502188a8ec7da3683a5169671b758598721 100644 (file)
@@ -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
index 55f6414aac61d0d775007ad607747f2459178195..a3aa92b72f24aff6e036865b05c216404bd6ae2b 100644 (file)
@@ -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