attention-retro-disorder/src/scenes/LevelComplete.js

62 lines
2.3 KiB
JavaScript

export default class LevelComplete extends Phaser.Scene {
constructor() {
super({ key: 'LevelComplete' });
}
init(data) {
this.config = data.config;
this.level = data.level;
this.lives = data.lives;
this.hasNextLevel = data.hasNextLevel;
this.selectedGame = data.selectedGame ?? null;
}
create() {
const cx = 800, cy = 450;
this.add.text(cx, 300, `LEVEL ${this.level} COMPLETE!`, {
fontSize: '80px', fontFamily: 'monospace',
color: '#00ff00', stroke: '#005500', strokeThickness: 4,
}).setOrigin(0.5);
this.add.text(cx, 420, '♥ '.repeat(this.lives).trim(), {
fontSize: '48px', fontFamily: 'monospace', color: '#ff4444',
}).setOrigin(0.5);
if (this.hasNextLevel) {
this.add.text(cx, 530, `PREPARE FOR LEVEL ${this.level + 1}`, {
fontSize: '40px', fontFamily: 'monospace', color: '#ffff00',
}).setOrigin(0.5);
const prompt = this.add.text(cx, 650, 'PRESS SPACE OR CLICK TO CONTINUE', {
fontSize: '28px', fontFamily: 'monospace', color: '#ffffff',
}).setOrigin(0.5);
this.tweens.add({ targets: prompt, alpha: 0, duration: 600, yoyo: true, repeat: -1 });
this.input.keyboard.once('keydown-SPACE', () => this._nextLevel());
this.input.once('pointerdown', () => this._nextLevel());
} else {
this.add.text(cx, 530, 'YOU BEAT THE GAME!', {
fontSize: '48px', fontFamily: 'monospace', color: '#ffff00',
}).setOrigin(0.5);
const prompt = this.add.text(cx, 650, 'PRESS SPACE OR CLICK TO RESTART', {
fontSize: '28px', fontFamily: 'monospace', color: '#ffffff',
}).setOrigin(0.5);
this.tweens.add({ targets: prompt, alpha: 0, duration: 600, yoyo: true, repeat: -1 });
this.input.keyboard.once('keydown-SPACE', () => this.scene.start('MainMenu'));
this.input.once('pointerdown', () => this.scene.start('MainMenu'));
}
}
_nextLevel() {
this.scene.start('GameManager', {
config: this.config,
level: this.level + 1,
lives: this.lives,
selectedGame: this.selectedGame,
});
}
}