xxxxxxxxxx
var score = 0;
heroSize = 20;
var minimario;
var x;
var y;
var timer;
var hasMyGameEnded = false;
var mushroom1;
var mushroom_array = [];
var imagenum = 1;
function preload (){
minimario = loadImage('minimario.png');
mushroom = loadImage ('mushroom.png');
}
function setup() {
createCanvas(1000,500);
for(var i = 0; i < 100; i++){
mushroom_array.push(new Mushroom());
}
print (mushroom_array)
x = 70
y = 350
imagenum = 1
timer = setTimeout(endGame, 30000);
}
function draw() {
drawBackground();
// CALL FUNCTIONS
for(var i = 0; i < 100; i++){
mushroom_array[i].display();
mushroom_array[i].hide();
}
if (hasMyGameEnded == true){
background(0);
textFont("Courier New");
fill(255);
textSize(50);
text(" Game over.",200,200)
textSize(25)
text("Your Score is:"+ score,200,300)
text("press SPACE to play again.",200,360)
}
if(hasMyGameEnded == false){
//character
}
if(imagenum == 1){
image (minimario,x, y, 90,90);
}
}
function keyPressed(){
if(key == 'd'){
x -= 10;
}
if(key == 'a'){
x += 10;
}
if(key == 'w'){
y -= 10;
}
if(key == 's'){
y += 10;
}
if(key == ' '){
score = 0;
heroSize = 10;
hasMyGameEnded = false;
timer = setTimeout(endGame, 30000);
}
} //end keypressed
function endGame() {
hasMyGameEnded = true;
}
function drawBackground(){
background(0)
}
class Mushroom{
// variables
constructor(){
this.x = random(400);
this.y = random(400);
this.size = random(30,40);
}
display(){
image(mushroom, this.x, this.y, 50, 50);
}
hide(){
if ( dist(x,y, this.x, this.y) < 20) {
this.x = 40000;
score += 1;
print(score);
this.x = (0, 500);
this.y = (0, 500);
}
}
}