diff --git a/src/GeneratedDancer.js b/src/GeneratedDancer.js index 5f5bd7ee..68f8b3ef 100644 --- a/src/GeneratedDancer.js +++ b/src/GeneratedDancer.js @@ -40,6 +40,7 @@ class GeneratedDancer { this.graphics = this.p5.createGraphics(worldW, worldH); this.graphics.pixelDensity(1); + this.danceMove = null; // Hand the renderer our mid-layer 2D context. this.renderer.init(this.graphics.drawingContext); @@ -49,6 +50,7 @@ class GeneratedDancer { if (typeof src === 'number') { src = movesById[src] || movesById[0]; } + this.danceMove = src; return this.renderer.setSource(src); } @@ -94,6 +96,24 @@ class GeneratedDancer { this.renderer = null; this.p5 = null; } + + shouldMirror(currentMeasure) { + const movesToMirror = new Set([ + 'rest', + 'clap_high', + 'dab', + 'drop', + 'floss', + 'fresh', + 'kick', + 'roll', + 'thriller', + ]); + return ( + movesToMirror.has(this.danceMove) && + Math.floor(currentMeasure * 2) % 2 === 1 + ); + } } module.exports = GeneratedDancer; diff --git a/src/p5.dance.js b/src/p5.dance.js index 13596a53..fcd34e75 100644 --- a/src/p5.dance.js +++ b/src/p5.dance.js @@ -683,7 +683,6 @@ module.exports = class DanceParty { animationLength - 1, Math.floor(measureTick * animationLength) ); - this.generatedDancer.render(measureFrame); } }; @@ -695,6 +694,9 @@ module.exports = class DanceParty { sprite.draw = () => { if (this.generatedDancer) { + sprite.mirrorX( + this.generatedDancer.shouldMirror(this.getCurrentMeasure()) ? -1 : 1 + ); this.p5_.image( this.generatedDancer.graphics, sprite.x - location.x, @@ -1654,7 +1656,7 @@ module.exports = class DanceParty { if (!this.generatedDancer) { return; } - + this.danceMove = source; this.generatedDancer.setSource(source); }