diff --git a/client/src/components/anims/test.jsx b/client/src/components/anims/test.jsx index fdbd846f..97e08d00 100644 --- a/client/src/components/anims/test.jsx +++ b/client/src/components/anims/test.jsx @@ -2,7 +2,9 @@ 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; @@ -10,53 +12,9 @@ class Attack extends Component { constructor(props) { super(); this.props = props; - const points = []; - - - for (let i = 0; i <= 2; i += 1) { - const x = Math.floor(Math.random() * 200 + 50); - const y = Math.floor(Math.random() * 300 + 50); - points.push([x, y]); - this.circles = points.map((coord, j) => ( - - - - - - )); - } + const points = randomPoints(7, 50, 300, 400); + const length = 6; + this.charges = points.map(coord => charge(coord[0], coord[1], length, '#a52a2a')); } render() { @@ -67,10 +25,7 @@ class Attack extends Component { id="Layer_1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 300 400"> - - - - {this.circles} + {this.charges} ); } @@ -105,7 +60,7 @@ class Attack extends Component { fill: '#a52a2a', delay: anime.stagger(100), loop: true, - duration: 1000, + duration: duration, easing: 'easeInQuad', }); diff --git a/client/src/components/svgs/charge.jsx b/client/src/components/svgs/charge.jsx new file mode 100644 index 00000000..7d2fc1a1 --- /dev/null +++ b/client/src/components/svgs/charge.jsx @@ -0,0 +1,42 @@ +const preact = require('preact'); + +module.exports = function charge(x, y, height, colour) { + return ( + + + + + + ); +} diff --git a/client/src/utils.jsx b/client/src/utils.jsx index 25039b98..da4b927c 100644 --- a/client/src/utils.jsx +++ b/client/src/utils.jsx @@ -345,6 +345,37 @@ const TARGET_COLOURS = { BROWN: '#583108', }; +function randomPoints(numPoints, radius, width, height) { + 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), + ]; + let overlapping = false; + for (let j = 0; j < points.length; j += 1) { + const o = points[j]; + const dx = c[0] - o[0]; + const dy = c[1] - o[1]; + const d = Math.floor(Math.sqrt(dx * dx + dy * dy)); + if (d < radius) { + overlapping = true; + } + } + if (!overlapping) { + points.push(c); + infCheck = 0; + } else { + infCheck += 1; + if (infCheck > 50) { + break; + } + } + } + return points; +} + module.exports = { stringSort, convertItem, @@ -356,4 +387,5 @@ module.exports = { STATS, COLOURS, TARGET_COLOURS, + randomPoints, };