actor: Added actor init code and tables for update and draw calls
authorLukas Krickl <lukas@krickl.dev>
Thu, 18 Dec 2025 08:14:24 +0000 (09:14 +0100)
committerLukas Krickl <lukas@krickl.dev>
Thu, 18 Dec 2025 08:14:24 +0000 (09:14 +0100)
src/actor.s
src/levels.s
src/map.s
src/player.s
src/update.s

index 7745ca5b73ec086d3ba91218ec20f147393f9fc7..1f61e2fef27242f8e83a379143a1b19bf88d84de 100644 (file)
@@ -40,28 +40,162 @@ act_dir_back:
        ; inputs:
        ;               hl: actor table
 act_table_load:
+       push hl
+       ; clear old table data
+       ld hl, map_actors
+       ld bc, act_size * ACT_MAX
+       ld d, 0
+       call memset
+       
+       pop de ; de = source
+       ld a, d
+       or a, e
+       ret z ; no table? -> bail
+
+
+       ld hl, map_actors ; hl = dst
+
+       ; load all tables until type is 0
+@load_loop:
+               ; check type for NULL
+               ld a, [de]
+               cp a, 0
+               jp z, @load_done
+               
+               ld bc, act_size
+               call memcpy
+               ; hl = next destination
+               ; de = next source
+               jp @load_loop
+@load_done:
+       
+       ; run actor init code for each actor type
+       ld hl, map_actors
+@init_loop:
+               ; check for type NULL
+               ld a, [hl]
+               cp a, 0
+               jp z, @init_done
+               
+               push hl
+               pop de
+               push de
+               call act_init
+               pop hl
+
+               ld bc, act_size
+               add hl, bc ; next act
+               jp @init_loop
+@init_done:
+       ret
+       
+       ; nop actor routine
+act_r_nop:
        ret
 
+
        ; updates the entire current actor table
 act_all_update:
        ret
+       
+       ; updates a bat
+       ; inputs:
+       ;               de: actor ptr
+act_r_bat:
+       ret
+
+act_update_table:
+       ; NULL
+       dw act_r_nop 
+       ; player
+       dw act_r_nop 
+       ; bat
+       dw act_r_bat
 
        ; updates and draws an actor
        ; calls different routines fro combat and map state
        ; inputs:
-       ;               hl: actor ptr
+       ;               de: actor ptr
 act_update:
        ; TODO: read type, get ptr from table
        ; and call
+       ld a, [de] ; type
+       add a, a ; * 2 for offset
+       ld hl, act_update_table
+       ld b, 0
+       ld c, a
+       add hl, bc
+
+       ; load routine ptr
+       ld a, [hl+]
+       ld h, [hl]
+       ld l, a
+       jp hl
+       
+       ; generic set tact init call
+       ; inputs:
+       ;               de: actor ptr
+act_init_set_tact:
+       call act_set_tact
        ret
+
+act_init_table:
+       ; NULL
+       dw act_r_nop 
+       ; player
+       dw act_init_set_tact
+       ;       bat
+       dw act_init_set_tact
+
+       ; inits an actor based on its type
+       ; inputs:
+       ;               de: actor ptr
+act_init:
+       ld a, [de] ; type
+       add a, a ; * 2 for table offset
+       ld hl, act_init_table
+       ld b, 0
+       ld c, a
+       add hl, bc
+
+       ; load routine ptr
+       ld a, [hl+]
+       ld h, [hl]
+       ld l, a
+       jp hl
+       
+       ; draws a bat actor
+       ; inputs:
+       ;               de: act ptr
+act_draw_nearby_bat:
+       ret
+
+act_draw_nearby_table:
+       ; NULL
+       dw act_r_nop
+       ; player
+       dw act_r_nop
+       ; bat
+       dw act_draw_nearby_bat
        
        ; draws an actor if they are near
        ; usuall act_nearby or prop_nearby
        ; to the camera
        ; inputs:
-       ;               hl: actor ptr
+       ;               de: actor ptr
 act_draw_nearby:
-       ret
+       ld a, [de] ; type
+       add a, a ; * 2 for offset
+       ld hl, act_draw_nearby_table
+       ld b, 0
+       ld c, a
+       add hl, bc
+
+       ; load routine ptr
+       ld a, [hl+]
+       ld h, [hl]
+       ld l, a
+       jp hl
        
        ; clears tact at the current actors position
        ; inputs:
index 2641081d69b9333a0b56b0484d60905bdcb17e43..a4aae475d55b68f9a5438b30bb1b28e22649b401 100644 (file)
@@ -9,12 +9,13 @@
        ; where each tile has values and its current state. The map can be drawn from this.
 
 l1:
-       mapdef MAP_F_DO_FULL_REDRAW, map_r_nop, 0, tile_banks_default 
+       mapdef MAP_F_DO_FULL_REDRAW, map_r_nop, l1_acts, tile_banks_default 
 #include "l1.inc"
        
        ; l1 actor table
 l1_acts:
        actdef ACT_T_BAT, 0, 10, 10, 0, 0
+       actdef ACT_T_BAT, 0, 0, 2, 0, 0
        .db 0 ; terminate
        
 
index 1ba296e3eab952f6279c86477af612f9c7ff58a8..a444b0ac176d8955d85a5958c6f58971a94583c0 100644 (file)
--- a/src/map.s
+++ b/src/map.s
@@ -96,10 +96,21 @@ map_settings_load:
        ld a, [hl]
        ld [bc], a
 
-
-
-       ; TODO: 
+       
+       push de
        ; load actors
+       ld hl, map_acts
+       add hl, de
+       ld a, [hl+]
+       ld h, [hl]
+       ld l, a
+       call act_table_load
+       
+       ; init the player
+       ld de, player
+       call act_init
+       
+       pop de
        ret
        
        ; loads a tile buffer
index 22fdf82391d73c0548e13f049c885d07be04442b..34a11b7b9b2048799736c4ee9e098b2797070018 100644 (file)
@@ -21,6 +21,9 @@ player_init:
        xor a, a
        ld [player+act_pos_y], a
        ld [player+act_pos_x], a
+
+       ld a, ACT_T_PLAYER
+       ld [player], a ; set type
        
        ret
        
index b5a1953816ca0254d2b2ae4ab122682980546f3e..3c1180b9085d9b204931459ee876ce5a0ad24b8a 100644 (file)
@@ -9,7 +9,7 @@ update_game:
        ; player should update even in debug mode
        call player_update
        call compass_draw
-       
+
   ; tick rng every frame
        call rand
 
@@ -79,6 +79,7 @@ update_render:
        ret
        
 new_game:
+       call player_init
        ld de, l1
        call map_load
 
@@ -132,7 +133,6 @@ game_init:
   ld [ROBP1], a
   ld [shadow_robp1], a
 
-       call player_init
        call ui_init
 
   ret