From: Lukas Krickl Date: Thu, 18 Dec 2025 08:14:24 +0000 (+0100) Subject: actor: Added actor init code and tables for update and draw calls X-Git-Url: https://git.krickl.dev/?a=commitdiff_plain;h=7ff838a384345acd0f5ce695d87a13888afbee9c;p=gbrg%2F.git actor: Added actor init code and tables for update and draw calls --- diff --git a/src/actor.s b/src/actor.s index 7745ca5..1f61e2f 100644 --- a/src/actor.s +++ b/src/actor.s @@ -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: diff --git a/src/levels.s b/src/levels.s index 2641081..a4aae47 100644 --- a/src/levels.s +++ b/src/levels.s @@ -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 diff --git a/src/map.s b/src/map.s index 1ba296e..a444b0a 100644 --- 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 diff --git a/src/player.s b/src/player.s index 22fdf82..34a11b7 100644 --- a/src/player.s +++ b/src/player.s @@ -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 diff --git a/src/update.s b/src/update.s index b5a1953..3c1180b 100644 --- a/src/update.s +++ b/src/update.s @@ -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