GitLab system status is available here and here

Commit 209fbce1 authored by Aaron Gonzales's avatar Aaron Gonzales
Browse files

Added sound effects and score tracking

parent 3dd18ae8
......@@ -7,6 +7,7 @@ class Rocket extends Phaser.GameObjects.Sprite {
scene.add.existing(this);
this.isFiring = false;
this.moveSpeed = 2;
this.sfxRocket = scene.sound.add('sfx_rocket'); // add rocket sfx
}
update() {
......@@ -20,8 +21,9 @@ class Rocket extends Phaser.GameObjects.Sprite {
}
// Firing
if (Phaser.Input.Keyboard.JustDown(keyF)) {
if (Phaser.Input.Keyboard.JustDown(keyF) && !this.isFiring) {
this.isFiring = true;
this.sfxRocket.play();
}
// If fired, move sprite upward
......
......@@ -3,8 +3,15 @@ class Menu extends Phaser.Scene {
super("menuScene");
}
preload() {
// load audio
this.load.audio('sfx_select', './assets/blip_select12.wav');
this.load.audio('sfx_explosion', './assets/explosion38.wav');
this.load.audio('sfx_rocket', './assets/rocket_shot.wav');
}
create() {
this.add.text(20, 20, "Rocket Patrol Menu");
this.scene.start("playScene");
}
}
}
\ No newline at end of file
......@@ -46,16 +46,56 @@ class Play extends Phaser.Scene {
frames: this.anims.generateFrameNumbers('explosion', { start: 0, end: 9, first: 0}),
frameRate: 30
});
// Initialize score
this.p1Score = 0;
// display score
let scoreConfig = {
fontFamily: 'Courier',
fontSize: '28px',
backgroundColor: '#F3B141',
color: '#843605',
align: 'right',
padding: {
top: 5,
bottom: 5,
},
fixedWidth: 100
}
// Add text to screen on creation
this.scoreLeft = this.add.text(borderUISize + borderPadding, borderUISize + borderPadding*2, this.p1Score, scoreConfig);
// GAME OVER Flag
this.gameOver = false;
// 60-second play clock
scoreConfig.fixedWidth = 0;
this.clock = this.time.delayedCall(10000, () => {
this.add.text(game.config.width/2, game.config.height/2, 'GAME OVER', scoreConfig).setOrigin(0.5);
this.add.text(game.config.width/2, game.config.height/2 + 64, 'Press (R) to Restart', scoreConfig).setOrigin(0.5);
this.gameOver = true;
}, null, this);
}
update() {
// check key input for restart
if (this.gameOver && Phaser.Input.Keyboard.JustDown(keyR)) {
this.scene.restart();
}
this.starfield.tilePositionX -= 4;
this.p1Rocket.update();
// Move spaceships
this.ship01.update();
this.ship02.update();
this.ship03.update();
if (!this.gameOver) {
// Move rocket
this.p1Rocket.update();
// Move spaceships
this.ship01.update();
this.ship02.update();
this.ship03.update();
}
// check collisions
if (this.checkCollision(this.p1Rocket, this.ship03)) {
......@@ -94,6 +134,10 @@ class Play extends Phaser.Scene {
ship.reset(); // reset ship position
ship.alpha = 1; // make ship visible again
boom.destroy(); // remove explosion sprite
});
});
this.p1Score += ship.points;
this.scoreLeft.text = this.p1Score;
this.sound.play('sfx_explosion');
}
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment