From 09868b42d527a20a994b2cdfe3b06394d15104a5 Mon Sep 17 00:00:00 2001 From: Mashy Date: Tue, 11 Jun 2019 17:52:33 +1000 Subject: [PATCH] tripping with triangles --- client/assets/styles/game.css | 6 ++--- client/src/components/game.construct.jsx | 4 +++- .../src/components/svgs/trippy.triangle.jsx | 22 ++++++++++++++----- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/client/assets/styles/game.css b/client/assets/styles/game.css index ba11a3a6..88c9688a 100644 --- a/client/assets/styles/game.css +++ b/client/assets/styles/game.css @@ -30,7 +30,7 @@ .opponent .combat-text { left: 40%; - top: 75%; + top: 65%; } .opponent .game-construct { @@ -204,8 +204,8 @@ font-size: 2em; font-family: 'Jura'; position: absolute; - top: 50%; - left: 50%; + top: 40%; + left: 40%; } .game-construct.active-skill { diff --git a/client/src/components/game.construct.jsx b/client/src/components/game.construct.jsx index 3e7d035b..6f5942d8 100644 --- a/client/src/components/game.construct.jsx +++ b/client/src/components/game.construct.jsx @@ -8,6 +8,8 @@ const { ConstructAvatar } = require('./construct'); const { animationDivs } = require('../animations'); const shapes = require('./shapes'); +const TrippyTriangle = require('./svgs/trippy.triangle'); + const SkillBtn = require('./skill.btn'); const addState = connect( @@ -77,7 +79,7 @@ function GameConstruct(props) { const combatTextClass = `combat-text ${combatClass}`; const combatTextEl = combatText ?
{combatText}
- : null; + :
; const effects = construct.effects.length ? construct.effects.map(c =>
{c.effect} - {c.duration}T
) diff --git a/client/src/components/svgs/trippy.triangle.jsx b/client/src/components/svgs/trippy.triangle.jsx index 194cb4a3..7e00d6c1 100644 --- a/client/src/components/svgs/trippy.triangle.jsx +++ b/client/src/components/svgs/trippy.triangle.jsx @@ -13,14 +13,16 @@ class TrippyTriangle extends Component { return ( + viewBox="0 0 300 300"> - + @@ -29,13 +31,21 @@ class TrippyTriangle extends Component { } progress() { - const delta = this.state.delta + 0.1; - const pct = 50 - 50 * Math.sin(delta); - this.setState({ pct, delta }); requestAnimationFrame(this.progress); + this.now = window.performance.now(); + const elapsed = this.now - this.then; + if (elapsed > this.fpsInterval) { + this.then = this.now - (elapsed % this.fpsInterval); + const delta = this.state.delta + Math.PI * 0.04; + const pct = 75 + 15 * Math.sin(delta); + this.setState({ pct, delta }); + } } componentDidMount() { + const fps = 30; + this.fpsInterval = 1000 / fps; + this.then = window.performance.now(); requestAnimationFrame(this.progress); }