xxxxxxxxxx
var bird;
var blocks = [];
var score;
var gameOn;
var firstRun;
var b;
var skin;
function setup() {
createCanvas(600,600);
textAlign(CENTER);
gameOn = false;
bird = new Bird();
firstRun = true;
textSize(32);
score = 0;
b = 0;
// background(b,60,100);
background(100,200,255);
skin = 1;
}
function draw() {
if (b > 400){
b = 0;
}
// colorMode(HSB);
// background(b,40,100);
background(100,200,255);
if(firstRun){
fill("#FFFFFF");
bird.display(skin);
text("SPACEBAR TO FLAP \n ENJOY",width/2,height/2);
}
if (gameOn){
fill("#FFFFFF");
textSize(16);
var scoreText = "Score: " + score;
text(scoreText,50,20);
for (var i = 0; i < blocks.length; i++){
blocks[i].display();
if(blocks[i].hits(bird)){
gameOn = false;
}
if(blocks[i].offscreen()){
score ++;
b+=10;
blocks.splice(i,1);
}
}
if (frameCount % 75 == 0){
blocks.push(new Block());
}
bird.update();
bird.display(skin);
}else if(!gameOn && !firstRun){
fill("#FFFFFF");
textSize(32);
var gameOverText = "GAME OVER \n CLICK TO RESTART \n SCORE: " + score;
text(gameOverText, width/2,height/2);
}
}
function keyPressed(){
if (key == ' '){
if(firstRun){
firstRun = false;
restart();
}
bird.flap();
// console.log("flapped");
}else if(key >= 0 && key <=9){
skin = key;
}
}
function mousePressed(){
firstRun = false;
restart();
}
function restart(){
blocks.push(new Block());
gameOn = true;
bird = new Bird();
blocks = [];
score = 0;
b = 0;
background(b,60,100);
}