Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions helpers/SimulationManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand All @@ -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) {
Expand Down