- use arrow keys to move the dot around the maze - press the space bar to pause movement - if you touch the wall, you will restart to the beginning - good luck & have fun!
xxxxxxxxxx
let x = 50
let y = 85
let c = 0;
let cwhite = [255,255,255,255];
let cblack = [0,0,0,255];
function setup() {
createCanvas(800,600);
background(0);
rectMode(CENTER);
}
function preload(){
Maze = loadImage('maze-one.jpg');
}
function draw() {
background(100);
image(Maze,0,0,800,600);
textSize(30);
let upColor = get(x,y-7.5);
let downColor = get(x,y+7.5);
let rightColor = get(x+7.5,y);
let leftColor = get(x-7.5,y);
if(keyCode == UP_ARROW){
if (eqColor(upColor,cblack)) {
x = 50;
y = 85;
} else {
y = y - 2;
}
}else if(keyCode == DOWN_ARROW){
if (eqColor(downColor,cblack)) {
x = 50;
y = 85;
} else {
y = y + 2;
}
}else if(keyCode == RIGHT_ARROW){
if (eqColor(rightColor,cblack)) {
x = 50;
y = 85;
} else {
x = x + 2;
}
}else if(keyCode == LEFT_ARROW){
if (eqColor(leftColor,cblack)) {
x = 50;
y = 85;
} else {
x = x - 2;
}
}
if(x <= 415 && y >= 560){
x = 50
y= 85
}
ellipse(x,y,15,15);
fill(c);
}
function eqColor(a,b){
return a[0]==b[0]&&a[1]==b[1]&&
a[2]==b[2]&&a[3]==b[3];
}