Skip to content
This repository has been archived by the owner on Jul 27, 2023. It is now read-only.

Commit

Permalink
Merge pull request #15 from MochicStudio/dev
Browse files Browse the repository at this point in the history
Spaceship shoots, and attack fixed
  • Loading branch information
andresruizdc authored Jan 12, 2021
2 parents 2af3d59 + a7ad487 commit 2c03f92
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 21 deletions.
10 changes: 7 additions & 3 deletions src/scenes/BootGame.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(){
Expand All @@ -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(){
Expand Down
25 changes: 7 additions & 18 deletions src/scenes/PlayGame.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -68,31 +67,21 @@ 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(){
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(){
Expand Down

0 comments on commit 2c03f92

Please sign in to comment.