xxxxxxxxxx
72
let x,y;
let frog;
let fly;
let score;
let pond;
let eatSound;
let startScreen;
function setup() {
createCanvas(500, 500);
eatSound = new Audio("frogeat.mp3");
startScreen = loadImage("startscreen.png");
pond = loadImage("pond.jpg");
frog = loadImage("frog.png");
fly = loadImage("fly.png");
x = random(10,450);
y = random(10,300);
score = 0;
}
function draw() {
background("pink");
image(startScreen,-90,15,660,480);
if (key) {
background(225);
image(pond, 0,0,500,500);
fill(150,75,0);
textSize(25);
fill(0);
rect(167,27,180,30);
fill("white")
text("Flies Eaten: "+score, 170,30,500,500);
// fly
image(fly,x,y,80,70);
//frog
image(frog,190,330,220,190);
// whe fly gets eaten
if (x < 340 && y > 290 && x > 170) {
eatSound.play();
score = score + 1;
x = random(10,450);
y = random(10,300);
}
if (mouseIsPressed === true) {
if (x < mouseX) {
x = x + random(-2.5,5);
}
if (x > mouseX) {
x = x + random(-5,2.5);
}
if (y < mouseY) {
y = y + random(-2.5,5);
}
if (y > mouseY) {
y = y + random(-5,2.5);
}
}
// boundaries
if (x > 440 ) {
x = x - 10;
} else if (x < 0) {
x = x + 2
}
}
}