UNPKG

@erikyuzwa/rogue-punk

Version:

a JavaScript library to help you build your roguelike adventures

38 lines (37 loc) 965 B
import { Stage } from './Stage'; export class Engine { constructor(options) { this.stage = new 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(); } } }