; 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
; 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
ld a, EXIT_SPECIAL
; no need to jmp in default case
+
; transitions to a new room
; that is part of the map:
; inputs:
@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
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:
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
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