line endings ="

This commit is contained in:
ntr 2018-11-27 23:57:13 +11:00
parent fa4793f5eb
commit e6e93b776e
2 changed files with 270 additions and 270 deletions

View File

@ -1,156 +1,156 @@
const Phaser = require('phaser'); const Phaser = require('phaser');
const { POSITIONS: { COMBAT }, DELAYS } = require('./constants'); const { POSITIONS: { COMBAT }, DELAYS } = require('./constants');
const randomColour = () => { const randomColour = () => {
const colours = ['green', 'blue', 'red', 'white', 'yellow']; const colours = ['green', 'blue', 'red', 'white', 'yellow'];
return colours[Math.floor(Math.random() * 5)]; return colours[Math.floor(Math.random() * 5)];
}; };
const animationParams = (isAlly) => { const animationParams = (isAlly) => {
const spawnLocation = isAlly ? COMBAT.width() * 0.35 : COMBAT.width() * 0.65; const spawnLocation = isAlly ? COMBAT.width() * 0.35 : COMBAT.width() * 0.65;
const speed = isAlly ? 250 : -250; const speed = isAlly ? 250 : -250;
const img = randomColour(); const img = randomColour();
const angleMin = isAlly ? 320 : 180; const angleMin = isAlly ? 320 : 180;
const angleMax = isAlly ? 360 : 220; const angleMax = isAlly ? 360 : 220;
return { spawnLocation, speed, img, angleMin, angleMax }; return { spawnLocation, speed, img, angleMin, angleMax };
}; };
class CombatSkills extends Phaser.GameObjects.Group { class CombatSkills extends Phaser.GameObjects.Group {
constructor(scene) { constructor(scene) {
super(scene); super(scene);
this.scene = scene; this.scene = scene;
} }
wall(isAlly) { wall(isAlly) {
const lifespan = DELAYS.EFFECT_DURATION; const lifespan = DELAYS.EFFECT_DURATION;
const { spawnLocation, speed, img } = animationParams(isAlly); const { spawnLocation, speed, img } = animationParams(isAlly);
const particles = this.scene.add.particles(img); const particles = this.scene.add.particles(img);
const emitter = particles.createEmitter({ const emitter = particles.createEmitter({
x: spawnLocation, x: spawnLocation,
y: { min: COMBAT.height() * 0.2, max: COMBAT.height() * 0.5 }, y: { min: COMBAT.height() * 0.2, max: COMBAT.height() * 0.5 },
speedX: { min: speed, max: speed * 2 }, speedX: { min: speed, max: speed * 2 },
scale: { start: 0.4, end: 0 }, scale: { start: 0.4, end: 0 },
quantity: 4, quantity: 4,
blendMode: 'ADD', blendMode: 'ADD',
lifespan, lifespan,
}); });
this.add(particles); this.add(particles);
this.scene.time.delayedCall(lifespan, () => { emitter.stop(); }, [], this.scene); this.scene.time.delayedCall(lifespan, () => { emitter.stop(); }, [], this.scene);
} }
spit(isAlly) { spit(isAlly) {
const lifespan = DELAYS.EFFECT_DURATION; const lifespan = DELAYS.EFFECT_DURATION;
const { spawnLocation, speed, img, angleMin, angleMax } = animationParams(isAlly); const { spawnLocation, speed, img, angleMin, angleMax } = animationParams(isAlly);
const particles = this.scene.add.particles(img); const particles = this.scene.add.particles(img);
const emitter = particles.createEmitter({ const emitter = particles.createEmitter({
x: spawnLocation, x: spawnLocation,
y: COMBAT.height() * 0.35, y: COMBAT.height() * 0.35,
angle: { min: angleMin, max: angleMax }, angle: { min: angleMin, max: angleMax },
speed: speed * 2, speed: speed * 2,
scale: { start: 0.4, end: 1 }, scale: { start: 0.4, end: 1 },
gravityY: 250, gravityY: 25,
quantity: 4, quantity: 4,
blendMode: 'ADD', blendMode: 'ADD',
lifespan, lifespan,
}); });
this.add(particles); this.add(particles);
this.scene.time.delayedCall(lifespan, () => { emitter.stop(); }, [], this); this.scene.time.delayedCall(lifespan, () => { emitter.stop(); }, [], this);
} }
gravBomb(isAlly) { gravBomb(isAlly) {
const lifespan = DELAYS.EFFECT_DURATION; const lifespan = DELAYS.EFFECT_DURATION;
const { spawnLocation, img } = animationParams(isAlly); const { spawnLocation, img } = animationParams(isAlly);
const particles = this.scene.add.particles(img); const particles = this.scene.add.particles(img);
const location = isAlly ? COMBAT.width() * 0.35 : COMBAT.width() * 0.65; const location = isAlly ? COMBAT.width() * 0.35 : COMBAT.width() * 0.65;
const well = particles.createGravityWell({ const well = particles.createGravityWell({
x: location, x: location,
y: COMBAT.height() * 0.25, y: COMBAT.height() * 0.25,
power: 4, power: 4,
gravity: 500, gravity: 500,
}); });
this.emitter = particles.createEmitter({ this.emitter = particles.createEmitter({
x: spawnLocation, x: spawnLocation,
y: COMBAT.height() * 0.25, y: COMBAT.height() * 0.25,
speed: 1000, speed: 1000,
scale: { start: 0.7, end: 1 }, scale: { start: 0.7, end: 1 },
blendMode: 'ADD', blendMode: 'ADD',
lifespan, lifespan,
}); });
this.add(particles); this.add(particles);
this.scene.time.delayedCall(lifespan, () => { this.emitter.stop(); well.active = false; }, [], this.scene); this.scene.time.delayedCall(lifespan, () => { this.emitter.stop(); well.active = false; }, [], this.scene);
} }
gravBlast(isAlly) { gravBlast(isAlly) {
const lifespan = DELAYS.EFFECT_DURATION; const lifespan = DELAYS.EFFECT_DURATION;
const WELL_END = lifespan / 2; const WELL_END = lifespan / 2;
const img = randomColour(); const img = randomColour();
const spawnLocation = isAlly ? COMBAT.width() * 0.35 : COMBAT.width() * 0.65; const spawnLocation = isAlly ? COMBAT.width() * 0.35 : COMBAT.width() * 0.65;
const isEnemyLocation = isAlly ? COMBAT.width() * 0.7 : COMBAT.width() * 0.3; const isEnemyLocation = isAlly ? COMBAT.width() * 0.7 : COMBAT.width() * 0.3;
const particles = this.scene.add.particles(img); const particles = this.scene.add.particles(img);
const bounds = isAlly const bounds = isAlly
? { x: COMBAT.width() * 0.3, y: COMBAT.height() * 0.2, w: COMBAT.width() * 0.5, h: COMBAT.height() * 0.2 } ? { x: COMBAT.width() * 0.3, y: COMBAT.height() * 0.2, w: COMBAT.width() * 0.5, h: COMBAT.height() * 0.2 }
: { x: 0.2 * COMBAT.width(), y: COMBAT.height() * 0.2, w: COMBAT.width() * 0.5, h: COMBAT.height() * 0.2 }; : { x: 0.2 * COMBAT.width(), y: COMBAT.height() * 0.2, w: COMBAT.width() * 0.5, h: COMBAT.height() * 0.2 };
const well = particles.createGravityWell({ const well = particles.createGravityWell({
x: spawnLocation, x: spawnLocation,
y: COMBAT.height() * 0.35, y: COMBAT.height() * 0.35,
power: 4, power: 4,
gravity: 500, gravity: 500,
}); });
const emitter = particles.createEmitter({ const emitter = particles.createEmitter({
x: spawnLocation, x: spawnLocation,
y: COMBAT.height() * 0.35, y: COMBAT.height() * 0.35,
speed: 1000, speed: 1000,
scale: { start: 0.7, end: 1 }, scale: { start: 0.7, end: 1 },
blendMode: 'ADD', blendMode: 'ADD',
bounds, bounds,
lifespan, lifespan,
}); });
this.add(particles); this.add(particles);
this.scene.time.delayedCall(WELL_END, () => { emitter.stop(); well.x = isEnemyLocation; }, [], this.scene); this.scene.time.delayedCall(WELL_END, () => { emitter.stop(); well.x = isEnemyLocation; }, [], this.scene);
this.scene.time.delayedCall(lifespan, () => { well.active = false; }, [], this.scene); this.scene.time.delayedCall(lifespan, () => { well.active = false; }, [], this.scene);
} }
chargeBall(isAlly) { chargeBall(isAlly) {
const lifespan = DELAYS.EFFECT_DURATION; const lifespan = DELAYS.EFFECT_DURATION;
const CHARGE_LIFESPAN = lifespan / 2; const CHARGE_LIFESPAN = lifespan / 2;
const { img, spawnLocation } = animationParams(isAlly); const { img, spawnLocation } = animationParams(isAlly);
const targetLocation = isAlly ? 0.7 * COMBAT.width() : 0.25 * COMBAT.width(); const targetLocation = isAlly ? 0.7 * COMBAT.width() : 0.25 * COMBAT.width();
const particles = this.scene.add.particles(img); const particles = this.scene.add.particles(img);
const emitter = particles.createEmitter({ const emitter = particles.createEmitter({
x: 0, x: 0,
y: 0, y: 0,
moveToX: spawnLocation, moveToX: spawnLocation,
moveToY: COMBAT.height() * 0.1, moveToY: COMBAT.height() * 0.1,
scale: 0.75, scale: 0.75,
quantity: 4, quantity: 4,
_frequency: 20, _frequency: 20,
blendMode: 'ADD', blendMode: 'ADD',
emitZone: { source: new Phaser.Geom.Rectangle(0, 0, COMBAT.width(), COMBAT.height()) }, emitZone: { source: new Phaser.Geom.Rectangle(0, 0, COMBAT.width(), COMBAT.height()) },
lifespan: CHARGE_LIFESPAN, lifespan: CHARGE_LIFESPAN,
}); });
const emitter2 = particles.createEmitter({ const emitter2 = particles.createEmitter({
radial: false, radial: false,
x: { min: spawnLocation, max: targetLocation, steps: 256 }, x: { min: spawnLocation, max: targetLocation, steps: 256 },
y: { min: COMBAT.height() * 0.1, max: COMBAT.height() * 0.4, steps: 256 }, y: { min: COMBAT.height() * 0.1, max: COMBAT.height() * 0.4, steps: 256 },
quantity: 4, quantity: 4,
gravityY: 0, gravityY: 0,
scale: { start: 1.5, end: 0, ease: 'Power3' }, scale: { start: 1.5, end: 0, ease: 'Power3' },
blendMode: 'ADD', blendMode: 'ADD',
active: false, active: false,
lifespan, lifespan,
}); });
this.add(particles); this.add(particles);
this.scene.time.delayedCall(CHARGE_LIFESPAN, () => { emitter.stop(); }, [], this.scene); this.scene.time.delayedCall(CHARGE_LIFESPAN, () => { emitter.stop(); }, [], this.scene);
this.scene.time.delayedCall(CHARGE_LIFESPAN, () => { emitter2.active = true; }, [], this.scene); this.scene.time.delayedCall(CHARGE_LIFESPAN, () => { emitter2.active = true; }, [], this.scene);
this.scene.time.delayedCall(lifespan, () => { emitter2.stop(); }, [], this.scene); this.scene.time.delayedCall(lifespan, () => { emitter2.stop(); }, [], this.scene);
} }
cleanup() { cleanup() {
this.children.entries.forEach(obj => obj.destroy()); this.children.entries.forEach(obj => obj.destroy());
} }
} }
module.exports = CombatSkills; module.exports = CombatSkills;

