xxxxxxxxxx
85
// At least one shape
// At least one image
// At least one sound
// At least one on-screen text
let speed = 1;
let paper_trash = [];
let MAX = 10;
function preload() {
paper = loadImage("assets/paper.png");
pizza_box = loadImage("assets/pizza_box.png");
letter = loadImage("assets/letter.png");
binImg = loadImage("assets/trashbins.png");
}
function setup() {
createCanvas(600, 600);
for (i = 0; i <MAX; i++) {
paper_trash[i] = new Item(random(0, width), 10, 50, 50, int(random(1,4)));
}
bin = new Bin(0, 0, width, height);
// imageMode(CENTER);
// trash = new Item (randomImg)
}
function draw() {
background(255);
bin.show();
for (i = 0; i < MAX; i++) {
paper_trash[i].display();
paper_trash[i].moveDown();
}
}
function play() {
playing = new Item(paper_trash);
imageMode(CORNER);
image(binImg, width, height / 2, 150, 100);
}
class Item {
constructor(posX, posY, w, h, paperType) {
this.x = posX;
this.y = posY;
this.w = w;
this.h = h;
this.randomImg = paperType;
}
display() {
if (this.randomImg == 1) {
image(paper, this.x, this.y, this.w, this.h);
}
if (this.randomImg == 2) {
image(letter, this.x, this.y, this.w, this.h);
}
if (this.randomImg == 3) {
image(pizza_box, this.x, this.y, this.w, this.h);
}
}
moveDown() {
this.y=this.y+2;
}
}
class Bin {
constructor(xLoc, yLoc, w, h) {
this.x = xLoc;
this.y = yLoc;
this.w = w;
this.h = h;
}
show() {
image(binImg, this.x, this.y, this.w, this.h);
// fill(255);
// rect(this.x,this.y, this.w,this.h)
}
}