From 100ce69cf7eb54dc1a9e9c80e69814669a3b30e4 Mon Sep 17 00:00:00 2001 From: Andres Ruiz Date: Tue, 12 Jan 2021 16:12:33 -0600 Subject: [PATCH 1/3] Load sprites for lasers --- src/scenes/BootGame.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/scenes/BootGame.js b/src/scenes/BootGame.js index 2e46440..f986d6e 100644 --- a/src/scenes/BootGame.js +++ b/src/scenes/BootGame.js @@ -10,8 +10,10 @@ import player_red_two from '../assets/images/png/playerShip2_red.png'; import player_blue_three from '../assets/images/png/playerShip3_blue.png'; import player_green_three from '../assets/images/png/playerShip3_green.png'; import player_red_three from '../assets/images/png/playerShip3_red.png'; -import player_laser_blue from '../assets/images/png/Lasers/laserBlue01.png'; -import enemy_black_one from '../assets/images/png/Enemies/enemyBlack1.png'; +import player_laser_blue from '../assets/images/png/Lasers/laserBlue16.png'; +import player_laser_green from '../assets/images/png/Lasers/laserGreen10.png'; +import player_laser_red from '../assets/images/png/Lasers/laserRed16.png'; +import enemy_blue_one from '../assets/images/png/Enemies/enemyBlue1.png'; export class BootGame extends Phaser.Scene { constructor(){ @@ -32,7 +34,9 @@ export class BootGame extends Phaser.Scene { this.load.image('player_green_three', player_green_three); this.load.image('player_red_three', player_red_three); this.load.image('player_laser_blue', player_laser_blue); - this.load.image('enemy_black_one', enemy_black_one); + this.load.image('player_laser_green', player_laser_green); + this.load.image('player_laser_red', player_laser_red); + this.load.image('enemy_blue_one', enemy_blue_one); } create(){ From 14dae001d9774fd178f22203a7a433a1424dcda8 Mon Sep 17 00:00:00 2001 From: Andres Ruiz Date: Tue, 12 Jan 2021 16:12:40 -0600 Subject: [PATCH 2/3] Use the right sprites --- src/scenes/PlayGame.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/scenes/PlayGame.js b/src/scenes/PlayGame.js index ed6c32f..e996885 100644 --- a/src/scenes/PlayGame.js +++ b/src/scenes/PlayGame.js @@ -68,11 +68,11 @@ export class PlayGame extends Phaser.Scene { playerAttack(){ const playerX = this.player.x; const playerY = this.player.y - 25; - this.lasers.push(this.physics.add.image(playerX, playerY, 'player_laser')); + this.lasers.push(this.physics.add.image(playerX, playerY, 'player_laser_blue')); } spawnEnemy(){ - this.enemies.push(this.physics.add.image(this.getRandomX(), 0, 'enemy_black_one')); + this.enemies.push(this.physics.add.image(this.getRandomX(), 0, 'enemy_blue_one')); } setKeyEvents(){ From a7ad487060c1ec38eac4d973637dae152476d803 Mon Sep 17 00:00:00 2001 From: Andres Ruiz Date: Tue, 12 Jan 2021 16:18:47 -0600 Subject: [PATCH 3/3] Fix attack, set key event as input event --- src/scenes/PlayGame.js | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/src/scenes/PlayGame.js b/src/scenes/PlayGame.js index e996885..75f245f 100644 --- a/src/scenes/PlayGame.js +++ b/src/scenes/PlayGame.js @@ -14,18 +14,17 @@ export class PlayGame extends Phaser.Scene { } update(){ + /* Move the player */ if(this.left.isDown){ if(this.player.x > 0) this.player.setX(this.player.x - 25); } - + /* Move the player */ if(this.right.isDown){ if(this.player.x < this.game.config.width) this.player.setX(this.player.x + 25); } - if(this.space.isDown) this.playerAttack(); - this.enemies.forEach(enemy => { enemy.setPosition(enemy.x, enemy.y + 5, 0, 0); if(enemy.y > this.game.config.height) enemy.destroy(); @@ -78,21 +77,11 @@ export class PlayGame extends Phaser.Scene { setKeyEvents(){ this.left = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.LEFT); this.right = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.RIGHT); - this.space = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.SPACE); - /* Move Player */ - this.input.keyboard.on('keydown-LEFT', () => { - if(this.player.x > 0) - this.player.setX(this.player.x - 25); - }); - this.input.keyboard.on('keydown-RIGHT', () => { - if(this.player.x < this.game.config.width) - this.player.setX(this.player.x + 25); - }); /* Player Attack */ - // this.input.keyboard.on('keydown-SPACE', () => { - // this.playerAttack(); - // }); + this.input.keyboard.on('keydown-SPACE', () => { + this.playerAttack(); + }); } setCollisionEvents(){