xxxxxxxxxx
71
let traps = [];
let butterfly;
let playing = false
// let butterflyIMG, flytrapIMG, backgroundIMG;
const GRAVITY = 9.81;
const JUMP_HEIGHT = 9.0;
const GROUND_HEIGHT = 20;
function preload() {
flytrap = loadImage("assets/flytrap.png");
butterfly = loadImage("assets/butterfly.png");
backgroundIMG = loadImage("assets/greenery.png");
}
function setup() {
createCanvas(600, 600);
background(backgroundIMG);
frameRate(40);
}
function draw() {
image(backgroundIMG, 0, 0);
push();
tint(250, 180, 0);
//flytrap1
image(flytrap, -50, 300, 250, 300);
//flytrap2
image(flytrap, 200, 300, 300, 300);
//flytrap3
image(flytrap, 500, 300, 250, 300);
pop();
//my beautiful butterfly
image(butterfly, 200, 100, 175, 175);
for (let i = traps.length - 1; i >= 0; i--) {
traps[i].show();
traps[i].update();
if (traps[i].offScreen()) {
if (traps[i].pass(butterfly)) {
butterfly.score++;
}
traps.splice(i, 1);
}
if (traps[i].hit(butterfly)) {
strokeWeight(8);
rectMode(CENTER);
fill(255);
rect(width / 2, height / 2, width - 80, 80);
fill(0);
text("Score: " +
butterfly.score, width / 2, height / 2);
playing = false;
noLoop();
}
}
// // draw bird
// // butterfly.show();
// butterfly.update();
// // show the current score
// if (playing) {
// text(butterfly.score, width / 2, height / 5);
// }
// if (traps.length - 1 < 0) {
// text("Let's go", width / 2, height / 3);
// }
}