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

View File

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