xxxxxxxxxx
45
var x = 200;
var y = 200;
var gameOver = false;
var direction = 40;
function setup() {
createCanvas(400, 400);
background(0,0,255);
fill(0);
rect(3,3,393,393);
textSize(40);
textAlign(CENTER);
}
function draw() {
if (gameOver === true)
return;
if(notBlack() === true){
fill(255);
text("Game Over!",200,120);
gameOver = true;
}
stroke(255);
point(x,y);
if (direction === 37)
x = x - 1;
if (direction === 38)
y = y - 1;
if (direction === 39)
x = x + 1;
if (direction === 40)
y = y + 1;
}
function notBlack() {
var a = get(x, y);
if (a[0] !== 0) return true;
else if (a[1] !== 0) return true;
else if (a[2] !== 0) return true;
return false;
}
function keyPressed(){
if(keyCode >= 37 && keyCode <= 40)
direction = keyCode;
}