From 491a612b1935b4b4aa7e7917953bf0e9bfc035ea Mon Sep 17 00:00:00 2001 From: Luke Murphy Date: Sun, 9 Feb 2020 16:07:16 +0100 Subject: [PATCH] Towards shape collision sounds --- voicegardens/static/voicegardens.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/voicegardens/static/voicegardens.js b/voicegardens/static/voicegardens.js index 66da9eb..f4796e6 100644 --- a/voicegardens/static/voicegardens.js +++ b/voicegardens/static/voicegardens.js @@ -241,6 +241,9 @@ class GeneratedShape { // the sound recording attached to this shape this.recording = recording; + // the shape that was last collided with + this.lastCollidedShape; + this.initialise(); } @@ -280,7 +283,7 @@ class GeneratedShape { for (let i = 0; i < shapes.length; i++) { let shape = shapes[i]; - if (this === shape) { + if (this === shape || this.lastCollidedShape === shape) { continue; } @@ -294,6 +297,7 @@ class GeneratedShape { ); if (collision === true) { + this.lastCollidedShape = shape; return [true, shape]; } } @@ -459,6 +463,9 @@ function draw() { if (positionTick) { shape.destX = random(windowWidth); shape.destY = random(windowHeight); + + // also reset last collided shape + shape.lastCollidedShape = undefined; } shape.draw();