Skip to content

Commit 382bd13

Browse files
committed
level: add random-walk npcs
1 parent 11aa4de commit 382bd13

10 files changed

Lines changed: 2557 additions & 5220 deletions

model/character.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export type ItemContainer = {
8383
remove(i: number, j: number): void
8484
}
8585

86-
type NPCType = "random" | "random-walk" | "static"
86+
export type NPCType = "random" | "random-walk" | "static"
8787

8888
export function spawnCharacter(
8989
id: string,
@@ -488,8 +488,6 @@ export class RandomlyTurnNPC extends Character {
488488
}
489489

490490
export class RandomWalkNPC extends Character {
491-
#counter = 32
492-
493491
override getNextAction(
494492
fieldTester: IFieldTester,
495493
collisionChecker: CollisionChecker,

model/field-block.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { CanvasWrapper } from "../util/canvas-wrapper.ts"
22
import { BLOCK_CHUNK_SIZE, BLOCK_SIZE, CELL_SIZE } from "../util/constants.ts"
33
import { seedrandom } from "../util/random.ts"
44
import { ceilN, floorN, modulo } from "../util/math.ts"
5-
import type { CellName, IBox } from "./character.ts"
5+
import type { CellName, IBox, NPCType } from "./character.ts"
66
import type { Item } from "./item.ts"
77

88
/**
@@ -42,7 +42,7 @@ export class FieldCell {
4242
class _ItemData {
4343
}
4444

45-
type CharacterType = "static" | "random"
45+
type CharacterType = NPCType
4646
type CharacterSpeed = 1 | 2 | 4 | 8 | 16
4747
type Dir = "up" | "down" | "left" | "right"
4848

@@ -551,4 +551,9 @@ export class FieldBlock {
551551
addSpawnInfo(spawn: SpawnInfo): void {
552552
this.#spawnInfoByChunk.add(spawn)
553553
}
554+
555+
/** Clears the spawn info */
556+
clearSpawnInfo(): void {
557+
this.#spawnInfoByChunk = new SpawnInfoByChunk([])
558+
}
554559
}

0 commit comments

Comments
 (0)