From 01e7f456a7132357eb2e816da89d900158286711 Mon Sep 17 00:00:00 2001 From: Adrien Burgun Date: Fri, 10 Mar 2023 17:06:56 +0100 Subject: [PATCH] :bug: Fix particles being moved twice --- src/simulation/update.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/simulation/update.ts b/src/simulation/update.ts index c5ec2e3..5f5774d 100644 --- a/src/simulation/update.ts +++ b/src/simulation/update.ts @@ -69,7 +69,7 @@ export function update( } if ( - hasMoved(target.get(x, y + 1)) || hasMoved(target.get(x, y + 2)) + hasMoved(target.get(x, y + 1)) // || hasMoved(target.get(x, y + 2)) ) { const left = isEmpty(target.get(x - 1, y + 1)); const right = isEmpty(target.get(x + 1, y + 1)); @@ -90,10 +90,10 @@ export function update( if (isSand(target.get(x, y - 1))) { swap(target, x, y, x, y - 1); swapped.push([x, y - 1]); - } else if (isSand(target.get(x - 1, y - 1))) { + } else if (isSand(target.get(x - 1, y - 1)) && !hasMoved(target.get(x - 1, y - 1))) { swap(target, x, y, x - 1, y - 1); swapped.push([x - 1, y - 1]); - } else if (isSand(target.get(x + 1, y - 1))) { + } else if (isSand(target.get(x + 1, y - 1)) && !hasMoved(target.get(x + 1, y - 1))) { swap(target, x, y, x + 1, y - 1); swapped.push([x + 1, y - 1]); }