Added new movement for player.
authorLukas Krickl <lukas@krickl.dev>
Mon, 18 Nov 2024 12:55:32 +0000 (13:55 +0100)
committerLukas Krickl <lukas@krickl.dev>
Mon, 18 Nov 2024 12:55:32 +0000 (13:55 +0100)
- TODO: collision is still not implemented again

src/actor.s
src/player.s
src/wram.s

index 828101d7f9575a13a3372c6b75f7adb25e06c4c6..b617ffc1ade2119c7f6a2e9e659347909636746a 100644 (file)
@@ -78,3 +78,53 @@ actors_update:
   jr nz, @loop REL
 
   ret
+
+  ; simple move animation
+  ; moves 1 pixel per frame
+  ; inputs:
+  ;   hl: ptr to y/x positon
+  ;   anim_move_x/y: y/x offset 
+  ;   anim_step_x/y: y/x step per frame 
+  ; returns:
+  ;   a == 0 if both y and x are 0
+  ; hl is left unchanged
+anim_move:
+  ; y pos
+  ld a, [anim_move_y]
+  ld b, a ; exit code == b
+
+  cp a, 0
+  jr z, @no_y REL ; if move is 0 do nothing 
+  
+  dec a
+  ld [anim_move_y], a ; a--
+
+  ld a, [hl]
+  ld b, a
+  ld a, [anim_step_y]
+  add a, b ; a = y + step
+  ld [hl], a
+@no_y:
+  
+  inc hl
+
+  ; x pos
+  ld a, [anim_move_x]
+  cp a, 0
+  jr z, @no_x REL ; if move is 0 do nothing 
+  
+  dec a
+  ld [anim_move_x], a ; a--
+
+  ld a, [hl]
+  ld b, a
+  ld a, [anim_step_x]
+  add a, b ; a = x + step
+  ld [hl], a
+
+@no_x:
+  dec hl
+  ; exit code 
+  ld a, b 
+
+  ret
index 4abe639ab41ef19f2973999b6c55cdd2bfae1df6..8dedd63c0b8bc31dd632ad87a35290236b8fde27 100644 (file)
@@ -76,6 +76,13 @@ player_update:
   ld a, [who]
   cp a, WHO_PLAYER
   jp nz, @skip_input 
+  ; play move animation 
+  ; and skip inputs if it is still 
+  ; ongoing
+  call anim_move 
+  cp a, 0
+  jp nz, @skip_input
 
   ; set collision mask
   ld a, RF_WALL 
@@ -85,85 +92,47 @@ player_update:
   ; input handling
   input_held BTNDOWN
   jr z, @notdown REL
-  ; hl = player_y 
-  ld a, [hl]
-  inc a
-  ld [hl], a
-
-
-  player_collision_check collision_player_bot 
-  jr z, @no_collision_up REL
-    ld a, [hl]
-    dec a
-    ld [hl], a
-@no_collision_down:
-
+  
+  ; set animation params 
+    ld a, ANIM_MOVE_TILE_SIZE
+    ld [anim_move_y], a
+    ld a, ANIM_STEP_DOWN
+    ld [anim_step_y], a
 @notdown:
   
   input_held BTNUP
   jr z, @notup REL
 
-  ; hl = player_y
-  ld a, [hl]
-  dec a
-  ld [hl], a
-  
-  player_collision_check collision_player_top 
-  jr z, @no_collision_up REL
-    ld a, [hl]
-    inc a
-    ld [hl], a
-@no_collision_up:
-
-
+  ; set animation params 
+    ld a, ANIM_MOVE_TILE_SIZE
+    ld [anim_move_y], a
+    ld a, ANIM_STEP_UP
+    ld [anim_step_y], a
 @notup:
   
-  ; store y in d 
-  ; and inc hl 
-  ld a, [hl+]
-  ld d, a 
 
   input_held BTNLEFT
   jr z, @notleft REL
 
-  ; hl = player_x 
-  ld a, [hl]
-  dec a
-  ld [hl], a
-
-
-  dec hl ; hl = player_y
-  player_collision_check collision_player_left
-  inc hl ; hl = player_x
-  jr z, @no_collision_left REL
-    ld a, [hl]
-    inc a
-    ld [hl], a
-@no_collision_left:
-
+  ; set animation params 
+    ld a, ANIM_MOVE_TILE_SIZE
+    ld [anim_move_x], a
+    ld a, ANIM_STEP_LEFT
+    ld [anim_step_x], a
 @notleft:
 
   input_held BTNRIGHT
   jr z, @notright REL
 
-  ; hl = player_x 
-  ld a, [hl]
-  inc a
-  ld [hl], a
-
+  ; set animation params 
+    ld a, ANIM_MOVE_TILE_SIZE
+    ld [anim_move_x], a
+    ld a, ANIM_STEP_RIGHT
+    ld [anim_step_x], a
+@notright:
 
-  dec hl ; hl = player_y
-  player_collision_check collision_player_right 
-  inc hl ; hl = player_x
-  jr z, @no_collision_right REL
-    ld a, [hl]
-    dec a
-    ld [hl], a
-@no_collision_right:
+@action_buttons:
 
-@notright:
   input_just BTNA 
   jr z, @nota REL
 
@@ -202,18 +171,12 @@ player_update:
   ; sotre x in e
   ld a, [hl]
   ld e, a
-  
-  ; hl is ok to use again
-  ; bc is free
-  ; de is still used
-  dec hl ; hl = player_y = player start
 
 @skip_input:
   ; hl should be player_y here 
 
   ; d: player_y
   ; e: player_x
-  ; b: obj flags mask
   ld a, [hl+] ; hl = player_x
   ld d, a ; d = player_y
   ld a, [hl] 
index c2dbc4803f3822b241ee43848cf59033576dc15c..558b9c6a6e9bf6c24ca776f6c37e427eae5accc5 100644 (file)
@@ -152,6 +152,19 @@ game_mode: .adv 1
   ; but may *never* act when they are not currently enabled 
 who: .adv 1
 
+#define ANIM_MOVE_TILE_SIZE 16
+#define ANIM_STEP_DOWN 1
+#define ANIM_STEP_LEFT 0xFF
+#define ANIM_STEP_UP 0xFF
+#define ANIM_STEP_RIGHT 1
+
+; animation params storage 
+anim_move_y: .adv 1
+anim_move_x: .adv 1
+
+anim_step_y: .adv 1
+anim_step_x: .adv 1
+
   ; collision tile tmp values  
 ct_poy: .adv 1
 ct_pox: .adv 1