xxxxxxxxxx
97
var gameOver = false;
let x = 200;
let y = 200;
var direction = 39;
var compX = 380;
var compY = 200;
var compDir = 37;
var autoPilot = true;
function setup() {
createCanvas(400, 400);
background(0, 0, 255);
fill(0);
rect(5, 5, 380, 380);
fill(0, 100, 0);
rect(350, 190, 20, 20);
textSize(24);
textAlign(CENTER);
print(get(2, 2));
}
function draw() {
if (gameOver == true) {
return;
computer();
}
function human(){
if (notBlack(comX,compY) === true) {
fill(255);
text("GAME OVER!/nHuman Wins!", 200, 180);
gameOver = true;
}
stroke(255);
point(compX, compY);
selfDrive();
if(compDir == 37)
compX = compX - 1;
if(compDir == 38)
compY = compX - 1;
if(compDir == 39)
compX = compX + 1;
if(compDir == 40)
CompY = compY + 1;
}
function keyPressed() {
if (keyCode === 37) {
direction = 37;
}
if (keyCode === 38) {
direction = 38;
}
if (keyCode === 39) {
direction = 39;
}
if (keyCode === 40) {
direction = 40;
}
}
function compDrive(){
if(compDir===37 && notBlack(compX-2, compY)===true)
compDir = 38;
if(compDir===38 && notBlack(compX, compY-2)===true)
compDir = 39;
if(compDir===39 && notBlack(compX+2, compY)===true)
compDir = 40;
if(compDir===40 && notBlack(compX, compY+2)===true)
compDir = 38;
}
function notBlack(x, y) {
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 && keyCode <= 40) direction = keyCode;
if(key === 'a')
autoPilot = !autoPilot;
}
function selfDrive(){
if(direction ===39 && notBlack(x+2, y)===true)
direction = 40;
if(direction===40 && notBlack(x, y+2)===true)
direction=37;
if(direction===37 && notBlack(x-2,y)===true)
direction=38;
if(direction===38 && notBlack(x,y-2)===true)
direction = 39
}