🔬 This draws a translucent square over the cell currently being carved. What happens if you raise the alpha value from 100 to 255, making it fully opaque?
highlight() {
let x = this.i * cellWidth;
let y = this.j * cellWidth;
noStroke();
fill(0, 255, 255, 100); // Cyan highlight for current cell
rect(x, y, cellWidth, cellWidth);
}
class Cell {
constructor(i, j) {
this.i = i;
this.j = j;
this.walls = [true, true, true, true]; // [top, right, bottom, left]
this.visited = false; // For maze generation
this.pathVisited = false; // For pathfinding
this.parent = null; // For pathfinding to reconstruct the path
}
show() {
let x = this.i * cellWidth;
let y = this.j * cellWidth;
stroke(255); // White walls
strokeWeight(2);
// Draw walls if they exist
if (this.walls[0]) line(x, y, x + cellWidth, y); // Top
if (this.walls[1]) line(x + cellWidth, y, x + cellWidth, y + cellWidth); // Right
if (this.walls[2]) line(x + cellWidth, y + cellWidth, x, y + cellWidth); // Bottom
if (this.walls[3]) line(x, y + cellWidth, x, y); // Left
// Highlight visited cells during generation (optional, can be removed once generated)
if (this.visited && !mazeGenerated) {
noStroke();
fill(255, 0, 255, 50); // Pink highlight
rect(x, y, cellWidth, cellWidth);
}
}
highlight() {
let x = this.i * cellWidth;
let y = this.j * cellWidth;
noStroke();
fill(0, 255, 255, 100); // Cyan highlight for current cell
rect(x, y, cellWidth, cellWidth);
}
checkNeighbors() {
let neighbors = [];
// Check neighbors (top, right, bottom, left)
let top = this.j > 0 ? grid[this.i][this.j - 1] : null;
let right = this.i < cols - 1 ? grid[this.i + 1][this.j] : null;
let bottom = this.j < rows - 1 ? grid[this.i][this.j + 1] : null;
let left = this.i > 0 ? grid[this.i - 1][this.j] : null;
if (top && !top.visited) neighbors.push(top);
if (right && !right.visited) neighbors.push(right);
if (bottom && !bottom.visited) neighbors.push(bottom);
if (left && !left.visited) neighbors.push(left);
return neighbors;
}
}