feat: Implement win/lose conditions with animated game over screens and reduce level selection to 4 levels

- Added win/lose game over screens with animated text effects and fade transitions
- Implemented victory condition detection after wave completion with 5 second delay
- Reduced level selection menu from 10 to 4 levels
- Added post-level timer logic for win condition verification
This commit is contained in:
Brian Fertig 2025-09-09 19:41:41 -06:00
parent df10eb1abe
commit 567376f8e9
3 changed files with 107 additions and 3 deletions

View File

@ -111,8 +111,101 @@ export class Level extends Phaser.Scene {
this.towerManager.update(time, delta); this.towerManager.update(time, delta);
} }
gameOver() { gameOver(type = 'defeat') {
console.log('GAME OVER'); if (type === 'win') {
const winText1 = this.add.text(800, 300, `Congratulations!`, {
fontFamily: 'neuropol, arial',
fontSize: '128px',
fill: '#ffd900ff',
stroke: '#c48f00ff',
strokeThickness: 2,
shadow: {
offsetX: 5,
offsetY: 5,
color: '#000000',
blur: 5,
stroke: false,
fill: true
}
}).setOrigin(0.5).setScrollFactor(0).setAlpha(0);
const winText2 = this.add.text(800, 450, `You have defeated the alien invasion!`, {
fontFamily: 'neuropol, arial',
fontSize: '56px',
fill: '#ffd900ff',
stroke: '#c48f00ff',
strokeThickness: 2,
shadow: {
offsetX: 5,
offsetY: 5,
color: '#000000',
blur: 5,
stroke: false,
fill: true
}
}).setOrigin(0.5).setScrollFactor(0).setAlpha(0);
this.tweens.add({
targets: [winText1, winText2],
alpha: 1,
duration: 6000,
ease: 'Bounce',
onComplete: () => {
this.UIScene.scene.stop();
this.cameras.main.fadeOut();
this.bgMusic.stop();
this.time.delayedCall(5000, () => {
this.scene.stop();
this.scene.start('Menu');
});
}
});
}
if (type === 'defeat') {
const winText1 = this.add.text(800, 300, `Defeat!`, {
fontFamily: 'neuropol, arial',
fontSize: '128px',
fill: '#ff0062ff',
stroke: '#5e182fff',
strokeThickness: 2,
shadow: {
offsetX: 5,
offsetY: 5,
color: '#000000',
blur: 5,
stroke: false,
fill: true
}
}).setOrigin(0.5).setScrollFactor(0).setAlpha(0);
const winText2 = this.add.text(800, 450, `The aliens have destroyed your Power Core!`, {
fontFamily: 'neuropol, arial',
fontSize: '56px',
fill: '#ff0062ff',
stroke: '#5e182fff',
strokeThickness: 2,
shadow: {
offsetX: 5,
offsetY: 5,
color: '#000000',
blur: 5,
stroke: false,
fill: true
}
}).setOrigin(0.5).setScrollFactor(0).setAlpha(0);
this.tweens.add({
targets: [winText1, winText2],
alpha: 1,
duration: 6000,
ease: 'Bounce',
onComplete: () => {
this.UIScene.scene.stop();
this.cameras.main.fadeOut();
this.bgMusic.stop();
this.time.delayedCall(5000, () => {
this.scene.stop();
this.scene.start('Menu');
});
}
});
}
} }
addControls() { addControls() {

View File

@ -195,7 +195,7 @@ export class Menu extends Phaser.Scene {
const totalButtonArea = (buttonHeight + spacing) * 10 - spacing; // Total height for all buttons const totalButtonArea = (buttonHeight + spacing) * 10 - spacing; // Total height for all buttons
const startY = levelSelectY + (levelSelectHeight - totalButtonArea) / 2; const startY = levelSelectY + (levelSelectHeight - totalButtonArea) / 2;
for (let i = 1; i <= 10; i++) { for (let i = 1; i <= 4; i++) {
const buttonX = levelSelectX + 20; const buttonX = levelSelectX + 20;
const buttonY = startY + (buttonHeight + spacing) * (i - 1); const buttonY = startY + (buttonHeight + spacing) * (i - 1);

View File

@ -15,6 +15,7 @@ export class WaveManager {
this.endY = WAVE_CONFIG[this.level].endY; this.endY = WAVE_CONFIG[this.level].endY;
this.path = null; this.path = null;
this.levelActive = true; this.levelActive = true;
this.postLevelTimer = 0;
this.waveActive = false; this.waveActive = false;
this.waveTimer = 0; this.waveTimer = 0;
@ -170,6 +171,16 @@ export class WaveManager {
} }
}); });
} }
if (this.levelActive === false) {
this.postLevelTimer += delta;
if (this.postLevelTimer >= 5000) {
this.postLevelTimer = 0;
if (this.scene.enemies.children.entries.length === 0) {
this.scene.gameOver('win');
}
}
}
} }
spawnSchedule() { spawnSchedule() {