From aca21d267da406ddfb0a11c69b20485853a8d94f Mon Sep 17 00:00:00 2001 From: Mashy Date: Thu, 13 Dec 2018 18:12:44 +1000 Subject: [PATCH] Added heals and removed enemy hitbox in target phase --- client/src/scenes/combat.animations.js | 32 +++++++++++++++++++ client/src/scenes/combat.hitbox.js | 4 +-- .../src/scenes/combat.render.resolutions.js | 9 ++---- client/src/scenes/combat.skills.js | 14 ++++---- 4 files changed, 44 insertions(+), 15 deletions(-) diff --git a/client/src/scenes/combat.animations.js b/client/src/scenes/combat.animations.js index 34765060..94dcbd8e 100644 --- a/client/src/scenes/combat.animations.js +++ b/client/src/scenes/combat.animations.js @@ -15,12 +15,44 @@ const animationParams = (isAlly) => { return { spawnLocation, speed, img, angleMin, angleMax }; }; +const randomAnimation = () => { + const animations = ['wall', 'spit', 'gravBlast', 'gravBomb', 'chargeBall']; + return animations[Math.floor(Math.random() * 5)]; +}; + class CombatSkills extends Phaser.GameObjects.Group { constructor(scene) { super(scene); this.scene = scene; } + getSkill(type, isAlly) { + if (type === 'attack') { + this[randomAnimation()](isAlly); + } else { + this.heal(); + } + } + + heal() { + const lifespan = DELAYS.ANIMATION_DURATION; + const particles = this.scene.add.particles(randomColour()); + const emitter = particles.createEmitter({ + x: COMBAT.width() * 0.3, + y: COMBAT.height() * 0.2, + angle: { min: 250, max: 290 }, + speed: 250, + gravityY: 1000, + quantity: 4, + scale: { start: 0.1, end: 1 }, + blendMode: 'ADD', + lifespan, + }); + this.add(particles); + this.scene.time.delayedCall(lifespan, () => { emitter.stop(); }, [], this); + + } + wall(isAlly) { const lifespan = DELAYS.ANIMATION_DURATION; const { spawnLocation, speed, img } = animationParams(isAlly); diff --git a/client/src/scenes/combat.hitbox.js b/client/src/scenes/combat.hitbox.js index c633b599..0400844b 100644 --- a/client/src/scenes/combat.hitbox.js +++ b/client/src/scenes/combat.hitbox.js @@ -99,7 +99,7 @@ class CombatHitBox extends Phaser.Scene { const account = this.registry.get('account'); const group = this.scene.get('CombatCryps').cryps; const skillScene = this.scene.get('CombatSkills'); - game.teams.forEach(t => t.cryps.forEach((c) => { + game.teams.find(t => t.id === account.id).cryps.forEach((c) => { const cback = () => { const { activeTarget } = skillScene; if (activeTarget) { @@ -112,7 +112,7 @@ class CombatHitBox extends Phaser.Scene { const crypSpawn = group.children.entries.find(s => s.cryp.id === c.id); const team = c.account === account.id ? 0 : 1; this.add.existing(new CrypHitBox(this, crypSpawn.iter, team, cback)); - })); + }); this.scene.sendToBack(); } diff --git a/client/src/scenes/combat.render.resolutions.js b/client/src/scenes/combat.render.resolutions.js index 566bfd8a..b1fffcd8 100644 --- a/client/src/scenes/combat.render.resolutions.js +++ b/client/src/scenes/combat.render.resolutions.js @@ -6,11 +6,6 @@ const { POSITIONS: { COMBAT }, } = require('./constants'); -const randomAnimation = () => { - const animations = ['wall', 'spit', 'gravBlast', 'gravBomb', 'chargeBall']; - return animations[Math.floor(Math.random() * 5)]; -}; - function findResolutionCryps(scene, group, resolution, game) { const sourceCryp = game.teams.find(t => t.cryps.find(c => c.id === resolution.source_cryp_id)) @@ -55,7 +50,6 @@ function animatePhase(scene, game, resolution, cb) { const group = scene.scene.get('CombatCryps').cryps; const animations = new CombatAnimations(scene); const account = scene.registry.get('account'); - const animation = randomAnimation(); // Find cryps, targets const { sourceSpawn, targetSpawn } = findResolutionCryps(scene, group, resolution, game); @@ -75,7 +69,8 @@ function animatePhase(scene, game, resolution, cb) { scene.time.delayedCall(MOVE_CREEP, () => { const isAlly = resolution.target_team_id !== account.id; // animate animation - animations[animation](isAlly); + if (resolution.skill === 'Heal') animations.getSkill(resolution.skill, isAlly); + else animations.getSkill('attack', isAlly); // Target cryp takes damage scene.time.delayedCall(ANIMATION_DURATION, () => { diff --git a/client/src/scenes/combat.skills.js b/client/src/scenes/combat.skills.js index f6f76551..7611a109 100644 --- a/client/src/scenes/combat.skills.js +++ b/client/src/scenes/combat.skills.js @@ -157,10 +157,12 @@ class CombatSkills extends Phaser.Scene { const enemyTeam = game.teams.find(t => t.id !== account.id); team.cryps.forEach((cryp) => { - const { iter } = this.scene.get('CombatCryps').cryps.children.entries.find(c => c.cryp.id === cryp.id); // return early if KOd if (cryp.hp.base === 0) return true; + // find the cryp position + const { iter } = this.scene.get('CombatCryps').cryps.children.entries.find(c => c.cryp.id === cryp.id); + // draw the skills const skillButtons = cryp.skills.map((skill, j) => addSkill(iter, j, skill, cryp)); @@ -221,22 +223,22 @@ class CombatSkills extends Phaser.Scene { const skills = game.stack.filter(skill => skill.target_team_id === account.id); const friendlyCryps = game.teams.find(t => t.id === account.id).cryps; - skills.forEach((skill, i) => { + skills.forEach((skill) => { const crypTeam = game.teams.find(t => t.cryps.find(c => c.id === skill.source_cryp_id)); const cryp = crypTeam.cryps.find(c => c.id === skill.source_cryp_id); // Draw the cryp name - const sourceCryp = this.scene.get('CombatCryps').cryps.children.entries + const { iter, team } = this.scene.get('CombatCryps').cryps.children.entries .find(c => c.cryp.id === cryp.id); - const skillPos = targetTextPosition(sourceCryp.iter, sourceCryp.team); + const skillPos = targetTextPosition(iter, team); const skillObj = new CrypSkill(this, skillPos[0], skillPos[1], skill, cryp); this.add.existing(skillObj); this.input.setDraggable(skillObj); keyboard.on( - TARGET_KEY_MAP[i], - () => this.mapTargetKeys(skillObj, game.id, friendlyCryps, i), + TARGET_KEY_MAP[iter], + () => this.mapTargetKeys(skillObj, game.id, friendlyCryps, iter), this ); });