63 lines
1.9 KiB
TypeScript
63 lines
1.9 KiB
TypeScript
import { type World, type EntityId, type RunState, type Tile, type Actor, type Vec2 } from "./types";
|
|
import { idx } from "./world";
|
|
|
|
export function makeTestWorld(level: number, runState: RunState): { world: World; playerId: EntityId } {
|
|
const width = 30;
|
|
const height = 18;
|
|
const tiles: Tile[] = new Array(width * height).fill(0);
|
|
|
|
const fakeWorldForIdx: World = { width, height, tiles, actors: new Map(), exit: { x: 0, y: 0 } };
|
|
|
|
// Border walls
|
|
for (let x = 0; x < width; x++) {
|
|
tiles[idx(fakeWorldForIdx, x, 0)] = 1;
|
|
tiles[idx(fakeWorldForIdx, x, height - 1)] = 1;
|
|
}
|
|
for (let y = 0; y < height; y++) {
|
|
tiles[idx(fakeWorldForIdx, 0, y)] = 1;
|
|
tiles[idx(fakeWorldForIdx, width - 1, y)] = 1;
|
|
}
|
|
|
|
// Internal walls (vary slightly with level so it feels different)
|
|
const shift = level % 4;
|
|
for (let x = 6; x < 22; x++) tiles[idx(fakeWorldForIdx, x, 7 + (shift % 2))] = 1;
|
|
for (let y = 4; y < 14; y++) tiles[idx(fakeWorldForIdx, 14 + ((shift + 1) % 2), y)] = 1;
|
|
|
|
// Exit (stairs)
|
|
const exit: Vec2 = { x: width - 3, y: height - 3 };
|
|
tiles[idx(fakeWorldForIdx, exit.x, exit.y)] = 0;
|
|
|
|
const actors = new Map<EntityId, Actor>();
|
|
|
|
const playerId = 1;
|
|
actors.set(playerId, {
|
|
id: playerId,
|
|
isPlayer: true,
|
|
pos: { x: 3, y: 3 },
|
|
speed: 100,
|
|
energy: 0,
|
|
stats: { ...runState.stats },
|
|
inventory: { gold: runState.inventory.gold, items: [...runState.inventory.items] }
|
|
});
|
|
|
|
// Enemies
|
|
actors.set(2, {
|
|
id: 2,
|
|
isPlayer: false,
|
|
pos: { x: 24, y: 13 },
|
|
speed: 90,
|
|
energy: 0,
|
|
stats: { maxHp: 10, hp: 10, attack: 3, defense: 1 }
|
|
});
|
|
actors.set(3, {
|
|
id: 3,
|
|
isPlayer: false,
|
|
pos: { x: 20, y: 4 },
|
|
speed: 130,
|
|
energy: 0,
|
|
stats: { maxHp: 8, hp: 8, attack: 4, defense: 0 }
|
|
});
|
|
|
|
return { world: { width, height, tiles, actors, exit }, playerId };
|
|
}
|