diff --git a/src/scenes/level.js b/src/scenes/level.js index 3cf7f55..42a1c93 100644 --- a/src/scenes/level.js +++ b/src/scenes/level.js @@ -111,8 +111,101 @@ export class Level extends Phaser.Scene { this.towerManager.update(time, delta); } - gameOver() { - console.log('GAME OVER'); + gameOver(type = 'defeat') { + 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() { diff --git a/src/scenes/menu.js b/src/scenes/menu.js index 1eb2152..8d8b822 100644 --- a/src/scenes/menu.js +++ b/src/scenes/menu.js @@ -195,7 +195,7 @@ export class Menu extends Phaser.Scene { const totalButtonArea = (buttonHeight + spacing) * 10 - spacing; // Total height for all buttons 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 buttonY = startY + (buttonHeight + spacing) * (i - 1); diff --git a/src/support/waveManager.js b/src/support/waveManager.js index 562ff82..f11cf2d 100644 --- a/src/support/waveManager.js +++ b/src/support/waveManager.js @@ -15,6 +15,7 @@ export class WaveManager { this.endY = WAVE_CONFIG[this.level].endY; this.path = null; this.levelActive = true; + this.postLevelTimer = 0; this.waveActive = false; 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() {