From: Lukas Krickl Date: Mon, 12 Jan 2026 15:47:33 +0000 (+0100) Subject: actor: Added actor rendering X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=37d771f926f5746c4e32567d418eeb1caea0abea;p=gbrg%2F.git actor: Added actor rendering --- diff --git a/src/actor.s b/src/actor.s index cc22617..f81d4a5 100644 --- a/src/actor.s +++ b/src/actor.s @@ -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: diff --git a/src/map.s b/src/map.s index 10f4e21..095decf 100644 --- 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 diff --git a/src/update.s b/src/update.s index 04da590..450a7aa 100644 --- a/src/update.s +++ b/src/update.s @@ -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 diff --git a/src/wram.s b/src/wram.s index fb083fe..ce954b5 100644 --- a/src/wram.s +++ b/src/wram.s @@ -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