xxxxxxxxxx
varscore = 0;
var heroSize = 10;
var timer;
var hasMyGameEnded = false;
var x = 10;
var y = 10;
var fb1;
var fb2;
var fb3;
var fb4;
var fb5;
var score = 0;
function setup() {
createCanvas(900, 500);
fb1 = new FoodBits();
fb2 = new FoodBits();
fb3 = new FoodBits();
fb4 = new FoodBits();
fb5 = new FoodBits();
timer = setTimeout(endGame, 30000);
}
function draw() {
background(220);
if (hasMyGameEnded == true) {
background(0);
fill(255);
textSize(50);
text("GAME OVER", 500, 250);
textSize(25);
text("your score is: " + score, 500, 300);
textSize(25);
text("press SPACE to play again", 500, 300);
}
if (hasMyGameEnded == false) {
fb1.display();
fb2.display();
fb3.display();
fb4.display();
fb5.display();
fb1.hide();
fb2.hide();
fb3.hide();
fb4.hide();
fb5.hide();
drawHero();
}
}
function drawHero() {
fill(194, 66, 245);
circle(mouseX, mouseY, heroSize);
}
function endGame() {
hasMyGameEnded == true;
}
function keyPressed() {
if (key == " ") {
score = 0;
heroSize = 10;
hasMyGameEnded == false;
timer = setTimeout(endGame, 30000);
}
}
class FoodBits {
//Variables(Properties)
constructor() {
this.c = color(random(255), random(255), random(255));
this.size = random(10, 30);
this.x = random(0, 1000);
this.y = random(0, 500);
this.haveIBeenEaten = false;
}
//Functions(Methods)
display() {
noStroke();
fill(this.c);
circle(this.x, this.y, this.size);
}
hide() {
if (dist(mouseX, mouseY, this.x, this.y) < heroSize / 2) {
score+= 1;
heroSize += this.size / 6;
this.x = random(0, 500);
this.y = random(0, 500);
}
}
}