UNPKG

@erikyuzwa/rogue-punk

Version:

a JavaScript library to help you build your roguelike adventures

42 lines (41 loc) 1.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Engine = void 0; const Stage_1 = require("./Stage"); class Engine { constructor(options) { this.stage = new Stage_1.Stage(options); this.init(); } init() { const engine = this; const bindEventToScreen = ((event) => { window.addEventListener(event, (e) => { if (engine.currentWorld) { engine.currentWorld.handleInput(event, e); } }, false); }); bindEventToScreen('keydown'); } getStage() { return this.stage; } refresh() { this.stage.clear(); if (this.currentWorld) { this.currentWorld.render(this.stage.getDisplay()); } } switchWorld(newWorld) { if (this.currentWorld) { this.currentWorld.end(); } this.currentWorld = newWorld; if (this.currentWorld) { this.currentWorld.begin(); this.refresh(); } } } exports.Engine = Engine;