GitLab system status is available here and here

Commit a271da29 authored by Aaron Gonzales's avatar Aaron Gonzales
Browse files

Added spaceships and their movement logic

parent fdb2a841
......@@ -14,6 +14,7 @@
<body>
<script src="./lib/phaser.js"></script>
<script src="./src/prefabs/Rocket.js"></script>
<script src="./src/prefabs/Spaceship.js"></script>
<script src="./src/scenes/Menu.js"></script>
<script src="./src/scenes/Play.js"></script>
<script src="./src/main.js"></script>
......
class Spaceship extends Phaser.GameObjects.Sprite {
constructor (scene, x, y, texture, frame, pointValue) {
super(scene, x, y, texture, frame);
scene.add.existing(this);
this.points = pointValue;
this.moveSpeed = 3
}
update() {
// Move Spaceship left
this.x -= this.moveSpeed;
// If ship goes offscreen, wrap it back around
if (this.x <= 0 - this.width) {
this.x = game.config.width;
}
}
}
\ No newline at end of file
......@@ -26,6 +26,11 @@ class Play extends Phaser.Scene {
// add rocket (p1)
this.p1Rocket = new Rocket(this, game.config.width/2, game.config.height - borderUISize - borderPadding, 'rocket').setOrigin(0.5, 0);
// add spaceships (x3)
this.ship01 = new Spaceship(this, game.config.width + borderUISize*6, borderUISize*4, 'spaceship', 0, 30).setOrigin(0, 0);
this.ship02 = new Spaceship(this, game.config.width + borderUISize*3, borderUISize*5 + borderPadding*2, 'spaceship', 0, 20).setOrigin(0,0);
this.ship03 = new Spaceship(this, game.config.width, borderUISize*6 + borderPadding*4, 'spaceship', 0, 10).setOrigin(0,0);
// define keys
keyF = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.F);
keyR = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.R);
......@@ -36,5 +41,10 @@ class Play extends Phaser.Scene {
update() {
this.starfield.tilePositionX -= 4;
this.p1Rocket.update();
// Move spaceships
this.ship01.update();
this.ship02.update();
this.ship03.update();
}
}
\ 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