GitLab system status is available here and here

Commit 070c079c authored by wbtate's avatar wbtate
Browse files

Finished

parent 82c24cd7
......@@ -9,6 +9,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(){
......@@ -19,8 +20,9 @@ class Rocket extends Phaser.GameObjects.Sprite {
this.x+=this.moveSpeed;
}
}
if(Phaser.Input.Keyboard.JustDown(keyF)){
if(Phaser.Input.Keyboard.JustDown(keyF)&&!this.isFiring){
this.isFiring=true;
this.sfxRocket.play(); // play sfx
}
if(this.isFiring&&this.y>=borderUISize*3+borderPadding){
this.y-=this.moveSpeed;
......
......@@ -5,7 +5,7 @@ class Spaceship extends Phaser.GameObjects.Sprite{
super(scene,x,y,texture,frame);
scene.add.existing(this);
this.points=pointValue;
this.moveSpeed=3;
this.moveSpeed=game.settings.spaceshipSpeed;
}
update(){
......
......@@ -2,9 +2,56 @@ class Menu extends Phaser.Scene {
constructor() {
super("menuScene");
}
preload() {
// load audio
this.load.audio('sfx_select', './assets/assets_blip_select12.wav');
this.load.audio('sfx_explosion', './assets/assets_explosion38.wav');
this.load.audio('sfx_rocket', './assets/assets_rocket_shot.wav');
}
create() {
this.add.text(20, 20, "Rocket Patrol Menu");
this.scene.start("playScene");
let menuConfig = {
fontFamily: 'Courier',
fontSize: '28px',
backgroundColor: '#F3B141',
color: '#843605',
align: 'right',
padding: {
top: 5,
bottom: 5,
},
fixedWidth: 0
}
this.add.text(game.config.width/2, game.config.height/2 - borderUISize - borderPadding, 'ROCKET PATROL', menuConfig).setOrigin(0.5);
this.add.text(game.config.width/2, game.config.height/2, 'Use ←→ arrows to move & (F) to fire', menuConfig).setOrigin(0.5);
menuConfig.backgroundColor = '#00FF00';
menuConfig.color = '#000';
this.add.text(game.config.width/2, game.config.height/2 + borderUISize + borderPadding, 'Press ← for Novice or → for Expert', menuConfig).setOrigin(0.5);
// define keys
keyLEFT = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.LEFT);
keyRIGHT = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.RIGHT);
}
update() {
if (Phaser.Input.Keyboard.JustDown(keyLEFT)) {
// easy mode
game.settings = {
spaceshipSpeed: 3,
gameTimer: 60000
}
this.sound.play('sfx_select');
this.scene.start('playScene');
}
if (Phaser.Input.Keyboard.JustDown(keyRIGHT)) {
// hard mode
game.settings = {
spaceshipSpeed: 4,
gameTimer: 45000
}
this.sound.play('sfx_select');
this.scene.start('playScene');
}
}
}
\ No newline at end of file
......@@ -11,7 +11,7 @@ class Play extends Phaser.Scene {
this.load.spritesheet('explosion', './assets/explosion.png', {frameWidth: 64, frameHeight: 32, startFrame: 0, endFrame: 9});
}
create() {
this.add.text(20, 20, "Rocket Patrol Play");
// place tile sprite
this.starfield = this.add.tileSprite(0, 0, 640, 480, 'starfield').setOrigin(0, 0);
// green UI background
......@@ -39,14 +39,45 @@ this.anims.create({
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
}
this.scoreLeft = this.add.text(borderUISize + borderPadding, borderUISize + borderPadding*2, this.p1Score, scoreConfig);
// 60-second play clock
this.gameOver = false;
scoreConfig.fixedWidth = 0;
this.clock = this.time.delayedCall(game.settings.gameTimer, () => {
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 or ← for Menu', scoreConfig).setOrigin(0.5);
this.gameOver=true;
}, null, this);
}
update() {
this.starfield.tilePositionX -= 4;
if (this.gameOver && Phaser.Input.Keyboard.JustDown(keyLEFT)) {
this.scene.start("menuScene");
}
if (this.gameOver && Phaser.Input.Keyboard.JustDown(keyR)) {
this.scene.restart();
}
if (!this.gameOver) {
this.p1Rocket.update();
this.ship01.update(); // update spaceships (x3)
this.ship02.update();
this.ship03.update();
this.ship03.update();}
// check collisions
if(this.checkCollision(this.p1Rocket, this.ship03)) {
this.p1Rocket.reset();
......@@ -77,14 +108,18 @@ if(this.checkCollision(this.p1Rocket, this.ship03)) {
shipExplode(ship) {
// temporarily hide ship
ship.alpha = 0;
ship.alpha = 0;
// create explosion sprite at ship's position
let boom = this.add.sprite(ship.x, ship.y, 'explosion').setOrigin(0, 0);
boom.anims.play('explode'); // play explode animation
boom.on('animationcomplete', () => { // callback after anim completes
ship.reset(); // reset ship position
ship.alpha = 1; // make ship visible again
boom.destroy(); // remove explosion sprite
});
boom.on('animationcomplete', () => { // callback after ani completes
ship.reset(); // reset ship position
ship.alpha = 1; // make ship visible again
boom.destroy(); // remove explosion sprite
});
// score add and repaint
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