xxxxxxxxxx
168
//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 mazeGate = false;
var mapGate = false;
var scl = 40;
var speed = 0.5;
var bottom = 0;
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();
}
//Look
// function mouseMoved(){
// let centerX = windowWidth/2;
// let centerY = windowHeight/2;
// // let dirUp = mouseY - centerY;
// // dirUp = constrain(dirUp,-10,10);
// // lookUp(dirUp);
// let turn = mouseX - centerX;
// turn = constrain(turn,-0.05,0.05);
// console.log(turn)
// // particle.rotate(-turn);
// }
//Movement
function move(){
if(keyIsDown(65)){
//particle.moveSide(-speed);
particle.rotate(-0.05);
}
if(keyIsDown(68)){
//particle.moveSide(speed);
particle.rotate(0.05);
}
if(keyIsDown(87)){
particle.move(speed);
}
if(keyIsDown(83)){
particle.move(-speed);
}
if(keyIsDown(UP_ARROW)){
lookUp(10);
}
if(keyIsDown(DOWN_ARROW)){
lookUp(-10);
}
if(keyIsDown(87) || keyIsDown(83)){
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(!mazeGate){
mazeGate = backtracking();
}
if(mazeGate){
var scene;
//Map
scene = particle.look(walls,particle.rays,false);
var w = width / scene.length;
move();
//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 + bottom, 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();
}
}
}
function lookUp(m){
bottom = bottom + m;
}