diff --git a/assets/alarm.mp3 b/assets/alarm.mp3 index 988cc6d..06458e9 100644 Binary files a/assets/alarm.mp3 and b/assets/alarm.mp3 differ diff --git a/src/GameScene.js b/src/GameScene.js index 8b11ac0..5a3d7a7 100644 --- a/src/GameScene.js +++ b/src/GameScene.js @@ -21,6 +21,7 @@ export class GameScene extends Phaser.Scene { this.score = 0; this.ally = 'goblin'; this.spritePlus = 0; + this.gridColor = 0x000000; // Status Indication this.isDropping = false; @@ -30,6 +31,7 @@ export class GameScene extends Phaser.Scene { this.isPlayingVideo = false; this.isPlayingAudio = false; this.gameStatus = true; + this.rowOne = false; // Add selectedJewel property this.selectedJewel = null; @@ -89,6 +91,7 @@ export class GameScene extends Phaser.Scene { this.moveInterval = newLevel.moveInterval; this.ally = newLevel.ally; this.spritePlus = newLevel.spritePlus; + this.gridColor = newLevel.gridColor; // Background Video this.bgVideo = this.add.video(0, 0, `${this.ally}-background`); @@ -96,11 +99,10 @@ export class GameScene extends Phaser.Scene { console.log("width",this.scale.width); this.bgVideo.scaleX = this.scale.width / 848; this.bgVideo.scaleY = this.scale.height / 480; - console.log(this.bgVideo); this.bgVideo.play(true); // Create the Game Grid - this.makeGrid(); + this.makeGrid(this.gridColor); this.physics.world.setBounds(this.grid.getBounds().x - 50, this.grid.getBounds().y - 50, this.grid.getBounds().width + 100, this.grid.getBounds().height + 100); this.jewels = this.physics.add.group({ collideWorldBounds: true, @@ -217,13 +219,13 @@ export class GameScene extends Phaser.Scene { }); } - makeGrid() { + makeGrid(gridColor = 0x000000) { this.grid = this.add.rectangle( this.gridConfig.leftPadding + this.gridConfig.allPadding, 0 + this.gridConfig.allPadding, this.gridConfig.cols * this.gridConfig.jewelWidth, this.gridConfig.rows*this.gridConfig.jewelHeight, - 0x000000, + gridColor, .5 ).setOrigin(0); this.grid.setInteractive(); @@ -555,6 +557,7 @@ export class GameScene extends Phaser.Scene { // Function to check for matches and destroy them checkMatches() { + this.checkWarning(); const matchedJewels = new Set(); // Check horizontal matches @@ -812,7 +815,7 @@ export class GameScene extends Phaser.Scene { // When all jewels have dropped, check for new matches if (droppedCount === jewelsToDrop.length) { - this.time.delayedCall(100, () => { + this.time.delayedCall(200, () => { this.isDropping = false; // Check for new matches after dropping this.checkMatches(); @@ -873,6 +876,7 @@ export class GameScene extends Phaser.Scene { this.time.delayedCall(300, () => { this.isMovingUp = false; this.createBottomRow(); + this.checkWarning(); }); } @@ -1016,16 +1020,61 @@ export class GameScene extends Phaser.Scene { } } + checkWarning() { + // Check if there are any jewels in row 1 (topmost row) + let hasJewelsInRow1 = false; + + this.time.delayedCall(500, () => { + this.jewels.children.iterate((jewel) => { + if (jewel) { + const col = Math.floor((jewel.x - this.gridConfig.leftPadding) / this.gridConfig.jewelWidth); + const row = Math.floor(jewel.y / this.gridConfig.jewelHeight); + + // If jewel is in row 1, set the flag to true + if (row === 1 && col >= 1 && col <= this.gridConfig.cols) { + hasJewelsInRow1 = true; + return false; // Stop iteration once we find one + } + } + }); + + if (this.rowOne === true && hasJewelsInRow1 === false) { + this.rowOne = false; + this.grid.setFillStyle(this.gridColor).setAlpha(0.5); + this.alarm.stop(); + this.alarmFlash.remove(); + this.alarmFlash = null; + } else if (this.rowOne === false && hasJewelsInRow1) { + console.log('in row one'); + this.rowOne = true; + this.alarm = this.sound.add('alarm', { loop: true, volume: 1 }); + this.alarm.play(); + this.alarmFlash = this.tweens.add({ + targets: this.grid, + fillColor: 0xFF0000, + duration: 3000, + alpha: .7, + ease: 'Linear', + yoyo: true, + repeat: -1 + }); + } + }); + } + levelUp() { this.level ++; const newLevel = LEVEL_CONFIG[this.level]; this.numberOfJewels = newLevel.numberOfJewels; this.matchesNeeded = newLevel.matchesNeeded; this.moveInterval = newLevel.moveInterval; + this.gridColor = newLevel.gridColor; this.LevelText.setText(`Level: ${this.level}`); this.sound.play('level-up'); this.sound.play('level-complete'); + this.grid.setFillStyle(newLevel.gridColor).setAlpha(0.5); + if (this.ally !== newLevel.ally) { this.sound.play(`${this.ally}-outro`); this.time.delayedCall(1000, () => { @@ -1080,6 +1129,11 @@ export class GameScene extends Phaser.Scene { console.log('Game Over!'); this.gameStatus = false; this.sound.play('game-over'); + this.rowOne = false; + this.grid.setFillStyle(this.gridColor).setAlpha(0.5); + this.alarm.stop(); + this.alarmFlash.remove(); + this.alarmFlash = null; // Make all jewels bounce off screen this.jewels.children.iterate((jewel) => { diff --git a/src/config.js b/src/config.js index 4b30383..7fe813a 100644 --- a/src/config.js +++ b/src/config.js @@ -4,83 +4,95 @@ export const LEVEL_CONFIG = { matchesNeeded: 8, moveInterval: 12000, ally: 'goblin', - spritePlus: 0 + spritePlus: 0, + gridColor: 0x000000 }, 2: { numberOfJewels: 5, matchesNeeded: 8, moveInterval: 12000, ally: 'goblin', - spritePlus: 0 + spritePlus: 0, + gridColor: 0x000000 }, 3: { numberOfJewels: 5, matchesNeeded: 9, moveInterval: 11000, ally: 'goblin', - spritePlus: 0 + spritePlus: 0, + gridColor: 0x000000 }, 4: { numberOfJewels: 5, matchesNeeded: 10, moveInterval: 10000, ally: 'goblin', - spritePlus: 0 + spritePlus: 0, + gridColor: 0x000000 }, 5: { numberOfJewels: 5, matchesNeeded: 10, moveInterval: 10000, ally: 'surfer', - spritePlus: 5 + spritePlus: 5, + gridColor: 0xFFFFFF }, 6: { numberOfJewels: 6, matchesNeeded: 10, moveInterval: 10000, ally: 'surfer', - spritePlus: 5 + spritePlus: 5, + gridColor: 0xFFFFFF }, 7: { numberOfJewels: 6, matchesNeeded: 10, moveInterval: 9500, ally: 'surfer', - spritePlus: 5 + spritePlus: 5, + gridColor: 0xFFFFFF }, 8: { numberOfJewels: 6, matchesNeeded: 10, moveInterval: 9000, ally: 'surfer', - spritePlus: 5 + spritePlus: 5, + gridColor: 0xff6000 }, 9: { numberOfJewels: 6, matchesNeeded: 10, moveInterval: 9000, ally: 'bear', - spritePlus: 11 + spritePlus: 11, + gridColor: 0xFFFFFF }, 10: { numberOfJewels: 7, matchesNeeded: 10, moveInterval: 9000, ally: 'bear', - spritePlus: 11 + spritePlus: 11, + gridColor: 0xFFFFFF }, 11: { numberOfJewels: 6, matchesNeeded: 9, moveInterval: 8500, ally: 'bear', - spritePlus: 11 + spritePlus: 11, + gridColor: 0xFFFFFF }, 12: { numberOfJewels: 6, matchesNeeded: 8, moveInterval: 7000, ally: 'bear', - spritePlus: 11 + spritePlus: 11, + gridColor: 0xFFFFFF } };