From: Lukas Krickl Date: Thu, 18 Dec 2025 16:54:21 +0000 (+0100) Subject: actor: Added simple bat script X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=053a4668e0058670f6164d6166e6c30b9a7e580c;p=gbrg%2F.git actor: Added simple bat script Added actor update call when player moves --- diff --git a/src/actor.s b/src/actor.s index 118981a..4efafde 100644 --- a/src/actor.s +++ b/src/actor.s @@ -98,13 +98,38 @@ act_r_nop: ; 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: @@ -434,6 +459,7 @@ _act_backup_pos: ; restores actor position ; from tmp_act_y/x + ; unsets act_just_moved ; inputs: ; de: actor ; preserves: @@ -446,6 +472,9 @@ _act_restore_pos: 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 @@ -478,7 +507,12 @@ _act_check_act_in_location: ; 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 @@ -505,6 +539,9 @@ act_move_forward: call act_apply_vec + ld a, 1 + ldh [act_just_moved], a + ; check if player collides with actor ; at new location pop de @@ -518,6 +555,8 @@ act_move_forward: ; inputs: ; de: actor act_move_back: + xor a, a + ldh [act_just_moved], a call _act_backup_pos push de @@ -549,6 +588,7 @@ act_move_back: ld b, [hl] ; b = direction call act_apply_vec + ldh [act_just_moved], a pop de call _act_check_act_in_location diff --git a/src/hram.s b/src/hram.s index a8ec00d..fe3a90e 100644 --- a/src/hram.s +++ b/src/hram.s @@ -2,3 +2,8 @@ ; 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 diff --git a/src/player.s b/src/player.s index 34a11b7..46af4c0 100644 --- a/src/player.s +++ b/src/player.s @@ -92,9 +92,17 @@ player_handle_move: 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 diff --git a/src/wram.s b/src/wram.s index 564b36c..6305210 100644 --- a/src/wram.s +++ b/src/wram.s @@ -142,3 +142,4 @@ act_nearby: .adv 2 ; to the current players facing direction ; populated when map is drawn prop_nearby: .adv 2 +