From e223bf4b40e884d9c514199487401d0a320634c5 Mon Sep 17 00:00:00 2001 From: Peter Stockings Date: Mon, 5 Jan 2026 13:00:16 +1100 Subject: [PATCH] Create enemy type --- src/core/types.ts | 6 ++++-- src/engine/simulation/simulation.ts | 4 ++-- src/rendering/DungeonRenderer.ts | 4 ++-- src/rendering/FxRenderer.ts | 4 ++-- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/core/types.ts b/src/core/types.ts index 3f8e60a..0dab8ab 100644 --- a/src/core/types.ts +++ b/src/core/types.ts @@ -3,6 +3,8 @@ export type EntityId = number; export type Vec2 = { x: number; y: number }; export type Tile = number; +export type EnemyType = "rat" | "bat" | "spider"; +export type ActorType = "player" | EnemyType; export type Action = | { type: "move"; dx: number; dy: number } @@ -15,7 +17,7 @@ export type SimEvent = | { type: "damaged"; targetId: EntityId; amount: number; hp: number; x: number; y: number; isCrit?: boolean; isBlock?: boolean } | { type: "dodged"; targetId: EntityId; x: number; y: number } | { type: "healed"; actorId: EntityId; amount: number; x: number; y: number } - | { type: "killed"; targetId: EntityId; killerId: EntityId; x: number; y: number; victimType?: "player" | "rat" | "bat" } + | { type: "killed"; targetId: EntityId; killerId: EntityId; x: number; y: number; victimType?: ActorType } | { type: "waited"; actorId: EntityId } | { type: "exp-collected"; actorId: EntityId; amount: number; x: number; y: number } @@ -107,7 +109,7 @@ export interface BaseActor { export interface CombatantActor extends BaseActor { category: "combatant"; isPlayer: boolean; - type: "player" | "rat" | "bat"; + type: ActorType; speed: number; energy: number; stats: Stats; diff --git a/src/engine/simulation/simulation.ts b/src/engine/simulation/simulation.ts index 0e427c5..2b6b006 100644 --- a/src/engine/simulation/simulation.ts +++ b/src/engine/simulation/simulation.ts @@ -1,4 +1,4 @@ -import type { World, EntityId, Action, SimEvent, Actor, CombatantActor, CollectibleActor } from "../../core/types"; +import type { World, EntityId, Action, SimEvent, Actor, CombatantActor, CollectibleActor, ActorType } from "../../core/types"; import { isBlocked } from "../world/world-logic"; import { GAME_CONFIG } from "../../core/config/GameConfig"; @@ -181,7 +181,7 @@ function handleAttack(w: World, actor: Actor, action: { targetId: EntityId }): S killerId: actor.id, x: target.pos.x, y: target.pos.y, - victimType: target.type as "player" | "rat" | "bat" + victimType: target.type as ActorType }); w.actors.delete(target.id); diff --git a/src/rendering/DungeonRenderer.ts b/src/rendering/DungeonRenderer.ts index 5bde52b..9456d49 100644 --- a/src/rendering/DungeonRenderer.ts +++ b/src/rendering/DungeonRenderer.ts @@ -1,5 +1,5 @@ import Phaser from "phaser"; -import { type World, type EntityId, type Vec2 } from "../core/types"; +import { type World, type EntityId, type Vec2, type ActorType } from "../core/types"; import { TILE_SIZE } from "../core/constants"; import { idx, isWall } from "../engine/world/world-logic"; import { GAME_CONFIG } from "../core/config/GameConfig"; @@ -264,7 +264,7 @@ export class DungeonRenderer { this.fxRenderer.showHeal(x, y, amount); } - spawnCorpse(x: number, y: number, type: "player" | "rat" | "bat") { + spawnCorpse(x: number, y: number, type: ActorType) { this.fxRenderer.spawnCorpse(x, y, type); } diff --git a/src/rendering/FxRenderer.ts b/src/rendering/FxRenderer.ts index 6320965..c01aac2 100644 --- a/src/rendering/FxRenderer.ts +++ b/src/rendering/FxRenderer.ts @@ -1,5 +1,5 @@ import Phaser from "phaser"; -import { type EntityId } from "../core/types"; +import { type EntityId, type ActorType } from "../core/types"; import { TILE_SIZE } from "../core/constants"; import { GAME_CONFIG } from "../core/config/GameConfig"; @@ -109,7 +109,7 @@ export class FxRenderer { }); } - spawnCorpse(x: number, y: number, type: "player" | "rat" | "bat") { + spawnCorpse(x: number, y: number, type: ActorType) { const textureKey = type === "player" ? "warrior" : type; const corpse = this.scene.add.sprite(