xxxxxxxxxx
79
var walls = [];
var ray;
var nx1, ny1, nx2, ny2;
function setup() {
createCanvas(windowWidth, windowHeight);
walls.push(new Wall(500, 100, 500, 339));
walls.push(new Wall(0, 0, width, 0));
walls.push(new Wall(0, height, width, height));
walls.push(new Wall(0, 0, 0, height));
walls.push(new Wall(width, 0, width, height));
for (let i = 0; i < 5; i++) {
const x1 = random(width);
const y1 = random(height);
const x2 = random(width);
const y2 = random(height);
walls.push(new Wall(x1, y1, x2, y2));
}
ray = new RaySystem(width / 2, height / 2, 720);
noFill();
stroke(255, 0, 105);
strokeWeight(4);
}
function draw() {
background(51);
rect(0, 0, width, height);
for (let wall of walls) {
wall.display();
}
ray.handle(walls);
}
function mousePressed() {
ray.setPos(mouseX, mouseY);
}
function mouseDragged() {
ray.setPos(mouseX, mouseY);
}
function keyPressed() {
if (keyCode == 67) {
walls = [];
walls.push(new Wall(0, 0, width, 0));
walls.push(new Wall(0, height, width, height));
walls.push(new Wall(0, 0, 0, height));
walls.push(new Wall(width, 0, width, height));
}
if (keyCode == 82) {
walls = [];
walls.push(new Wall(500, 100, 500, 339));
walls.push(new Wall(0, 0, width, 0));
walls.push(new Wall(0, height, width, height));
walls.push(new Wall(0, 0, 0, height));
walls.push(new Wall(width, 0, width, height));
for (let i = 0; i < 5; i++) {
const x1 = random(width);
const y1 = random(height);
const x2 = random(width);
const y2 = random(height);
walls.push(new Wall(x1, y1, x2, y2));
}
}
if (keyCode == 81) {
nx1 = mouseX;
ny1 = mouseY;
}
if (keyCode == 87) {
nx2 = mouseX;
ny2 = mouseY;
walls.push(new Wall(nx1,ny1,nx2,ny2));
}
}