From ec3366cbde33dba550fa3852ba6d68f7a1a79282 Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Tue, 24 Dec 2024 07:49:52 +0100 Subject: [PATCH] WIP: room loading It now crashes whenever a transition happens. --- BUGS.md | 1 + src/map.s | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/BUGS.md b/BUGS.md index c854c2b..dd14ea8 100644 --- 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 diff --git a/src/map.s b/src/map.s index ff6481e..d941d92 100644 --- 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 -- 2.30.2