WIP: room loading
authorLukas Krickl <lukas@krickl.dev>
Tue, 24 Dec 2024 06:49:52 +0000 (07:49 +0100)
committerLukas Krickl <lukas@krickl.dev>
Tue, 24 Dec 2024 06:49:52 +0000 (07:49 +0100)
It now crashes whenever a transition happens.

BUGS.md
src/map.s

diff --git a/BUGS.md b/BUGS.md
index c854c2b77ade3cbcd7ab363189aafd64b06e79f4..dd14ea8d19a72ffe3db56a3d90b154f9e26f561a 100644 (file)
--- a/BUGS.md
+++ b/BUGS.md
@@ -1,5 +1,6 @@
 # Known Bugs
 
 - When moving a player sometimes gains an extra pixel
+- When loading a map sometimes a double load is caused 
 - When moving off-screen NORTH the movement behaves weird
 - Map loads can occur when the player is moving off a door tile
index ff6481ebbe24f5a51c7f040c51f1f60d8910b132..d941d922a76da0eaee68675afcb214940f68b907 100644 (file)
--- a/src/map.s
+++ b/src/map.s
@@ -85,20 +85,65 @@ room_goto_player_pos:
   ld e, a ; d = player x
   div16 e ; d = player x tile 
 
+  dec hl ; hl = player_y
+
   ; compare to expected positions to decide what to do
 
-  ; 0/0 == north
   xor a, a ; a = 0 
 
-  ; player_y (d) == 0
+  ; player_y (d) == 0 (NORTH)
   cp a, d
   jr nz, @not_north REL 
 
+  ; set new player position
+  ld a, 0x60
+  ld [hl], a ; player_y = 0x60 after going NORTH
+
   ; load north as direction
   ld a, NORTH 
   jp room_goto 
 @not_north:
 
+  ; player_x (e) == 0 (WEST)
+  cp a, e 
+  jr nz, @not_west REL
+
+  ld a, 0x80
+  inc hl ; hl = player_x 
+  ld [hl], a ; player_x = 0x80 after going WEST
+
+  ; load WEST as direction
+  ld a, WEST
+  jp room_goto
+@not_west:
+
+  ld a, 9 ; tile 9 == EAST
+  ; player_x (e) == 9 (EAST)
+  cp a, e
+  jr nz, @not_east REL
+
+  ld a, 0x10
+  inc hl ; hl = player_x 
+  ld [hl], a ; player_x = 0x10 after going EAST
+  
+  ; load EAST as direction
+  ld a, EAST
+  jp room_goto
+@not_east:
+  
+  ld a, 7 ; tile 7 == SOUTH
+  ; player_y (d_ == 7 (SOUTH)
+  cp a, d 
+  jr nz, @not_south REL
+
+  ld a, 0x10 
+  ld [hl], a ; player_y = 0x10 after going SOUTH
+
+  ; load SOUTH as direction
+  ld a, SOUTH
+  jp room_goto
+@not_south:
+
   ; default use special exit
   ld a, EXIT_SPECIAL 
   ; no need to jmp in default case