GitLab system status is available here and here

Commit eecfca2a authored by Ankie Pon's avatar Ankie Pon
Browse files

fixed firing bug

parent 92ca6d7f
......@@ -21,7 +21,7 @@ class Rocket extends Phaser.GameObjects.Sprite {
}
//fire button
if(Phaser.Input.Keyboard.JustDown(keyF)) {
this.isFiring = ture;
this.isFiring = true;
}
//if fired move up
if(this.isFiring && this.y >= borderUISize * 3 + borderPadding) {
......@@ -33,4 +33,9 @@ class Rocket extends Phaser.GameObjects.Sprite {
this.y = game.config.height - borderUISize - borderPadding;
}
}
reset() {
this.isFiring = false;
this.y = game.config.height - borderUISize - borderPadding;
}
}
\ No newline at end of file
......@@ -15,4 +15,8 @@ class Spaceship extends Phaser.GameObjects.Sprite {
this.x = game.config.width;
}
}
reset() {
this.x = game.config.width;
}
}
\ No newline at end of file
......@@ -45,5 +45,30 @@ class Play extends Phaser.Scene {
this.ship01.update();
this.ship02.update();
this.ship03.update();
//check collisions
if(this.checkCollision(this.p1Rocket, this.ship03)) {
this.p1Rocket.reset();
}
if(this.checkCollision(this.p1Rocket, this.ship02)) {
this.p1Rocket.reset();
}
if(this.checkCollision(this.p1Rocket, this.ship01)) {
this.p1Rocket.reset();
}
}
checkCollision(rocket, ship) {
//simple AABB checking
if (rocket.x < ship.x + ship.width &&
rocket.x + rocket.width > ship.x &&
rocket.y < ship.y + ship.height &&
rocket.height + rocket.y > ship.y) {
return true;
}
else {
return false;
}
}
}
\ 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