mnml/client/src/scenes/combat.old.js
2018-11-21 17:13:04 +11:00

91 lines
3.5 KiB
JavaScript

const Phaser = require('phaser');
const fs = require('fs');
class PhaserCombat extends Phaser.Scene {
constructor() {
super('combat');
}
preload() {
/* Static Images */
this.textures.addBase64('alk', `data:image/png;base64,${new Buffer.from(fs.readFileSync('./assets/alakazam-f.png')).toString('base64')}`);
this.textures.addBase64('magmar', `data:image/png;base64,${new Buffer.from(fs.readFileSync('./assets/magmar.png')).toString('base64')}`);
this.load.image('sky', 'http://labs.phaser.io/assets/skies/nebula.jpg');
this.load.image('proj', 'http://labs.phaser.io/assets/sprites/bullet.png');
this.load.image('blue', 'http://labs.phaser.io/assets/particles/blue.png');
this.load.image('green', 'http://labs.phaser.io/assets/particles/green.png');
this.load.image('red', 'http://labs.phaser.io/assets/particles/red.png');
this.load.image('white', 'http://labs.phaser.io/assets/particles/white.png');
this.load.image('yellow', 'http://labs.phaser.io/assets/particles/yellow.png');
/* Spritesheets */
this.load.spritesheet({
key: 'explosion',
url: 'http://labs.phaser.io/assets/sprites/explosion.png',
frameConfig: { frameWidth: 64, frameHeight: 64, endFrame: 23 },
});
}
create() {
this.add.image(400, 300, 'sky');// Background image
this.createPlayers();
this.createAnim();
this.cursors = this.input.keyboard.createCursorKeys();
this.combat = false;
this.registry.events.on('changedata', this.updateData, this);
this.input.keyboard.on('keydown_S', () => {
this.scene.switch('passives'); // Switch to battle scene
}, 0, this);
}
createPlayers() {
this.players = this.physics.add.staticGroup();
const img = this.players.create(100, 300, 'alk');
const imgTwo = this.players.create(500, 300, 'magmar');
img.setScale(0.5);
imgTwo.setScale(0.5);
this.playerOneHp = this.add.text(20, 200, '', { fontFamily: 'Arial', fontSize: 24, color: '#00ff00' });
this.playerTwoHp = this.add.text(450, 200, '', { fontFamily: 'Arial', fontSize: 24, color: '#00ff00' });
}
createAnim() {
const config = {
key: 'explodeAnimation',
frames: this.anims.generateFrameNumbers('explosion', { start: 0, end: 23, first: 23 }),
frameRate: 20,
repeat: 0,
};
this.anims.create(config);
}
explode(proj) {
this.proj.disableBody(true, true);
this.emitter.stop();
const sprite = this.add.sprite(proj.x, proj.y, 'explosion').play('explodeAnimation');
sprite.setScale(3);
}
updateData(parent, key, data) {
if (key === 'playerCryps') {
this.playerOneHp.text = (`${data.cryps[0].hp.base.toString()} / ${data.cryps[0].stamina.base.toString()} HP`);
if (data.cryps[0].hp.base === 0) {
// this.PhaserCombat.skills('blast', 400, -150);
this.skills('wall', 'green', 400, -250);
}
}
if (key === 'enemyCryps') {
this.playerTwoHp.text = `${data.cryps[0].hp.base.toString()} / ${data.cryps[0].stamina.base.toString()} HP`;
if (data.cryps[0].hp.base === 0) {
// this.PhaserCombat.skills('blast', 180, 150);
this.skills('wall', 'green', 180, 250);
}
}
}
}
PhaserCombat.prototype.skills = require('./phaser.skills.js');
module.exports = PhaserCombat;