View File

@ -1,114 +1,114 @@
const Phaser = require('phaser'); const Phaser = require('phaser');
const fs = require('fs'); const fs = require('fs');
const { POSITIONS: { COMBAT }, TEXT } = require('./constants'); const { POSITIONS: { COMBAT }, TEXT } = require('./constants');
const { DrawCrypTeams, CrypImage, CrypSkill } = require('./combat.cryps'); const { DrawCrypTeams, CrypImage, CrypSkill } = require('./combat.cryps');
const renderResolutions = require('./combat.render.resolutions'); const renderResolutions = require('./combat.render.resolutions');
const CRYP_KEY_MAP = ['keydown_ONE', 'keydown_TWO', 'keydown_THREE']; const CRYP_KEY_MAP = ['keydown_ONE', 'keydown_TWO', 'keydown_THREE'];
const SKILL_KEY_MAP = ['keydown_Q', 'keydown_W', 'keydown_E', 'keydown_R']; const SKILL_KEY_MAP = ['keydown_Q', 'keydown_W', 'keydown_E', 'keydown_R'];
class Combat extends Phaser.Scene { class Combat extends Phaser.Scene {
constructor() { constructor() {
super({ key: 'Combat' }); super({ key: 'Combat' });
} }
preload() { preload() {
/* Static Images */ /* Static Images */
this.textures.addBase64('alk', `data:image/png;base64,${new Buffer.from(fs.readFileSync('./assets/alakazam-f.png')).toString('base64')}`); 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.textures.addBase64('magmar', `data:image/png;base64,${new Buffer.from(fs.readFileSync('./assets/magmar.png')).toString('base64')}`);
this.load.image('proj', 'http://labs.phaser.io/assets/sprites/bullet.png'); 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('blue', 'http://labs.phaser.io/assets/particles/blue.png');
this.load.image('green', 'http://labs.phaser.io/assets/particles/green.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('red', 'http://labs.phaser.io/assets/particles/red.png');
this.load.image('white', 'http://labs.phaser.io/assets/particles/white.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'); this.load.image('yellow', 'http://labs.phaser.io/assets/particles/yellow.png');
} }
create() { create() {
this.registry.events.on('changedata', this.updateData, this); this.registry.events.on('changedata', this.updateData, this);
this.input.keyboard.on('keydown_S', () => { this.input.keyboard.on('keydown_S', () => {
this.scene.switch('CrypList'); // Switch back to cryp list this.scene.switch('CrypList'); // Switch back to cryp list
}, 0, this); }, 0, this);
this.input.on('pointerup', (pointer, obj) => { this.input.on('pointerup', (pointer, obj) => {
if (obj[0] instanceof CrypImage || obj[0] instanceof CrypSkill) { if (obj[0] instanceof CrypImage || obj[0] instanceof CrypSkill) {
obj[0].clickHandler(); obj[0].clickHandler();
} else if (this.registry.get('activeSkill')) { } else if (this.registry.get('activeSkill')) {
this.registry.get('activeSkill').clearTint(); this.registry.get('activeSkill').clearTint();
this.registry.set('activeSkill', null); this.registry.set('activeSkill', null);
} }
}); });
const logX = COMBAT.LOG.x(); const logX = COMBAT.LOG.x();
const logY = COMBAT.LOG.y(); const logY = COMBAT.LOG.y();
const logWidth = COMBAT.LOG.width(); const logWidth = COMBAT.LOG.width();
// this.skills = new CombatSkills(this);
this.renderedResolves = 0; this.renderedResolves = 0;
this.registry.set('gameAnimating', false);
this.registry.set('gameAnimating', false);
this.account = this.registry.get('account'); this.account = this.registry.get('account');
this.log = this.add.text(COMBAT.LOG.x(), COMBAT.LOG.y(), '', TEXT.NORMAL); this.log = this.add.text(COMBAT.LOG.x(), COMBAT.LOG.y(), '', TEXT.NORMAL);
this.log.setWordWrapWidth(COMBAT.LOG.width()); this.log.setWordWrapWidth(COMBAT.LOG.width());
return true; return true;
} }
updateData(parent, key, data) { updateData(parent, key, data) {
if (key === 'game') { if (key === 'game') {
this.redrawGame(data); this.redrawGame(data);
} }
return true; return true;
} }
redrawGame(game) { redrawGame(game) {
if (!game) return false; if (!game) return false;
const updatedNeeded = !this.registry.get('activeSkill') && !this.registry.get('gameAnimating'); const updatedNeeded = !this.registry.get('activeSkill') && !this.registry.get('gameAnimating');
if (!updatedNeeded) return false; if (!updatedNeeded) return false;
// do we need to render resolution animations? // do we need to render resolution animations?
if (game.resolved.length !== this.renderedResolves) { if (game.resolved.length !== this.renderedResolves) {
const newResolutions = game.resolved.slice(this.renderedResolves); const newResolutions = game.resolved.slice(this.renderedResolves);
renderResolutions(this, game, this.crypTeamRender, newResolutions); renderResolutions(this, game, this.crypTeamRender, newResolutions);
this.renderedResolves = game.resolved.length; this.renderedResolves = game.resolved.length;
return true; return true;
} }
// If not animating resolutions render static skill / block phase // If not animating resolutions render static skill / block phase
if (this.crypTeamRender) this.crypTeamRender.destroy(true); if (this.crypTeamRender) this.crypTeamRender.destroy(true);
this.crypTeamRender = new DrawCrypTeams(this, game); this.crypTeamRender = new DrawCrypTeams(this, game);
// update log // update log
// shallow copy because reverse mutates // shallow copy because reverse mutates
this.log.setText(Array.from(game.log).slice(0, this.logIter).reverse()); this.log.setText(Array.from(game.log).slice(0, this.logIter).reverse());
return true; return true;
} }
iterateLog(game) { iterateLog(game) {
this.logIter += 1; this.logIter += 1;
this.renderedResolves += 1; this.renderedResolves += 1;
this.log.setText(Array.from(game.log).slice(0, this.logIter).reverse()); this.log.setText(Array.from(game.log).slice(0, this.logIter).reverse());
return this.resolvedIter === game.resolved.length; return this.resolvedIter === game.resolved.length;
} }
crypKeyHandler(cryp, iter) { crypKeyHandler(cryp, iter) {
if (CRYP_KEY_MAP[iter]) { if (CRYP_KEY_MAP[iter]) {
this.input.keyboard.removeListener(CRYP_KEY_MAP[iter]); this.input.keyboard.removeListener(CRYP_KEY_MAP[iter]);
if (cryp.skills.length > 0) { // check there are cryp skills if (cryp.skills.length > 0) { // check there are cryp skills
this.input.keyboard.on(CRYP_KEY_MAP[iter], () => { this.input.keyboard.on(CRYP_KEY_MAP[iter], () => {
SKILL_KEY_MAP.forEach(k => this.input.keyboard.removeListener(k)); SKILL_KEY_MAP.forEach(k => this.input.keyboard.removeListener(k));
cryp.skills.forEach((skill, i) => { cryp.skills.forEach((skill, i) => {
this.input.keyboard.on(SKILL_KEY_MAP[i], () => { this.input.keyboard.on(SKILL_KEY_MAP[i], () => {
this.game.events.emit('SET_ACTIVE_SKILL', skill); this.game.events.emit('SET_ACTIVE_SKILL', skill);
skill.setActive(); skill.setActive();
}, this); }, this);
}); });
}, this); }, this);
} }
} }
} }
} }
module.exports = Combat; module.exports = Combat;