@erikyuzwa/rogue-punk
Version:
a JavaScript library to help you build your roguelike adventures
46 lines (45 loc) • 1.41 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Stage = void 0;
const ROT = require("rot-js");
class Stage {
constructor(options) {
this.options = Object.assign({}, options);
this.width = options.width || 60;
this.height = options.height || 30;
this.id = options.id || 'stage';
this.display = new ROT.Display(this.options);
this.displayContainer = null;
this.cameraTarget = null;
this.center = null;
this.setDimensions(this.width, this.height);
this.attachToElement();
}
setDimensions(x, y) {
this.width = x;
this.height = y;
this.center.x = Math.round(x / 2);
this.center.y = Math.round(y / 2);
}
attachToElement() {
this.displayContainer = document.getElementById(this.id);
this.displayContainer.appendChild(this.display.getContainer());
}
getDisplay() {
return this.display;
}
clear() {
this.display.clear();
}
setCameraTarget(cameraTarget) {
this.cameraTarget = cameraTarget;
}
draw(x, y, glyph, fgColor, bgColor) {
if (this.cameraTarget) {
x += (this.center.x - this.cameraTarget.x);
y += (this.center.y - this.cameraTarget.y);
}
return this.display.draw(x, y, glyph, fgColor, bgColor);
}
}
exports.Stage = Stage;