Added cryp avatar hash and fixed some animations

This commit is contained in:
Mashy
2019-01-04 18:24:01 +10:00
parent 9fa2a94ade
commit 2ae764a3a3
6 changed files with 53 additions and 26 deletions
+13
View File
@@ -0,0 +1,13 @@
const genAvatar = (name) => {
let hash = 0;
if (name.length === 0) return hash;
// Probs don't need to hash using the whole string
for (let i = 0; i < name.length; i += 1) {
const chr = name.charCodeAt(i);
hash = ((hash << 5) - hash) + chr;
hash = hash & 19; // We have avatars named 0-19
}
return `sprite${hash}`;
};
module.exports = genAvatar;
+14 -2
View File
@@ -35,11 +35,23 @@ class CombatSkills extends Phaser.GameObjects.Group {
}
Heal(isAlly, castLocation) {
this.genericHeal(isAlly, castLocation);
}
Triage(isAlly, castLocation) {
this.genericHeal(isAlly, castLocation);
}
TriageTick(isAlly, castLocation) {
this.genericHeal(isAlly, castLocation);
}
genericHeal(isAlly, castLocation) {
// const { sourceX, sourceY } = getCrypPosition(sourcePos, 0);
const lifespan = DELAYS.ANIMATION_DURATION;
const colour = randomColour();
const particles = this.scene.add.particles(colour);
const x = isAlly ? COMBAT.width() * 0.7 : COMBAT.width() * 0.3;
const x = isAlly ? COMBAT.width() * 0.3 : COMBAT.width() * 0.7;
const emitter2 = particles.createEmitter({
x: castLocation.x,
@@ -79,7 +91,7 @@ class CombatSkills extends Phaser.GameObjects.Group {
Block(isAlly) {
const lifespan = DELAYS.ANIMATION_DURATION;
const colour = randomColour();
const x = isAlly ? COMBAT.width() * 0.7 : COMBAT.width() * 0.3;
const x = isAlly ? COMBAT.width() * 0.3 : COMBAT.width() * 0.7;
const emitter1 = this.scene.add.particles(colour).createEmitter({
x,
y: COMBAT.height() * 0.4,
+2 -1
View File
@@ -1,4 +1,5 @@
const Phaser = require('phaser');
const genAvatar = require('./avatar');
const { DELAYS, TEXT, POSITIONS: { COMBAT }, COLOURS } = require('./constants');
@@ -128,7 +129,7 @@ class CrypImage extends Phaser.GameObjects.Image {
// Cryp display
// const avatar = team ? 'magmar' : 'alk';
super(scene, crypAvatarX, crypAvatarY, 'aztec', `sprite${Math.floor(Math.random() * 19) + 1}`);
super(scene, crypAvatarX, crypAvatarY, 'aztec', genAvatar(cryp.name));
this.setScale(0.5);
if (!team) this.flipX = true;
@@ -69,7 +69,7 @@ function animatePhase(scene, game, resolution, cb) {
if (results.length === 0) return cb();
// Move cryps into posistion
// Move cryps into position
if (moveSourceBattle) scene.tweens.add(moveSourceBattle);
scene.tweens.add(moveTargetBattle);
@@ -77,7 +77,7 @@ function animatePhase(scene, game, resolution, cb) {
const isAlly = sourceSpawn.cryp.account === account.id;
// animate animation
const workingSkills = ['Heal', 'Block'];
const workingSkills = ['Heal', 'Block', 'Triage', 'TriageTick'];
if (workingSkills.includes(resolution.skill)) animations.getSkill(resolution.skill, isAlly, castLocation);
else animations.getSkill('attack', isAlly);
+2 -1
View File
@@ -1,6 +1,7 @@
const Phaser = require('phaser');
const { TEXT, COLOURS, POSITIONS: { CRYP_LIST } } = require('./constants');
const genAvatar = require('./avatar');
const ROW_HEIGHT = CRYP_LIST.height() * 0.2;
const ROW_WIDTH = CRYP_LIST.width();
@@ -89,7 +90,7 @@ class MenuCrypList extends Phaser.Scene {
crypInteract.getCenter().x,
crypInteract.getCenter().y,
'aztec',
`sprite${Math.floor(Math.random() * 19) + 1}`
genAvatar(cryp.name)
));
this.crypRows.add(crypInteract);