monsterplex/src/scenes/LevelFailedScene.js

47 lines
1.3 KiB
JavaScript

import Phaser from 'phaser';
import { GAME_WIDTH, GAME_HEIGHT, WORLD_SCALE } from '../config.js';
import { createButton } from '../util/ui.js';
const REASON_TEXT = {
'all-kids-lost': 'Every kid got thrown off the bus!',
'bus-fell': 'The bus fell into the gap!',
};
export default class LevelFailedScene extends Phaser.Scene {
constructor() {
super('LevelFailed');
}
init(data) {
this.levelId = data.levelId;
this.reason = data.reason;
}
create() {
this.cameras.main.setBackgroundColor('#c96a5a');
this.add.text(GAME_WIDTH / 2, 130 * WORLD_SCALE, 'LEVEL FAILED', {
fontFamily: 'monospace',
fontSize: `${36 * WORLD_SCALE}px`,
color: '#1a1f29',
fontStyle: 'bold',
}).setOrigin(0.5);
this.add.text(GAME_WIDTH / 2, 190 * WORLD_SCALE, REASON_TEXT[this.reason] || 'The bus didn\'t make it.', {
fontFamily: 'monospace',
fontSize: `${16 * WORLD_SCALE}px`,
color: '#1a1f29',
}).setOrigin(0.5);
const y = GAME_HEIGHT / 2 + 40 * WORLD_SCALE;
createButton(this, GAME_WIDTH / 2, y - 40 * WORLD_SCALE, 'RETRY', () => {
this.scene.start('Play', { levelId: this.levelId });
});
createButton(this, GAME_WIDTH / 2, y + 40 * WORLD_SCALE, 'LEVEL SELECT', () => {
this.scene.start('LevelSelect');
});
}
}