From bd750be110b4283fce405415971dc4f89387b182 Mon Sep 17 00:00:00 2001 From: Mashy Date: Thu, 20 Jun 2019 16:25:03 +1000 Subject: [PATCH] blast anim, improved random point util --- client/src/components/animations.jsx | 11 ++- client/src/components/anims/attack.charge.jsx | 2 +- client/src/components/anims/blast.jsx | 90 ++++++++++++++++++ client/src/components/anims/test.jsx | 93 ++++++++++++------- client/src/utils.jsx | 14 ++- 5 files changed, 168 insertions(+), 42 deletions(-) create mode 100644 client/src/components/anims/blast.jsx diff --git a/client/src/components/animations.jsx b/client/src/components/animations.jsx index 4797a2f9..b60c89b7 100644 --- a/client/src/components/animations.jsx +++ b/client/src/components/animations.jsx @@ -1,8 +1,10 @@ const preact = require('preact'); const Attack = require('./anims/attack'); +const Blast = require('./anims/blast'); const Strike = require('./anims/strike'); -// const Test = require('./anims/test'); + +const Test = require('./anims/test'); const AttackCharge = require('./anims/attack.charge'); @@ -43,6 +45,7 @@ function animations(props) { const skill = removeTier(text); switch (skill) { case 'Attack': return ; + case 'Blast': return ; case 'StrikeI': return ; default: return text; } @@ -57,13 +60,13 @@ function animations(props) { ; } - /* - return ( + +/* return (
); - */ +*/ return (
 
); } diff --git a/client/src/components/anims/attack.charge.jsx b/client/src/components/anims/attack.charge.jsx index 33c51a21..263d35a3 100644 --- a/client/src/components/anims/attack.charge.jsx +++ b/client/src/components/anims/attack.charge.jsx @@ -11,7 +11,7 @@ class AttackCharge extends Component { super(); this.team = props.team; this.colour = props.colour; - const points = randomPoints(7, 50, 300, 400); + const points = randomPoints(7, 50, { x: 0, y: 0, width: 300, height: 400 }); this.charges = points.map(coord => charge(coord[0], coord[1], 6, this.colour)); } diff --git a/client/src/components/anims/blast.jsx b/client/src/components/anims/blast.jsx new file mode 100644 index 00000000..83a47d0d --- /dev/null +++ b/client/src/components/anims/blast.jsx @@ -0,0 +1,90 @@ +const preact = require('preact'); +const { Component } = require('preact'); +const anime = require('animejs').default; + +const { TIMES } = require('../../constants'); +const { randomPoints } = require('../../utils'); + +const duration = TIMES.START_SKILL; + + +function projectile(x, y, radius, colour) { + return ( + + ); +} + +class AttackCharge extends Component { + constructor(props) { + super(); + this.team = props.team; + // this.colour = props.colour; + this.colour = '#00aabb'; + const points = randomPoints(8, 60, { x: 0, y: 0, width: 300, height: 400 }); + this.charges = points.map(coord => projectile(coord[0], coord[1], 20, this.colour)); + } + + render() { + return ( + + // {this.charges} + + + + + + + + + + + + + {this.charges} + + ); + } + + componentDidMount() { + anime.set('.skill-anim', { + rotate: 90, + translateY: -200, + translateX: 0, + }); + anime.set('#explosion feDisplacementMap', { + scale: 1, + }); + + anime({ + targets: '.skill-anim', + translateY: 0, + translateX: 0, + loop: false, + duration: (duration * 1 / 2), + easing: 'easeInQuad', + }); + anime({ + targets: '#explosion feDisplacementMap', + scale: 100, + loop: false, + duration, + easing: 'easeInQuad', + }); + } +} + +module.exports = AttackCharge; diff --git a/client/src/components/anims/test.jsx b/client/src/components/anims/test.jsx index 0b0f3cb5..f7929bfe 100644 --- a/client/src/components/anims/test.jsx +++ b/client/src/components/anims/test.jsx @@ -2,19 +2,35 @@ const preact = require('preact'); const { Component } = require('preact'); const anime = require('animejs').default; -const charge = require('../svgs/charge'); const { TIMES } = require('../../constants'); const { randomPoints } = require('../../utils'); const duration = TIMES.START_SKILL; -class Attack extends Component { + +function projectile(x, y, radius, colour) { + return ( + + ); +} + +class AttackCharge extends Component { constructor(props) { super(); - this.props = props; - const points = randomPoints(7, 50, 300, 400); - const length = 6; - this.charges = points.map(coord => charge(coord[0], coord[1], length, '#a52a2a')); + this.team = props.team; + // this.colour = props.colour; + this.colour = '#00aabb'; + const points = randomPoints(8, 60, { x: 0, y: 0, width: 300, height: 400 }); + this.charges = points.map(coord => projectile(coord[0], coord[1], 20, this.colour)); } render() { @@ -25,45 +41,56 @@ class Attack extends Component { id="Layer_1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 300 400"> + // {this.charges} + + + + + + + + + + + + {this.charges} ); } componentDidMount() { - if (this.props.stage === 'START_SKILL') { - if (!this.props.team) { - anime.set('.skill-anim', { - rotate: 180, - }); - } else { - anime.set('.skill-anim', { - rotate: 0, - }); - } + const charges = document.querySelectorAll('#projectile'); + if (!this.team) { + anime.set('.skill-anim', { + rotate: 90, + translateY: -200, + translateX: 0, + }); + } else { + anime.set('.skill-anim', { + rotate: 90, + translateY: -200, + translateX: 0, + }); } - if (this.props.stage === 'END_SKILL') { - if (!this.props.team) { - anime.set('.skill-anim', { - rotate: 0, - }); - } else { - anime.set('.skill-anim', { - rotate: 180, - }); - } - } - const stageone = document.querySelectorAll('#charge'); anime({ - targets: stageone, - fill: '#a52a2a', - delay: anime.stagger(2), - loop: true, + targets: '.skill-anim', + translateY: 0, + translateX: 0, + loop: false, + duration: (duration * 1 / 2), + easing: 'easeInQuad', + }); + anime({ + targets: '#explosion feDisplacementMap', + scale: 100, + loop: false, duration, easing: 'easeInQuad', }); } } -module.exports = Attack; +module.exports = AttackCharge; diff --git a/client/src/utils.jsx b/client/src/utils.jsx index 4dffe54e..d0b19020 100644 --- a/client/src/utils.jsx +++ b/client/src/utils.jsx @@ -345,13 +345,19 @@ const TARGET_COLOURS = { BROWN: '#583108', }; -function randomPoints(numPoints, radius, width, height) { +function randomPoints(numPoints, radius, dimensions) { + const { + x, + y, + width, + height, + } = dimensions; const points = []; let infCheck = 0; while (points.length < numPoints) { const c = [ - Math.floor(Math.random() * (width - 2 * radius) + radius), - Math.floor(Math.random() * (height - 2 * radius) + radius), + Math.floor(Math.random() * (x + width - 2 * radius) + x + radius), + Math.floor(Math.random() * (y + height - 2 * radius) + y + radius), ]; let overlapping = false; for (let j = 0; j < points.length; j += 1) { @@ -368,7 +374,7 @@ function randomPoints(numPoints, radius, width, height) { infCheck = 0; } else { infCheck += 1; - if (infCheck > 50) { + if (infCheck > 100) { break; } }