enemy: added demo actor draw
authorLukas Krickl <lukas@krickl.dev>
Sat, 20 Sep 2025 06:07:10 +0000 (08:07 +0200)
committerLukas Krickl <lukas@krickl.dev>
Sat, 20 Sep 2025 06:07:10 +0000 (08:07 +0200)
src/actor.s
src/enemy.s [new file with mode: 0644]
src/main.s
src/player.s
src/update.s

index 6aafc46aee7eb6954b273b19929fc673f8323534..aa5396e12c967282a64167b37479d5fdbd90a6e4 100644 (file)
@@ -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 (file)
index 0000000..4c22a67
--- /dev/null
@@ -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
index c1f398f3fe6ddb25421a4fe0d670ae59df9103a1..544376a02860bd07c5769450a3a1b8c701b27488 100644 (file)
@@ -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"
index 2b5b478849e9ca3d9c77b6ea25b6a63ef9f32fda..4a3147e1d2238b0e2b701c6b7e6bce7d4b8ca1ce 100644 (file)
@@ -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
index e342b237be45233c48bccaefbf1b6d726fd5f75f..74b365b307997c50f7bdccafef7d54057d5917c6 100644 (file)
@@ -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