From: Lukas Krickl Date: Mon, 23 Dec 2024 13:28:51 +0000 (+0100) Subject: Added ability to flag room loading X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=f829713774893bd94f7b6cbc2de1ad64a0446f84;p=gbrg%2F.git Added ability to flag room loading 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 --- diff --git a/src/map.s b/src/map.s index dfe844d..acd54c1 100644 --- 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: diff --git a/src/player.s b/src/player.s index 570744d..3c6ac56 100644 --- a/src/player.s +++ b/src/player.s @@ -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: diff --git a/src/video.s b/src/video.s index 035ce8c..21a4244 100644 --- a/src/video.s +++ b/src/video.s @@ -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 diff --git a/src/wram.s b/src/wram.s index 6794c57..b7f3773 100644 --- a/src/wram.s +++ b/src/wram.s @@ -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