xxxxxxxxxx
31
let bird;
let pipes = [];
function setup() {
createCanvas(400, 600);
bird = new Bird();
pipes.push(new Pipe());
}
function draw() {
background(50);
bird.show();
bird.update();
for(let i = pipes.length - 1; i >= 0; i--) {
const pipe = pipes[i];
pipe.show();
pipe.update();
if (pipe.offscreen()) {
pipes.splice(i, 1);
}
};
if (frameCount % 100 === 0) {
pipes.push(new Pipe());
}
}
function keyPressed() {
if (key == ' ') {
bird.up();
}
}