From 8e5094f3be7c507633ac42fa5b2e831e3eaa58da Mon Sep 17 00:00:00 2001 From: Lukas Krickl Date: Mon, 27 Oct 2025 15:09:26 +0100 Subject: [PATCH] enemy: added basic walking guard --- src/enemy.s | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) diff --git a/src/enemy.s b/src/enemy.s index 4fc2725..123f625 100644 --- a/src/enemy.s +++ b/src/enemy.s @@ -4,6 +4,12 @@ act_enemy_guard: actdef ACT_T_GUARD, 0, 0, 10, 0 +#define ACT_GUARD_WALK_RIGHT 0 +#define ACT_GUARD_SHOOT 1 +#define ACT_GUARD_WALK_LEFT 2 + +#define ACT_GUARD_MOVE_FRAMES 40 + ; updates the guard enemy ; inputs: ; de: actor ptr @@ -29,11 +35,100 @@ act_guard_update: ld a, RF_ENEMY call actor_write_default_collider + ; call states + ld hl, act_state + add hl, de + ld a, [hl] + cp a, ACT_GUARD_WALK_RIGHT + jp z, act_guard_walk_right + + cp a, ACT_GUARD_SHOOT + jp z, act_guard_shoot + + cp a, ACT_GUARD_WALK_LEFT + jp z, act_guard_walk_left + ret @despawn: call actor_despawn ret + ; guard shoot state + ; inputs: + ; de: actor +act_guard_shoot: + ; TODO + ld hl, act_state + add hl, de + ld a, ACT_GUARD_WALK_LEFT + ld [hl], a + ret + + ; actor walk left state + ; inputs: + ; de: actor ptr + ; uses: + ; p0 as timer +act_guard_walk_left: + ; walk + ld hl, act_pos_x + add hl, de + ld a, [hl] + dec a + ld [hl], a + + ; process timer + ld hl, act_p0 + add hl, de + ld a, [hl] + inc a + ld [hl], a + cp a, ACT_GUARD_MOVE_FRAMES + jr nz, @not_done REL + ; clear p0 and transition + xor a, a + ld [hl], a + + ld hl, act_state + add hl, de + ld a, ACT_GUARD_WALK_RIGHT + ld [hl], a +@not_done: + ret + + ; walk right state + ; inputs: + ; de: actor ptr + ; uses: + ; p0 as timer +act_guard_walk_right: + ; walk + ld hl, act_pos_x + add hl, de + ld a, [hl] + inc a + ld [hl], a + + ; process timer + ld hl, act_p0 + add hl, de + ld a, [hl] + inc a + ld [hl], a + cp a, ACT_GUARD_MOVE_FRAMES ; how many frames do we walk? + jr nz, @not_done REL + ; clear p0 and transition + xor a, a + ld [hl], a + + ld hl, act_state + add hl, de + ld a, ACT_GUARD_SHOOT + ld [hl], a + +@not_done: + ret + ; draws the guard enemy ; inputs: ; de: actor ptr @@ -90,4 +185,14 @@ act_guard_init: add hl, de ld a, 4 ld [hl], a + + xor a, a + ld hl, act_state + add hl, de + ld [hl], a + + ld hl, act_p0 + add hl, de + ld [hl], a + ret -- 2.30.2