GitLab system status is available here and here

Commit 7ffee330 authored by Ankie Pon's avatar Ankie Pon
Browse files

spaceship explode animation works

parent eecfca2a
......@@ -12,7 +12,7 @@ class Spaceship extends Phaser.GameObjects.Sprite {
//wrap around from left edge to right edge
if(this.x <= 0 - this.width) {
this.x = game.config.width;
this.reset();
}
}
......
......@@ -7,6 +7,7 @@ class Play extends Phaser.Scene {
this.load.image('rocket', './assets/rocket.png');
this.load.image('spaceship', './assets/spaceship.png');
this.load.image('starfield', './assets/starfield.png');
this.load.spritesheet('explosion', './assets/explosion.png', {frameWidth: 64, frameHeight: 32, startFrame: 0, endFrame: 9});
}
create() {
......@@ -34,6 +35,13 @@ class Play extends Phaser.Scene {
keyR = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.R);
keyLEFT = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.LEFT);
keyRIGHT = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.RIGHT);
//creating animation
this.anims.create({
key: 'explode',
frames: this.anims.generateFrameNumbers('explosion', {start: 0, end: 9, first: 0}),
frameRate: 30
});
}
update() {
......@@ -49,12 +57,15 @@ class Play extends Phaser.Scene {
//check collisions
if(this.checkCollision(this.p1Rocket, this.ship03)) {
this.p1Rocket.reset();
this.shipExplode(this.ship03);
}
if(this.checkCollision(this.p1Rocket, this.ship02)) {
this.p1Rocket.reset();
this.shipExplode(this.ship02);
}
if(this.checkCollision(this.p1Rocket, this.ship01)) {
this.p1Rocket.reset();
this.shipExplode(this.ship01);
}
}
......@@ -69,6 +80,18 @@ class Play extends Phaser.Scene {
else {
return false;
}
}
shipExplode(ship) {
//temporarily hide ship
ship.alpha = 0;
//create explosion at ships position
let boom = this.add.sprite(ship.x, ship.y, 'explosion').setOrigin(0, 0);
boom.anims.play('explode');
boom.on('animationcomplete', () => {
ship.reset();
ship.alpha = 1;
boom.destroy();
});
}
}
\ 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