actor: Added simple bat script
authorLukas Krickl <lukas@krickl.dev>
Thu, 18 Dec 2025 16:54:21 +0000 (17:54 +0100)
committerLukas Krickl <lukas@krickl.dev>
Thu, 18 Dec 2025 16:54:21 +0000 (17:54 +0100)
Added actor update call when player moves

src/actor.s
src/hram.s
src/player.s
src/wram.s

index 118981ade43ad999e25f55d2ebc8d71e593c71b1..4efafde877d363889a01d59194ed6e6d4191f15c 100644 (file)
@@ -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
index a8ec00d34d7560dd677b274ee5f635015e34694f..fe3a90e3b3a1b5e743be86eddaee689339050f26 100644 (file)
@@ -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
index 34a11b7b9b2048799736c4ee9e098b2797070018..46af4c057609eb46fc42a669aace322310475f9e 100644 (file)
@@ -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
index 564b36cc5788df9fa77e7927227e3fa261dd0b11..6305210a773426b3b6b66cab6acceb190c5bd0a9 100644 (file)
@@ -142,3 +142,4 @@ act_nearby: .adv 2
        ; to the current players facing direction
        ; populated when map is drawn
 prop_nearby: .adv 2
+