From a4f331aaf1dbb6b5d77e6d9a9317ea34a440f60f Mon Sep 17 00:00:00 2001 From: Mathom Johnson <156151500+MathomJohnson@users.noreply.github.com> Date: Mon, 23 Jun 2025 20:14:19 -0500 Subject: [PATCH] Update SimulationManager obstacle handling --- helpers/SimulationManager.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/helpers/SimulationManager.js b/helpers/SimulationManager.js index 8ba9575..47b81ad 100644 --- a/helpers/SimulationManager.js +++ b/helpers/SimulationManager.js @@ -50,9 +50,6 @@ export class SimulationManager { // Skip updates during evolution or delay if (this.isEvolving) return; - // update obstacles - this.obstacleManager.updateAll(this.getAliveCars()); - this.obstacleManager.drawAll(this.canvas.getContext("2d")); // Update living cars and track max fitness for (const car of this.cars) { @@ -66,6 +63,9 @@ export class SimulationManager { } } + // After updating cars, update obstacles and handle collisions + this.obstacleManager.updateAll(this.getAliveCars()); + // Increment overall distance if at least one car is alive if (this.cars.some(car => car.alive)) { this.distanceTraveled += this.speed; @@ -84,6 +84,9 @@ export class SimulationManager { } draw(ctx) { + // Draw obstacles first so cars appear on top + this.obstacleManager.drawAll(ctx); + // Draw all alive cars for (const car of this.cars) { if (car.alive) {