actor: Added actor rendering
authorLukas Krickl <lukas@krickl.dev>
Mon, 12 Jan 2026 15:47:33 +0000 (16:47 +0100)
committerLukas Krickl <lukas@krickl.dev>
Mon, 12 Jan 2026 15:47:33 +0000 (16:47 +0100)
src/actor.s
src/map.s
src/update.s
src/wram.s

index cc22617695f7438369cd6d38955aef537d40cc07..f81d4a5e31a84cbf4cce7eaf7866f36750adc231 100644 (file)
@@ -77,6 +77,26 @@ act_update_all:
                dec b
        jr nz, @loop REL
        ret
+
+
+       ; draws the entire current actor table
+act_draw_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_draw
+               pop bc
+               pop hl
+               ld de, act_size
+               add hl, de
+
+               dec b
+       jr nz, @loop REL
+       ret
        
        ; updates a bat
        ; inputs:
@@ -103,12 +123,9 @@ act_update_table:
        dw act_r_bat
 
        ; updates and draws an actor
-       ; calls different routines fro combat and map state
        ; inputs:
        ;               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
@@ -121,6 +138,76 @@ act_update:
        ld h, [hl]
        ld l, a
        jp hl
+
+       ; draws the bat actor
+       ; inputs:
+       ;               de: actor ptr
+act_d_bat:
+       ld hl, act_pos_y
+       add hl, de
+       push hl
+       pop de ; de = act_pos_y in tiles
+
+       ld a, 1
+       call oamalloc
+
+       ; y pos
+       ld a, [de]
+       ld b, a
+       ld a, [map_offset_y]
+       add a, b
+
+       mul8 a
+       add a, OBJ_OFF_Y
+       ld [hl+], a
+       
+       ; x pos
+       inc de ; de = act pos x in tiles
+
+       ld a, [de]
+       ld b, a
+       ld a, [map_offset_x]
+       add a, b
+
+       mul8 a
+       add a, OBJ_OFF_X
+       ld [hl+], a
+
+       ; tile
+       ld a, 0xA3
+       ld [hl+], a
+
+       ; flags
+       xor a, a
+       ld [hl], a
+       
+       ret
+
+act_draw_table:
+       ; NULL
+       dw act_r_nop
+       ; player
+       dw act_r_nop
+       ; bat
+       dw act_d_bat
+
+       ; draws all actors
+       ; inputs:
+       ;               de: actor ptr
+act_draw:
+       ld a, [de] ; type
+       add a, a ; * 2 for offset
+       ld hl,  act_draw_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:
index 10f4e21ec8e938cd9271564cc517adc7143929cc..095decfd1f7cf2c7cf336ecb0b080f7cf3860092 100644 (file)
--- a/src/map.s
+++ b/src/map.s
@@ -445,14 +445,16 @@ map_full_draw:
        call map_set_visible_range
 
        ; set map offset
-       ld a, b
-       mul8 a
-       sub a, OBJ_OFF_Y
+       ; offset to screen corner from player position
+       ; in tiles
+       ld a, [player+act_pos_y]
+       sub a, 10
+       cpl
        ld [map_offset_y], a
 
-       ld a, c
-       mul8 a
-       sub a, OBJ_OFF_X
+       ld a, [player+act_pos_x]
+       sub a, 11
+       cpl
        ld [map_offset_x], a
        
        ; render destination
index 04da59070bb33c32ac2767ef3dda84560f369a53..450a7aafc94d4ade959ada62c064486642dad9ea 100644 (file)
@@ -9,11 +9,23 @@ update_game:
        ; player should update even in debug mode
        call player_update
        call player_draw
+       
+       ; if turn flag is 1 -> update actors
+       ld a, [turn_flag]
+       cp a, 1
+       call z, act_update_all
+
+       call act_draw_all
 
   ; tick rng every frame
        call rand
 
        call ui_update
+       
+       ; clear turn flag
+       xor a, a
+       ld [turn_flag], a
+
   ret
 
        
index fb083fe004d7a39cb542b2edc711fb5808aa7500..ce954b5a89c5cf614d7ea4b6dfa4bd091a6c1a69 100644 (file)
@@ -45,6 +45,10 @@ demo_inputs: .adv 2
        
        ; gameplay control flags
 game_flags: .adv 1
+       
+       ; if 0 == player can perform actions
+       ; if 1 == all other actors can perform actions
+turn_flag: .adv 1
 
        ; debug control flags
 debug_flags: .adv 1