GitLab system status is available here and here

Commit 92ca6d7f authored by Ankie Pon's avatar Ankie Pon
Browse files

spaceships insterted and updating

parent 95edb3ab
......@@ -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;
//wrap around from left edge to right edge
if(this.x <= 0 - this.width) {
this.x = game.config.width;
}
}
}
\ No newline at end of file
......@@ -24,6 +24,11 @@ class Play extends Phaser.Scene {
//add rocekt (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);
......@@ -33,6 +38,12 @@ class Play extends Phaser.Scene {
update() {
this.starfield.tilePositionX -= 4;
//update the rocket
this.p1Rocket.update();
//update the 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