The door animation now only plays when the player touches a door.
This made the code a lot simpler to deal with overall.
; inputs:
; a: tile flags
; b: tile index
- ; c: previous player rt special flags
+ ; unit_test_collision_pos_y/x
; de: actor
objanim_door_open:
push de
ld bc, st_size
call memcpy
pop bc
-
pop de
- ld hl, act_pos_y
- add hl, de ; hl = act y pos
-
- ; save palyer rt flags in flags
- ; but invert CF_COVERED
- ld a, c
+
+ ; clear flags
ld de, objanim+obja_flags
+ xor a, a
ld [de], a
inc de ; de = y pos
- ld a, [hl+]
+ ld a, [unit_test_collision_pos_y]
ld [de], a
inc de ; de = x pos
- ld a, [hl]
+ ld a, [unit_test_collision_pos_x]
ld [de], a
inc de ; de = dat
or a, GPF_PAUSE_UPDATE
ld [gameplay_flags], a
- ; prevent player from drawing
- ld de, player_unit
- ld bc, unit_nop_draw
- call unit_set_draw
-
ret
; state function for door opening animation
objanim_door_open_fn:
#define TMP_Y, scratch
#define TMP_X, scratch+1
-
call load_unit_obj
ld de, objanim+st_size
; de = anim flags
; set first object
- ; reload rt flags from backup while the animation is playing
- ld a, [de]
- ld [player_rt_special_flags], a
inc de ; skip flags
ld a, [de] ; a = y position
inc de ; de = x postion
and a, ~GPF_PAUSE_UPDATE & 0xFF
ld [gameplay_flags], a
- ; restore player draw call
- ld de, player_unit
- ld bc, player_draw
- call unit_set_draw
-
ld bc, st_null
ret
#undefine TMP_X
; hl should still be tile ptr here
- ; check if player is on a door tile
- ; if so, remove door and queue a map redraw
- and a, CF_DOOR
- ; save CF_DOOR flag value to
- ; return before input handling later
- push af
- push de
- call nz, unit_player_remove_door
- pop de
-
- ; check for exit flags
+ ; check for exit flags
push de
call unit_check_exit_hit
pop de
call unit_scroll_center
pop de
- ; return if CF_DOOR was handeled earlier
- ; and skip inputs
- ; load next state in case this ret is hit
- pop af
- jr nz, @early_ret REL
-
push de
call unit_handle_inputs
pop de
+ push de
+ push bc
+ ; test last collision flags
+ ld a, [unit_test_collision_cf_flags]
+ and a, CF_DOOR
+ call nz, unit_player_remove_door
+ pop bc
+ pop de
+
ret
-@early_ret:
- ldnull bc
- ret
; removes the door tile the player is currently
; standing on
; inputs:
+ ; unit_test_collision_pos_y/x
; de: actor
- ; hl: ptr to tile player is on
- ; b: tile index
- ; a: tile flags
unit_player_remove_door:
+ ; get tile of last collision
+ ld a, [unit_test_collision_pos_y]
+ ld b, a
+ ld a, [unit_test_collision_pos_x]
+ ld c, a
+ call map_get_tile
+
; schedule animation
push_all
call objanim_door_open
ld a, CF_COVERED
ld [hl], a
- ld hl, act_pos_y
- add hl, de
- ld a, [hl] ; load y offset
+ ld a, [unit_test_collision_pos_y] ; load y offset
call map_request_redraw_at
ret
.db CF_COLLISION, CF_COLLISION
.db 0x00 ; floor
; doors
- .db CF_DOOR | CF_COVERED, CF_DOOR | CF_COVERED, CF_DOOR | CF_COVERED, CF_DOOR | CF_COVERED
+ .db CF_COLLISION | CF_DOOR | CF_COVERED, CF_COLLISION | CF_DOOR | CF_COVERED
+ .db CF_COLLISION | CF_DOOR | CF_COVERED, CF_COLLISION | CF_DOOR | CF_COVERED
; roof
.db CF_COVERED
#macro unit_test_collision
; perform tile collision check
push de
+ call unit_get_pos
+ $1
+
; write y and x pos
ld a, b
ld [unit_test_collision_pos_y], a
ld a, c
ld [unit_test_collision_pos_x], a
- call unit_get_pos
- $1
+
push bc
call map_get_tile
; set flags result