xxxxxxxxxx
78
var x = 200;
var y = 200;
var gameOver = false;
var direction = 39;
function setup() {
createCanvas(400, 400);
background(6, 15, 97);
fill(0);
rect(10, 10, 380, 380);
textSize(25);
textAlign(CENTER);
frameRate(30);
strokeWeight(2);
}
function draw() {
if (gameOver === true) {
return;
}
if (notBlack() === true) {
fill(255);
text("GAME OVER", 180, 200);
gameOver = true;
}
fill(6, 15, 97);
rect(0, 0, 75, 25);
fill(255);
text(frameCount, 37, 20);
stroke(255);
point(x, y);
if (direction === 37) {
x = x - 2;
}
if (direction === 38) {
y = y - 2;
}
if (direction === 39) {
x = x + 2;
}
if (direction === 40) {
y = y + 2;
}
}
function notBlack() {
let 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) {
direction = 37;
}
if (keyCode === 38) {
direction = 38;
}
if (keyCode === 39) {
direction = 39;
}
if (keyCode === 40) {
direction = 40;
}
if(key === 'r'){
x = 200;
y = 200;
gameOver = false;
direction = 39;
background(6, 15, 97);
fill(0);
rect(10, 10, 380, 380);
frameCount = 0;
}
}