const preact = require('preact'); const { Component } = require('preact'); const anime = require('animejs').default; const { TIMES } = require('../../constants'); const { randomPoints } = require('../../utils'); const duration = TIMES.TARGET_DURATION_MS; function projectile(x, y, radius, colour) { return ( ); } function sword(colour) { return ( ); } class AttackCharge extends Component { constructor(props) { super(); this.animations = []; this.colour = '#a52a2a'; const points = new Array(30).fill(0); this.charges = points.map(() => projectile(150, 420, 7, '#1FF01F')); } render() { return ( {sword(this.colour)} {this.charges} ); } componentDidMount() { let rotate = 0; // Self target value if (this.props.direction.y) { if (!this.props.direction.x) rotate = this.props.direction.y > 0 ? 0 : 180; else { rotate = this.props.direction.y > 0 ? -Math.atan(this.props.direction.y / this.props.direction.x) * 180 / Math.PI : -Math.atan(this.props.direction.y / this.props.direction.x) * 180 / Math.PI + 180; } } else if (this.props.direction.x) { rotate = this.props.direction.x > 0 ? 270 : 90; } anime.set('#slay', { rotate, }); anime.set('#slay', { translateY: -400, translateX: 0, }); anime.set('#explosion feDisplacementMap', { scale: 100, }); anime.set('#sword', { fill: this.colour, stroke: this.colour, }); this.animations.push(anime({ targets: '#slay', opacity: [ { value: 1, delay: TIMES.TARGET_DELAY_MS, duration: TIMES.TARGET_DURATION_MS * 0.3 }, { value: 0, delay: TIMES.TARGET_DURATION_MS * 0.7 + TIMES.POST_SKILL_DURATION_MS * 0.8, duration: TIMES.POST_SKILL_DURATION_MS * 0.2, }], translateY: 0, translateX: 0, loop: false, delay: TIMES.TARGET_DELAY_MS, duration: (duration * 1 / 2), easing: 'easeInQuad', })); this.animations.push(anime({ targets: '#explosion feDisplacementMap', scale: 10000, loop: false, delay: (TIMES.TARGET_DELAY_MS + duration * 1 / 2), duration: (duration * 1 / 2), easing: 'easeInQuad', })); this.animations.push(anime({ targets: '#sword', fill: '#1FF01F', stroke: '#1FF01F', delay: (TIMES.TARGET_DELAY_MS + duration + TIMES.POST_SKILL_DURATION_MS * 0.7), })); const projectiles = document.querySelectorAll('#slay circle'); projectiles.forEach(proj => { this.animations.push(anime({ targets: proj, cx: Math.random() * 250 + 25, cy: Math.random() * 200 - 100, delay: (TIMES.TARGET_DELAY_MS + duration + TIMES.POST_SKILL_DURATION_MS * 0.7), duration: (TIMES.POST_SKILL_DURATION_MS * 0.3), easing: 'easeInQuad', })); }); } componentWillUnmount() { for (let i = this.animations.length - 1; i >= 0; i--) { this.animations[i].reset(); } } } module.exports = AttackCharge;