From 07a814ffa2e9ad2b571ecf6df98b3ab74257ec3c Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Sat, 20 Sep 2025 08:07:10 +0200 Subject: [PATCH] enemy: added demo actor draw --- src/actor.s | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/enemy.s | 38 ++++++++++++++++++++++++++++++++++ src/main.s | 1 + src/player.s | 7 ++++++- src/update.s | 4 ++++ 5 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 src/enemy.s diff --git a/src/actor.s b/src/actor.s index 6aafc46..aa5396e 100644 --- a/src/actor.s +++ b/src/actor.s @@ -66,4 +66,62 @@ actor_draw: ld [hl+], a + ret + + ; actor no-op call +act_nop: + ret + + ; tables for each actor type +actor_update_draw_table: + dw act_nop + dw player_update_and_draw + dw act_guard_update_and_draw + + ; calls update for all actors + ; and draws them +actor_update_all: + ld de, actors + ld b, ACTS_MAX +@loop: + ; look up rotuine from table + ld a, [de] ; a = type + add a, a ; * 2 for offset + + push_all + ld b, 0 + ld c, a ; bc = offset + ld hl, actor_update_draw_table + add hl, bc + ld a, [hl+] + ld b, a + ld a, [hl] + ld h, a + ld l, b + + call_hl + pop_all + + ; move to next actor + ld hl, act_size + add hl, de + push hl + pop de ; de = next act + + dec b ; counter-- + jr nz, @loop REL + ret + + ; loads a test actor +actor_load_test: + ld de, act_enemy_guard + ld hl, actors + ld bc, act_size + call memcpy + + ; set a test position + ld a, 130 + ld [actors+act_pos_y], a + ld [actors+act_pos_x], a + ret diff --git a/src/enemy.s b/src/enemy.s new file mode 100644 index 0000000..4c22a67 --- /dev/null +++ b/src/enemy.s @@ -0,0 +1,38 @@ + +#define GUARD_SPRITE_IDLE1 0x88 + +act_enemy_guard: + actdef ACT_T_GUARD, 0, 0, 10, 0 + + ; updates the guard enemy + ; inputs: + ; de: actor ptr +act_guard_update: + ret + + ; draws the guard enemy + ; inputs: + ; de: actor ptr +act_guard_draw: + push de + ld a, 2 + call oamalloc + pop de + + push de + ld b, GUARD_SPRITE_IDLE1 + ld c, 0 + ld a, 0 + call actor_draw + pop de + + ld b, GUARD_SPRITE_IDLE1+2 + ld c, 0 + ld a, 8 + call actor_draw + ret + + ; combination of update and draw call +act_guard_update_and_draw: + call act_guard_draw + jp act_guard_update diff --git a/src/main.s b/src/main.s index c1f398f..544376a 100644 --- a/src/main.s +++ b/src/main.s @@ -56,6 +56,7 @@ main: #include "sys.s" #include "input.s" #include "player.s" +#include "enemy.s" #include "update.s" #include "ui.s" #include "audio.s" diff --git a/src/player.s b/src/player.s index 2b5b478..4a3147e 100644 --- a/src/player.s +++ b/src/player.s @@ -14,7 +14,7 @@ player_init: player_update: ret -#define PLAYER_SPRITE_IDLE1 0x88 +#define PLAYER_SPRITE_IDLE1 0x8D ; draws the special player actor player_draw: @@ -33,3 +33,8 @@ player_draw: ld a, 8 call actor_draw ret + + ; combination of update and draw call +player_update_and_draw: + call player_draw + jp player_update diff --git a/src/update.s b/src/update.s index e342b23..74b365b 100644 --- a/src/update.s +++ b/src/update.s @@ -10,6 +10,8 @@ update_game: call player_draw call player_update + + call actor_update_all ret @@ -17,6 +19,8 @@ new_game: ld de, l1_map call map_load + call actor_load_test + ld hl, update_game call game_set_state -- 2.30.2