From f45121a1724ec027464b6261743ed606b0b9ce47 Mon Sep 17 00:00:00 2001 From: Luke Murphy Date: Sun, 9 Feb 2020 13:30:06 +0100 Subject: [PATCH] Comment, reshuffle shape drawing --- voicegardens/static/voicegardens.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/voicegardens/static/voicegardens.js b/voicegardens/static/voicegardens.js index 6caa133..0118aa9 100644 --- a/voicegardens/static/voicegardens.js +++ b/voicegardens/static/voicegardens.js @@ -438,6 +438,7 @@ function draw() { screenY = lerp(screenY, toScreenY, 0.2); translate(screenX, screenY); + // generate a new shape after a sound recording if (newSoundJustRecorded === true) { let newShape = new GeneratedShape(); shapes.push(newShape); @@ -448,19 +449,24 @@ function draw() { for (let i = 0; i < shapes.length; i++) { let shape = shapes[i]; - shape.draw(); - shape.move(); - + // randomly move the shapes if (positionTick) { shape.destX = random(windowWidth); shape.destY = random(windowHeight); } - if (shape.collide(shapes) === true) { + shape.draw(); + shape.move(); + + // play recordings when shapes collide + let [collision, collidedShape] = shape.collide(shapes); + if (collision === true) { shape.sound(); + collidedShape.sound(); } } + // reset random shape position time ticker positionTick = false; }