Newer
Older
rpg / apps / game / src / main.ts
import { Engine, computeScale, ensurePixelFont, type EngineOptions } from '@rpg/engine';
import { Game } from './Game';
import { BootScene } from './scenes/BootScene';

async function main(): Promise<void> {
    const container = document.getElementById('game')!;

    const options: EngineOptions = {
        virtualWidth: Game.VIRTUAL_W,
        virtualHeight: Game.VIRTUAL_H,
        scale: computeScale(Game.VIRTUAL_W, Game.VIRTUAL_H, window.innerWidth, window.innerHeight),
        background: 0x0b0b12,
        fixedFps: 60,
        parent: container
    };

    const engine = new Engine(options);
    await engine.init();
    engine.input.bindActions({
        advance: ['Space', 'Enter'],
        menu: ['Escape'],
        up: ['KeyW', 'ArrowUp'],
        down: ['KeyS', 'ArrowDown']
    });
    engine.input.bindGamepad({
        advance: [0], // A
        menu: [9], // Start
        up: [12],
        down: [13]
    });

    // Пиксельный шрифт движка (VT323): до первого текста; фолбэк monospace безопасен.
    void ensurePixelFont(Game.FONT_URL);

    const game = new Game(engine);
    await engine.scenes.push(new BootScene(game));
    await engine.start();
}

void main();