xxxxxxxxxx
66
var x = 200;
var y = 200;
var gameOver = false;
var direction = 'w';
function setup() {
createCanvas(400, 400);
background(0, 144, 255);
fill(0);
stroke(0);
rect(5, 5, 390, 390);
print(get(2, 2));
}
function draw() {
if(gameOver == true){
return; //stops the program
}
if (notBlack()) {
fill(255);
textAlign(CENTER);
textSize(50);
text("Game Over!", 100, 100);
gameOver = true;
}
stroke(255);
point(x, y);
if(direction == 'd'){
x++;
}
if(direction == 'a'){
x--;
}
if(direction == 'w'){
y--;
}
if(direction == 's'){
y++;
}
}
function notBlack() {
var a = get(x, y); //get() returns an array for the rgb and opacity of that position
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(key == 's'){
direction = 's';
}
if(key == 'a'){
direction = 'a';
}
if(key == 'd'){
direction = 'd';
}
if(key == 'w'){
direction = 'w';
}
}