59 lines
1.6 KiB
JavaScript
59 lines
1.6 KiB
JavaScript
const Phaser = require('phaser');
|
|
|
|
const { TEXT } = require('./constants');
|
|
|
|
const ROW_WIDTH = 400;
|
|
const ROW_HEIGHT = 200;
|
|
const ROW_FILL = 0x888888;
|
|
|
|
const TOP_MARGIN = 50;
|
|
const ROW_MARGIN = 50;
|
|
const TEXT_MARGIN = 24;
|
|
|
|
const KEY_MAP = [
|
|
'keydown_ONE',
|
|
'keydown_TWO',
|
|
'keydown_THREE',
|
|
];
|
|
|
|
const xPos = i => 0;
|
|
const yPos = i => (i * ROW_HEIGHT + ROW_MARGIN) + TOP_MARGIN;
|
|
|
|
class CrypRow extends Phaser.GameObjects.Group {
|
|
constructor(list, cryps) {
|
|
super(list);
|
|
this.keyboard = list.input.keyboard;
|
|
cryps.forEach((cryp, i) => {
|
|
const X_ORIGIN = xPos(i);
|
|
const Y_ORIGIN = yPos(i);
|
|
|
|
// only draw for active cryps
|
|
if (cryp.active) {
|
|
const row = list.add
|
|
.rectangle(X_ORIGIN, Y_ORIGIN, ROW_WIDTH, ROW_HEIGHT, ROW_FILL * Math.random())
|
|
.setInteractive()
|
|
.setOrigin(0);
|
|
this.add(row);
|
|
row.cryp = cryp;
|
|
}
|
|
|
|
if (KEY_MAP[i]) {
|
|
this.keyboard.on(KEY_MAP[i], () => {
|
|
list.game.events.emit('CRYP_ACTIVE', cryp);
|
|
}, this);
|
|
}
|
|
|
|
this.add(list.add.text(X_ORIGIN, Y_ORIGIN + (TEXT_MARGIN * 0), cryp.name, TEXT.HEADER));
|
|
this.add(list.add.text(ROW_WIDTH - 20, Y_ORIGIN + (TEXT_MARGIN * 0), i + 1, TEXT.HEADER));
|
|
this.add(list.add.text(X_ORIGIN, Y_ORIGIN + (TEXT_MARGIN * 1), cryp.stamina.base, TEXT.NORMAL));
|
|
});
|
|
return true;
|
|
}
|
|
|
|
cleanup() {
|
|
KEY_MAP.forEach(k => this.keyboard.removeListener(k));
|
|
}
|
|
}
|
|
|
|
module.exports = CrypRow;
|