xxxxxxxxxx
97
let x = 200;
let y = 200;
let sx=50;
let sy=50;
let m=0
let j=0
let gameOver = false;
let direction = 39;
function setup() {
createCanvas(400, 400);
background (0,0,255);
fill(0);
rect(10, 10, 380, 380);
fill(255, 0, 0);
textSize(30);
textAlign(CENTER);
fill(255)
}
function draw() {
noStroke()
rect(sx,50,20,100);
fill(0)
rect(sx-20,50,20,100)
rect(sx+20,50,20,100)
fill(255)
rect(sx,250,20,100);
fill(0)
rect(sx-20,250,20,100)
rect(sx+20,250,20,100)
if (sx<190){
m=m+0.5}
if (sx>190){
m=m-0.5
j=-20}
sx=sx+m;
if(gameOver === true){
return;
}
if(notBlack() === true){
fill(255, 0, 0);
stroke(255, 0, 0);
ellipse(x, y, 25, 25);
fill(255);
stroke(0);
text("Game Over", 200, 180);
textSize(20);
gameOver = true;
}
stroke(0);
fill(0);
rect(0, 0, 100, 50);
fill(255);
textSize(30);
text(frameCount, 50, 35);
stroke(255,0,0);
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 keyPressed(){
if(keyCode === 37){
direction = 37;
}
if(keyCode === 38){
direction = 38;
}
if(keyCode === 39){
direction = 39;
}
if(keyCode === 40){
direction = 40;
}
}
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;
}