Updates
This commit is contained in:
parent
17f3a0f728
commit
49b4ca8e5e
BIN
assets/alarm.mp3
BIN
assets/alarm.mp3
Binary file not shown.
|
|
@ -21,6 +21,7 @@ export class GameScene extends Phaser.Scene {
|
||||||
this.score = 0;
|
this.score = 0;
|
||||||
this.ally = 'goblin';
|
this.ally = 'goblin';
|
||||||
this.spritePlus = 0;
|
this.spritePlus = 0;
|
||||||
|
this.gridColor = 0x000000;
|
||||||
|
|
||||||
// Status Indication
|
// Status Indication
|
||||||
this.isDropping = false;
|
this.isDropping = false;
|
||||||
|
|
@ -30,6 +31,7 @@ export class GameScene extends Phaser.Scene {
|
||||||
this.isPlayingVideo = false;
|
this.isPlayingVideo = false;
|
||||||
this.isPlayingAudio = false;
|
this.isPlayingAudio = false;
|
||||||
this.gameStatus = true;
|
this.gameStatus = true;
|
||||||
|
this.rowOne = false;
|
||||||
|
|
||||||
// Add selectedJewel property
|
// Add selectedJewel property
|
||||||
this.selectedJewel = null;
|
this.selectedJewel = null;
|
||||||
|
|
@ -89,6 +91,7 @@ export class GameScene extends Phaser.Scene {
|
||||||
this.moveInterval = newLevel.moveInterval;
|
this.moveInterval = newLevel.moveInterval;
|
||||||
this.ally = newLevel.ally;
|
this.ally = newLevel.ally;
|
||||||
this.spritePlus = newLevel.spritePlus;
|
this.spritePlus = newLevel.spritePlus;
|
||||||
|
this.gridColor = newLevel.gridColor;
|
||||||
|
|
||||||
// Background Video
|
// Background Video
|
||||||
this.bgVideo = this.add.video(0, 0, `${this.ally}-background`);
|
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);
|
console.log("width",this.scale.width);
|
||||||
this.bgVideo.scaleX = this.scale.width / 848;
|
this.bgVideo.scaleX = this.scale.width / 848;
|
||||||
this.bgVideo.scaleY = this.scale.height / 480;
|
this.bgVideo.scaleY = this.scale.height / 480;
|
||||||
console.log(this.bgVideo);
|
|
||||||
this.bgVideo.play(true);
|
this.bgVideo.play(true);
|
||||||
|
|
||||||
// Create the Game Grid
|
// 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.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({
|
this.jewels = this.physics.add.group({
|
||||||
collideWorldBounds: true,
|
collideWorldBounds: true,
|
||||||
|
|
@ -217,13 +219,13 @@ export class GameScene extends Phaser.Scene {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
makeGrid() {
|
makeGrid(gridColor = 0x000000) {
|
||||||
this.grid = this.add.rectangle(
|
this.grid = this.add.rectangle(
|
||||||
this.gridConfig.leftPadding + this.gridConfig.allPadding,
|
this.gridConfig.leftPadding + this.gridConfig.allPadding,
|
||||||
0 + this.gridConfig.allPadding,
|
0 + this.gridConfig.allPadding,
|
||||||
this.gridConfig.cols * this.gridConfig.jewelWidth,
|
this.gridConfig.cols * this.gridConfig.jewelWidth,
|
||||||
this.gridConfig.rows*this.gridConfig.jewelHeight,
|
this.gridConfig.rows*this.gridConfig.jewelHeight,
|
||||||
0x000000,
|
gridColor,
|
||||||
.5
|
.5
|
||||||
).setOrigin(0);
|
).setOrigin(0);
|
||||||
this.grid.setInteractive();
|
this.grid.setInteractive();
|
||||||
|
|
@ -555,6 +557,7 @@ export class GameScene extends Phaser.Scene {
|
||||||
|
|
||||||
// Function to check for matches and destroy them
|
// Function to check for matches and destroy them
|
||||||
checkMatches() {
|
checkMatches() {
|
||||||
|
this.checkWarning();
|
||||||
const matchedJewels = new Set();
|
const matchedJewels = new Set();
|
||||||
|
|
||||||
// Check horizontal matches
|
// Check horizontal matches
|
||||||
|
|
@ -812,7 +815,7 @@ export class GameScene extends Phaser.Scene {
|
||||||
|
|
||||||
// When all jewels have dropped, check for new matches
|
// When all jewels have dropped, check for new matches
|
||||||
if (droppedCount === jewelsToDrop.length) {
|
if (droppedCount === jewelsToDrop.length) {
|
||||||
this.time.delayedCall(100, () => {
|
this.time.delayedCall(200, () => {
|
||||||
this.isDropping = false;
|
this.isDropping = false;
|
||||||
// Check for new matches after dropping
|
// Check for new matches after dropping
|
||||||
this.checkMatches();
|
this.checkMatches();
|
||||||
|
|
@ -873,6 +876,7 @@ export class GameScene extends Phaser.Scene {
|
||||||
this.time.delayedCall(300, () => {
|
this.time.delayedCall(300, () => {
|
||||||
this.isMovingUp = false;
|
this.isMovingUp = false;
|
||||||
this.createBottomRow();
|
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() {
|
levelUp() {
|
||||||
this.level ++;
|
this.level ++;
|
||||||
const newLevel = LEVEL_CONFIG[this.level];
|
const newLevel = LEVEL_CONFIG[this.level];
|
||||||
this.numberOfJewels = newLevel.numberOfJewels;
|
this.numberOfJewels = newLevel.numberOfJewels;
|
||||||
this.matchesNeeded = newLevel.matchesNeeded;
|
this.matchesNeeded = newLevel.matchesNeeded;
|
||||||
this.moveInterval = newLevel.moveInterval;
|
this.moveInterval = newLevel.moveInterval;
|
||||||
|
this.gridColor = newLevel.gridColor;
|
||||||
this.LevelText.setText(`Level: ${this.level}`);
|
this.LevelText.setText(`Level: ${this.level}`);
|
||||||
this.sound.play('level-up');
|
this.sound.play('level-up');
|
||||||
this.sound.play('level-complete');
|
this.sound.play('level-complete');
|
||||||
|
|
||||||
|
this.grid.setFillStyle(newLevel.gridColor).setAlpha(0.5);
|
||||||
|
|
||||||
if (this.ally !== newLevel.ally) {
|
if (this.ally !== newLevel.ally) {
|
||||||
this.sound.play(`${this.ally}-outro`);
|
this.sound.play(`${this.ally}-outro`);
|
||||||
this.time.delayedCall(1000, () => {
|
this.time.delayedCall(1000, () => {
|
||||||
|
|
@ -1080,6 +1129,11 @@ export class GameScene extends Phaser.Scene {
|
||||||
console.log('Game Over!');
|
console.log('Game Over!');
|
||||||
this.gameStatus = false;
|
this.gameStatus = false;
|
||||||
this.sound.play('game-over');
|
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
|
// Make all jewels bounce off screen
|
||||||
this.jewels.children.iterate((jewel) => {
|
this.jewels.children.iterate((jewel) => {
|
||||||
|
|
|
||||||
|
|
@ -4,83 +4,95 @@ export const LEVEL_CONFIG = {
|
||||||
matchesNeeded: 8,
|
matchesNeeded: 8,
|
||||||
moveInterval: 12000,
|
moveInterval: 12000,
|
||||||
ally: 'goblin',
|
ally: 'goblin',
|
||||||
spritePlus: 0
|
spritePlus: 0,
|
||||||
|
gridColor: 0x000000
|
||||||
},
|
},
|
||||||
2: {
|
2: {
|
||||||
numberOfJewels: 5,
|
numberOfJewels: 5,
|
||||||
matchesNeeded: 8,
|
matchesNeeded: 8,
|
||||||
moveInterval: 12000,
|
moveInterval: 12000,
|
||||||
ally: 'goblin',
|
ally: 'goblin',
|
||||||
spritePlus: 0
|
spritePlus: 0,
|
||||||
|
gridColor: 0x000000
|
||||||
},
|
},
|
||||||
3: {
|
3: {
|
||||||
numberOfJewels: 5,
|
numberOfJewels: 5,
|
||||||
matchesNeeded: 9,
|
matchesNeeded: 9,
|
||||||
moveInterval: 11000,
|
moveInterval: 11000,
|
||||||
ally: 'goblin',
|
ally: 'goblin',
|
||||||
spritePlus: 0
|
spritePlus: 0,
|
||||||
|
gridColor: 0x000000
|
||||||
},
|
},
|
||||||
4: {
|
4: {
|
||||||
numberOfJewels: 5,
|
numberOfJewels: 5,
|
||||||
matchesNeeded: 10,
|
matchesNeeded: 10,
|
||||||
moveInterval: 10000,
|
moveInterval: 10000,
|
||||||
ally: 'goblin',
|
ally: 'goblin',
|
||||||
spritePlus: 0
|
spritePlus: 0,
|
||||||
|
gridColor: 0x000000
|
||||||
},
|
},
|
||||||
5: {
|
5: {
|
||||||
numberOfJewels: 5,
|
numberOfJewels: 5,
|
||||||
matchesNeeded: 10,
|
matchesNeeded: 10,
|
||||||
moveInterval: 10000,
|
moveInterval: 10000,
|
||||||
ally: 'surfer',
|
ally: 'surfer',
|
||||||
spritePlus: 5
|
spritePlus: 5,
|
||||||
|
gridColor: 0xFFFFFF
|
||||||
},
|
},
|
||||||
6: {
|
6: {
|
||||||
numberOfJewels: 6,
|
numberOfJewels: 6,
|
||||||
matchesNeeded: 10,
|
matchesNeeded: 10,
|
||||||
moveInterval: 10000,
|
moveInterval: 10000,
|
||||||
ally: 'surfer',
|
ally: 'surfer',
|
||||||
spritePlus: 5
|
spritePlus: 5,
|
||||||
|
gridColor: 0xFFFFFF
|
||||||
},
|
},
|
||||||
7: {
|
7: {
|
||||||
numberOfJewels: 6,
|
numberOfJewels: 6,
|
||||||
matchesNeeded: 10,
|
matchesNeeded: 10,
|
||||||
moveInterval: 9500,
|
moveInterval: 9500,
|
||||||
ally: 'surfer',
|
ally: 'surfer',
|
||||||
spritePlus: 5
|
spritePlus: 5,
|
||||||
|
gridColor: 0xFFFFFF
|
||||||
},
|
},
|
||||||
8: {
|
8: {
|
||||||
numberOfJewels: 6,
|
numberOfJewels: 6,
|
||||||
matchesNeeded: 10,
|
matchesNeeded: 10,
|
||||||
moveInterval: 9000,
|
moveInterval: 9000,
|
||||||
ally: 'surfer',
|
ally: 'surfer',
|
||||||
spritePlus: 5
|
spritePlus: 5,
|
||||||
|
gridColor: 0xff6000
|
||||||
},
|
},
|
||||||
9: {
|
9: {
|
||||||
numberOfJewels: 6,
|
numberOfJewels: 6,
|
||||||
matchesNeeded: 10,
|
matchesNeeded: 10,
|
||||||
moveInterval: 9000,
|
moveInterval: 9000,
|
||||||
ally: 'bear',
|
ally: 'bear',
|
||||||
spritePlus: 11
|
spritePlus: 11,
|
||||||
|
gridColor: 0xFFFFFF
|
||||||
},
|
},
|
||||||
10: {
|
10: {
|
||||||
numberOfJewels: 7,
|
numberOfJewels: 7,
|
||||||
matchesNeeded: 10,
|
matchesNeeded: 10,
|
||||||
moveInterval: 9000,
|
moveInterval: 9000,
|
||||||
ally: 'bear',
|
ally: 'bear',
|
||||||
spritePlus: 11
|
spritePlus: 11,
|
||||||
|
gridColor: 0xFFFFFF
|
||||||
},
|
},
|
||||||
11: {
|
11: {
|
||||||
numberOfJewels: 6,
|
numberOfJewels: 6,
|
||||||
matchesNeeded: 9,
|
matchesNeeded: 9,
|
||||||
moveInterval: 8500,
|
moveInterval: 8500,
|
||||||
ally: 'bear',
|
ally: 'bear',
|
||||||
spritePlus: 11
|
spritePlus: 11,
|
||||||
|
gridColor: 0xFFFFFF
|
||||||
},
|
},
|
||||||
12: {
|
12: {
|
||||||
numberOfJewels: 6,
|
numberOfJewels: 6,
|
||||||
matchesNeeded: 8,
|
matchesNeeded: 8,
|
||||||
moveInterval: 7000,
|
moveInterval: 7000,
|
||||||
ally: 'bear',
|
ally: 'bear',
|
||||||
spritePlus: 11
|
spritePlus: 11,
|
||||||
|
gridColor: 0xFFFFFF
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue