xxxxxxxxxx
136
//Add start and end
//Update backtrack system
//add spookies
const sceneW = 400;
const sceneH = 400;
const Y_AXIS = 1;
const X_AXIS = 2;
const da = 1 / 800;
var cols,rows,current,particle,footStep,music;
var grid = [];
var stack = [];
let walls = [];
var gate = false;
var gate1 = false;
var mapGate = false;
var scl = 40;
function preload(){
footStep = loadSound("sounds/footstep/footstep.mp3");
music = loadSound("sounds/music/Horror_Ambience_Music.mp3");
}
function setup() {
createCanvas(800, 800);
cols = floor(sceneW/scl);
rows = floor(sceneH/scl);
//maze
for(var j = 0; j < rows; j++){
for(var i = 0; i< cols; i++){
var cell = new Cell(i,j);
grid.push(cell)
}
}
current = grid[0];
//ray
particle = new Particle();
}
//Movement
function move(d){
if(keyIsDown(LEFT_ARROW)){
particle.rotate(-0.05);
}
if(keyIsDown(RIGHT_ARROW)){
particle.rotate(0.05);
}
if(keyIsDown(UP_ARROW)){
particle.move(0.5,d);
}
if(keyIsDown(DOWN_ARROW)){
particle.move(-0.5,d);
}
if(keyIsDown(UP_ARROW) || keyIsDown(DOWN_ARROW)){
if(!(footStep.isPlaying())){
footStep.play();
}
}else{
footStep.stop();
}
}
function keyPressed(){
//Map Toggle
if(keyCode === 77){
if(mapGate){
mapGate = false;
}else{
mapGate = true;
}
}
}
function draw() {
background(0);
//music
if(!(music.isPlaying())){
//music.play();
}
//Maze Gen
if(!gate){
gate = backtracking();
}
if(gate){
var scene;
//Map
scene = particle.look(walls,particle.rays,false);
var w = width / scene.length;
move(scene);
//3D Rendering
push();
translate(0,0);
for(let i = 0; i < scene.length; i++){
const d = scene[i] / width;
const sq = scene[i] * scene[i];
const wSq = width * width;
const h = 30 / d;
const b = 5 / d * 0.6;
noStroke();
fill(b);
rectMode(CENTER);
rect((i + 0.5) * w, height / 2, w, h);
}
pop();
//Map
if(mapGate){
push();
scale(0.5);
noStroke();
fill(190);
rect(0,0,sceneW,sceneH)
particle.show();
for(let wall of walls){
wall.show();
}
scene = particle.look(walls,particle.rays,true);
pop();
}
}
}