Added ability to flag room loading
authorLukas Krickl <lukas@krickl.dev>
Mon, 23 Dec 2024 13:28:51 +0000 (14:28 +0100)
committerLukas Krickl <lukas@krickl.dev>
Mon, 23 Dec 2024 13:28:51 +0000 (14:28 +0100)
When a player collides with a door a special flag is set that
allows the engine to initiate a room load during the next vblank

src/map.s
src/player.s
src/video.s
src/wram.s

index dfe844d50f0a2ca2fb7a0084570a898188fa3921..acd54c101daa757a0d024f29528551352f9168ae 100644 (file)
--- a/src/map.s
+++ b/src/map.s
@@ -60,12 +60,28 @@ room_load_from:
   ; inputs:
   ;   curr_room_exits: ptr to exits table
   ;   player_x/y: player position
+  ; flags:
+  ;   resets engine flag FLOAD_ROOM to 0
 room_goto_player_pos:
-  ld a, [player_y]
+  ; who must not be player
+  ; this ensures that the player
+  ; turn has finished 
+  ; before we check
+  ld a, [who]
+  cp a, WHO_PLAYER
+  ret z
+
+  ; reset room load flag 
+  ld a, [engine_flags]
+  xor a, EG_FLOAD_ROOM 
+  ld [engine_flags], a
+  ld hl, player ; hl = player_y 
+
+  ld a, [hl+] ; hl = player_x
   ld d, a ; d = player y
   div16 d ; d = player y tile 
 
-  ld a, [player_x]
+  ld a, [hl]
   ld e, a ; d = player x
   div16 e ; d = player x tile 
 
@@ -74,11 +90,9 @@ room_goto_player_pos:
   ; 0/0 == north
   xor a, a ; a = 0 
 
-  ; d == 0 && e == 0
+  ; player_y (d) == 0
   cp a, d
   jr nz, @not_north REL 
-  cp a, e
-  jr nz, @not_north REL
 
   ; load north as direction
   ld a, NORTH 
@@ -89,6 +103,7 @@ room_goto_player_pos:
   ld a, EXIT_SPECIAL 
   ; no need to jmp in default case
 
+
   ; transitions to a new room 
   ; that is part of the map:
   ; inputs:
index 570744de6ae2a51d2413e69c7b704d8612a5e1e4..3c6ac56982334808f2f4a1fc83aa56b5fef4a089 100644 (file)
@@ -101,7 +101,7 @@ player_update:
 @no_anim:
 
   ; set collision mask
-  ld a, RF_WALL 
+  ld a, RF_WALL | RF_DOOR 
   ld [ct_mask], a
   
   ; anim_target_y = y movement target 
@@ -243,14 +243,25 @@ player_update:
   add a, 8
   ld e, a ; e = target x + 8 to center on tile 
   call collision_tile 
+  ld h, a ; store original a in h for now 
+
+  and a, RF_DOOR
+  jr z, @no_door_hit REL
+
+  ; set room load flag is door was hit
+  ld a, [engine_flags]
+  or a, EG_FLOAD_ROOM 
+  ld [engine_flags], a
+  
+
+@no_door_hit:
+  ld a, h ; restore original a for next check  
+  and a, RF_WALL
   pop hl
+  
   jr z, @no_collision REL
     ; clear anim memory
-    xor a, a
-    ld [anim_move_y], a
-    ld [anim_move_x], a
-    ld [anim_step_y], a
-    ld [anim_step_x], a
+    call anim_clear 
 @no_collision:
 
 @skip_input:
index 035ce8c6a7f58a24edf405fdb23b53f60abb931a..21a42444e85585f0ac89d26482e194264a2e856e 100644 (file)
@@ -43,6 +43,11 @@ vblank:
   ret ; never set frame to be ready during game-over 
 @not_game_over:
 
+  ; check for room transition 
+  ld a, [engine_flags]
+  and a, EG_FLOAD_ROOM
+  call nz, room_goto_player_pos
+
   ld a, 1
   ld [frame_ready], a
   ret
index 6794c5751872a9cba0bb8594875fb183d9dd9d04..b7f3773d51f00542a8e65be2b9779b1d64afc403 100644 (file)
@@ -143,6 +143,13 @@ curr_room_exits: .adv 2
 ui_flags: .adv 1
 draw_flags: .adv 1
 
+  ; engine flags 
+.se 1
+  ; if set to 1, call room_goto_player_pos in next blank
+.de EG_FLOAD_ROOM, 1
+
+engine_flags: .adv 1
+
   ; tmp can be used by routines as
   ; they see fit
 tmp: .adv 16