GitLab system status is available here and here

Commit 42e973f5 authored by Aaron Gonzales's avatar Aaron Gonzales
Browse files

Added reset code for spaceship and rockets into respective methods

parent a271da29
......@@ -31,8 +31,12 @@ class Rocket extends Phaser.GameObjects.Sprite {
// If missed, reset position of sprite
if (this.y <= borderUISize * 3 + borderPadding) {
this.isFiring = false;
this.y = game.config.height - borderUISize - borderPadding;
this.reset();
}
}
}
\ No newline at end of file
reset() {
this.isFiring = false;
this.y = game.config.height - borderUISize - borderPadding;
}
}
\ No newline at end of file
......@@ -12,7 +12,11 @@ class Spaceship extends Phaser.GameObjects.Sprite {
// If ship goes offscreen, wrap it back around
if (this.x <= 0 - this.width) {
this.x = game.config.width;
this.reset();
}
}
reset() {
this.x = game.config.width;
}
}
\ No newline at end of file
......@@ -46,5 +46,31 @@ 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();
this.ship03.reset();
}
if (this.checkCollision(this.p1Rocket, this.ship02)) {
this.p1Rocket.reset();
this.ship02.reset();
}
if (this.checkCollision(this.p1Rocket, this.ship01)) {
this.p1Rocket.reset();
this.ship01.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