xxxxxxxxxx
109
let frog1;
let frog2;
let frog3;
let frog4;
let frog5;
let fly1, fly2, fly3, fly4, fly5;
function preload() {
bgImg = loadImage("background.png");
flyImg = loadImage("fly.png");
beeImg = loadImage("bee.png");
frogImg = loadImage("frog.png");
flowerImg1 = loadImage("flower1.png");
flowerImg2 = loadImage("flower2.png");
flowerImg3 = loadImage("flower3.png");
}
function setup() {
createCanvas(windowWidth, windowHeight);
frog1 = new Froggy();
frog2 = new Froggy();
frog3 = new Froggy();
frog4 = new Froggy();
frog5 = new Froggy();
fly1 = new Fly();
fly2 = new Fly();
fly3 = new Fly();
fly4 = new Fly();
fly5 = new Fly();
}
function draw() {
background(bgImg);
print(mouseX, mouseY);
frog1.display();
frog2.display();
frog3.display();
frog4.display();
frog5.display();
frog1.move();
frog2.move();
frog3.move();
frog4.move();
frog5.move();
fly1.display();
fly2.display();
fly3.display();
fly4.display();
fly5.display();
fly1.move();
fly2.move();
fly3.move();
fly4.move();
fly5.move();
}
class Fly {
constructor() {
this.x = random(windowWidth / 2, windowWidth);
this.y = random(windowHeight/4, windowHeight / 2);
this.xchange = random(1,3);
this.ychange = random(1,3);
}
display() {
image(flyImg, this.x, this.y, windowWidth / 30, windowHeight / 30);
}
move(){
this.x += this.xchange;
this.y += this.ychange;
if (this.x < windowWidth * 0.7 || this.x > windowWidth * 0.95) {
this.xchange *= -1;
}
if (this.y < windowHeight * 0.2 || this.y > windowHeight * 0.8) {
this.ychange *= -1;
}
}
}
class Froggy {
constructor() {
this.x = random(windowWidth / 1.5, windowWidth);
this.y = random(windowHeight / 2, windowHeight);
this.xchange = random(1,3);
this.ychange = random(1,3);
this.size = random(windowWidth / 13, windowHeight / 2);
}
move() {
this.x += this.xchange;
this.y += this.ychange;
if (this.x < windowWidth * 0.7 || this.x > windowWidth * 0.95) {
this.xchange *= -1;
}
if (this.y < windowHeight * 0.7 || this.y > windowHeight * 0.95) {
this.ychange *= -1;
}
}
display(){
image(frogImg, this.x, this.y, windowWidth / 12, windowHeight / 12);
}
}