Phase 3: World generation — procedural tilemap for Catalytic Wastes

- simplex-noise with seeded PRNG (mulberry32) for deterministic generation
- Biome data: 8 tile types (scorched earth, cracked ground, ash sand,
  acid pools, acid shallow, crystals, geysers, mineral veins)
- Elevation noise → base terrain; detail noise → geyser/mineral overlays
- Canvas-based tileset with per-pixel brightness variation
- Phaser tilemap with collision on non-walkable tiles
- Camera: WASD movement, mouse wheel zoom (0.5x–3x), world bounds
- Minimap: 160x160 canvas overview with viewport indicator
- 21 world generation tests passing (95 total)

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Денис Шкабатур
2026-02-12 12:47:21 +03:00
parent ddbca12740
commit bc472d0f77
12 changed files with 749 additions and 62 deletions

View File

@@ -1,91 +1,83 @@
import Phaser from 'phaser';
import { createGameWorld, updateTime, type GameWorld } from '../ecs/world';
import { movementSystem, bounceSystem } from '../ecs/systems/movement';
import { movementSystem } from '../ecs/systems/movement';
import { healthSystem } from '../ecs/systems/health';
import { createGameEntity, removeGameEntity } from '../ecs/factory';
import { removeGameEntity } from '../ecs/factory';
import { PhaserBridge } from '../ecs/bridge';
import { GAME_WIDTH, GAME_HEIGHT } from '../config';
const ENTITY_COUNT = 20;
const COLORS = [
0x00ff88, 0xff0044, 0x44aaff, 0xffaa00,
0xff44ff, 0x44ffaa, 0xffff44, 0xaa44ff,
];
import biomeDataArray from '../data/biomes.json';
import type { BiomeData } from '../world/types';
import { generateWorld } from '../world/generator';
import { createWorldTilemap } from '../world/tilemap';
import { setupCamera, updateCamera, type CameraKeys } from '../world/camera';
import { Minimap } from '../world/minimap';
export class GameScene extends Phaser.Scene {
private gameWorld!: GameWorld;
private bridge!: PhaserBridge;
private cameraKeys!: CameraKeys;
private minimap!: Minimap;
private statsText!: Phaser.GameObjects.Text;
private worldSeed!: number;
constructor() {
super({ key: 'GameScene' });
}
create(): void {
// 1. Initialize ECS
// 1. Initialize ECS (needed for future entity systems)
this.gameWorld = createGameWorld();
this.bridge = new PhaserBridge(this);
// 2. Spawn bouncing circles with random properties
for (let i = 0; i < ENTITY_COUNT; i++) {
const speed = 50 + Math.random() * 150;
const angle = Math.random() * Math.PI * 2;
// 2. Generate world
const biome = biomeDataArray[0] as BiomeData;
this.worldSeed = Date.now() % 1000000;
const worldData = generateWorld(biome, this.worldSeed);
createGameEntity(this.gameWorld.world, {
position: {
x: 100 + Math.random() * (GAME_WIDTH - 200),
y: 100 + Math.random() * (GAME_HEIGHT - 200),
},
velocity: {
vx: Math.cos(angle) * speed,
vy: Math.sin(angle) * speed,
},
sprite: {
color: COLORS[i % COLORS.length],
radius: 6 + Math.random() * 14,
},
health: {
current: 100,
max: 100,
},
});
}
// 3. Create tilemap
createWorldTilemap(this, worldData);
// 3. UI labels
this.add.text(10, 10, 'Phase 2: ECS Foundation', {
fontSize: '14px',
// 4. Camera with bounds and WASD controls
const worldPixelW = biome.mapWidth * biome.tileSize;
const worldPixelH = biome.mapHeight * biome.tileSize;
this.cameraKeys = setupCamera(this, worldPixelW, worldPixelH);
// 5. Minimap
this.minimap = new Minimap(this, worldData);
// 6. UI overlay
this.statsText = this.add.text(10, 10, '', {
fontSize: '12px',
color: '#00ff88',
fontFamily: 'monospace',
backgroundColor: '#000000aa',
padding: { x: 4, y: 2 },
});
this.statsText = this.add.text(10, 30, '', {
fontSize: '12px',
color: '#557755',
fontFamily: 'monospace',
});
this.statsText.setScrollFactor(0);
this.statsText.setDepth(100);
}
update(_time: number, delta: number): void {
// 1. Update world time
updateTime(this.gameWorld, delta);
// 2. Run systems
movementSystem(this.gameWorld.world, delta);
bounceSystem(this.gameWorld.world, GAME_WIDTH, GAME_HEIGHT);
// 2. Camera movement
updateCamera(this, this.cameraKeys, delta);
// 3. Health check + cleanup
// 3. ECS systems (no entities yet — future phases will add player, creatures)
movementSystem(this.gameWorld.world, delta);
const dead = healthSystem(this.gameWorld.world);
for (const eid of dead) {
removeGameEntity(this.gameWorld.world, eid);
}
// 4. Sync to Phaser
this.bridge.sync(this.gameWorld.world);
// 5. Update stats
// 4. Minimap viewport
this.minimap.update(this.cameras.main);
// 5. Stats
const fps = delta > 0 ? Math.round(1000 / delta) : 0;
this.statsText.setText(
`${this.bridge.entityCount} entities | tick ${this.gameWorld.time.tick} | ${fps} fps`,
`seed: ${this.worldSeed} | ${fps} fps | WASD move, scroll zoom`,
);
}
}