xxxxxxxxxx
var fb1
var fb2
var fb3
var fb4
var fb5
var fb6
var score=0
var heroSize= 35
var timer
var hasMyGameEnded = false
var x=200
var y=200
function setup() {
createCanvas(500, 500);
fb1= new FoodBits();
fb2 = new FoodBits();
fb3= new FoodBits();
fb4= new FoodBits();
fb5= new FoodBits();
fb6= new FoodBits();
timer=setTimeout(endGame,25000);
}
function draw() {
if(hasMyGameEnded == true){background(255)
fill(0)
textSize(40)
text("The Game is Over",100,150)
textSize(20)
text("Your Score:"+score,150,300)
text("Press SPACE to play again",100,480)}
if (hasMyGameEnded==false){
background(0);
fb1.display();
fb2.display();
fb3.display();
fb4.display();
fb5.display();
fb6.display();
fb1.hide();
fb2.hide();
fb3.hide();
fb4.hide();
fb5.hide();
fb6.hide();
drawHero();
}
}
function drawHero(){
circle(x,y,heroSize)
if(keyCode==RIGHT_ARROW){
x+=5
}
if(keyCode==LEFT_ARROW){
x-=5
}
if(keyCode==DOWN_ARROW){
y+=5
}
if(keyCode==UP_ARROW){
y-=5
}
}
function endGame(){
hasMyGameEnded=true;
print("The Game Has Ended")
}
function keyPressed(){
if(key==' '){
score=0;
heroSize=35
hasMyGameEnded=false
}
}
class FoodBits{
constructor(){
this.c = color(random(255),random(255),random(255))
this.size = random(20,40)
this.x= random(400)
this.y=random(400)
this.haveIBeenEaten= false
}
//variables
//size
//number value
//x and y position
//have i been eaten
//Functions <-methods
//display
display(){
noStroke();
fill(this.c);
circle(this.x,this.y, this.size)
}
hide(){
if(dist(x,y,this.x,this.y)<heroSize/2){
this.x=50000;
score +=1
print(score);
heroSize+=this.size/5
this.x=random(0,500)
this.y=random(0,500)
}
}
}