; updates the entire current actor table
-act_all_update:
+act_update_all:
+ ld hl, map_actors
+ ld b, ACT_MAX
+@loop:
+ push hl
+ pop de ; de = act for update call
+ push hl
+ push bc
+ call act_update
+ pop bc
+ pop hl
+ ld de, act_size
+ add hl, de
+
+ dec b
+ jr nz, @loop REL
ret
; updates a bat
; inputs:
; de: actor ptr
act_r_bat:
+ push de
+ call rand ; pick a random direction
+ and a, 3
+ pop de
+ ld hl, act_dir
+ add hl, de
+ ld [hl], a
+
+ call act_move_forward
+
ret
act_update_table:
; restores actor position
; from tmp_act_y/x
+ ; unsets act_just_moved
; inputs:
; de: actor
; preserves:
ld [hl+], a
ld a, [tmp_act_x]
ld [hl], a
+
+ xor a, a
+ ldh [act_just_moved], a
ret
; tests if the new actor location contains
; performs collision checks
; inputs:
; de: actor
+ ; returns:
+ ; act_just_moved: 1 -> moved
+ ; act_just_moved: 0 -> not moved
act_move_forward:
+ xor a, a
+ ldh [act_just_moved], a
call _act_backup_pos
push de
call act_apply_vec
+ ld a, 1
+ ldh [act_just_moved], a
+
; check if player collides with actor
; at new location
pop de
; inputs:
; de: actor
act_move_back:
+ xor a, a
+ ldh [act_just_moved], a
call _act_backup_pos
push de
ld b, [hl] ; b = direction
call act_apply_vec
+ ldh [act_just_moved], a
pop de
call _act_check_act_in_location
; 0x80 - 0x90 are used by dma routines
.org 0xFF90
+
+ ; this flag is set to 1
+ ; by move forward or back
+ ; to indicate a move occured
+act_just_moved: .adv 1
player_move_forward:
ld de, player
call act_move_forward
+
+ ldh a, [act_just_moved]
+ cp a, 1
+ call z, act_update_all
jp map_full_draw
player_move_back:
ld de, player
call act_move_back
+
+ ldh a, [act_just_moved]
+ cp a, 1
+ call z, act_update_all
jp map_full_draw