xxxxxxxxxx
77
var x = 200;
var y = 200;
var gameOver = false;
var direction = 39;
var direction2 = 37;
var b = 600;
var c = 600;
function setup() {
createCanvas(800, 800);
background(0, 0, 255);
fill(0);
rect(3, 3, 793, 793);
textAlign(CENTER);
frameRate(45);
strokeWeight(2);
}
function draw() {
if(gameOver === true)
return;
if (notBlack() === true) {
fill(255);
textSize(90);
text("Game Over!", 400, 100);
gameOver = true;
fill(255,0,0);
stroke(255,0,0);
ellipse(x,y,40,40);
}
fill(0,100,0);
rect(0,0,75,25);
textSize(20);
fill(255)
text(frameCount,37,20);
stroke(255);
point(x, y);
point(b,c);
if(direction === 37){
x = x - 2;
}
else if(direction === 38){
y = y - 2;
}
else if(direction === 39){
x = x + 2;
}
else if(direction === 40){
y = y + 2;
}
}
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;
var d = get(b, c);
return false;
}
function keyPressed(){
if(keyCode >= 37 && keyCode<=40){
direction = keyCode;
}
if (key === 'r'){
x = 200;
y = 200;
gameOver = false;
direction = int(random(37,41));
background(0,0,225);
fill(0);
stroke(0);
rect(3,3,793,793);
frameCount = 0;
}
}