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) {