Reworking player input handling for turn-based movement
authorLukas Krickl <lukas@krickl.dev>
Sun, 17 Nov 2024 20:05:44 +0000 (21:05 +0100)
committerLukas Krickl <lukas@krickl.dev>
Sun, 17 Nov 2024 20:05:44 +0000 (21:05 +0100)
src/player.s

index 9f11ecaf36a4060f209334bb827848459dc8dc6e..4abe639ab41ef19f2973999b6c55cdd2bfae1df6 100644 (file)
@@ -73,14 +73,13 @@ player_init:
   ;   hl: pointer to player memory
 player_update:
   ; update
+  ld a, [who]
+  cp a, WHO_PLAYER
+  jp nz, @skip_input 
 
   ; set collision mask
   ld a, RF_WALL 
   ld [ct_mask], a
-
-  ; d: player_y
-  ; e: player_x
-  ; b: obj flags mask
   
 
   ; input handling
@@ -207,13 +206,25 @@ player_update:
   ; 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] 
+  ld e, a ; e = player_x 
+  dec hl ; hl = player_y
 
   ; check if i-frame 
   ; if iframe is divisible by 2
   ; flash all sprites off
   ; otherwise continue with regular code
   ; hl = player_x
-  dec hl ; hl = player_y = player start 
   ld bc, player_timer_i
   add hl, bc ; hl = timer now
   ld a, [hl]