xxxxxxxxxx
249
// At least one shape
// At least one image
// At least one sound
// At least one on-screen text
let gameState = 0;
let speed = 4;
let trash = [];
// let general_waste=[];
// let plastic_can=[];
let MAX = 2;
let triggerTime;
let trash_collection={
"images": [
{
"name": 'paper',
"classification": 'paper',
"path": "assets/paper.png",
},
{
"name":'letter',
"classification": 'paper',
"path": "assets/letter.png"
},
{
"name":'pizza_box',
"classification": 'paper',
"path": "assets/pizza_box.png"
},
]
}
function preload() {
// paper = loadImage("assets/paper.png");
// pizza_box = loadImage("assets/pizza_box.png");
// letter= loadImage("assets/letter.png");
// can= loadImage("assets/can.png");
// chocolate_wrap= loadImage("assets/chocolate_wrap.png");
// banana = loadImage("assets/banana.png");
// apple= loadImage("assets/apple.png");
binImg = loadImage("assets/trashbins.png");
}
function setup() {
createCanvas(600, 600);
gameState = "START";
triggerTime = 300; //floor(random(70, 500));
let type=random(trash);
for (i = 0; i < trash_collection.images.length; i++) {
// trash[i] = new Item(random(100, width - 100), 0, 50, 50, int(random(1, 4)));
trash.push(loadImage(trash_collection.images[i].path))
// !!! trash[i] = new Item(random(100, width - 100), 0, 50, 50, type);
// if (trash[i].type == 0){
// trash.[]
}
bin = new Bin(0, 0, width, height);
}
function draw() {
if (gameState == "START") {
startGame();
} else if (gameState == "PLAY") {
playGame();
} else if (gameState == "WIN") {
winGame();
} else if (gameState == "OVER") {
overGame();
}
background(255);
bin.show();
if (frameCount % triggerTime == 0) {
print("yo");
trash.push(new Item(random(100, 400), 0, 50, 50, floor(random(1, 4))));
// triggerTime = floor(random(500, 800));
}
if (millis() > 5000 && triggerTime > 20) {
if (frameCount % 60 == 0) {
triggerTime -= 500;
}
}
print(triggerTime);
for (i = 0; i < trash.length; i++) {
trash[i].display();
trash[i].moveDown();
if (trash[i].y > height) {
trash.splice(i, 1);
}
// for (i = 0; i < trash.length; i++) {
// trash[i].display();
// trash[i].moveDown();
// // if (this.y > height/2) {
// // paper_trash[i].display();
// // }
// // paper_trash[i].moveDown();
// if (trash[i].y > height) {
// trash.splice(i, 1);
// }
// }
}
function startGame() {}
function playGame() {}
function winGame() {}
function overGame() {
textAlign(CENTER);
textSize(20);
text("CLICK TO START GAME", width / 2, height / 2);
if (mousePressed == true) {
gameState = "PLAY";
}
}
function keyPressed() {
if (keyCode == RIGHT_ARROW) {
// trash[].moveRight();
}
// else if (keyCode == DOWN_ARROW) {
// y+=speed;
// }
// else if (keyCode == LEFT_ARROW) {
// trash[i].moveLeft();
// } else if (key == " ") {
// speed = 0;
// }
// return false;
}
}
class Item {
constructor(posX, posY, w, h, itemType, itemNum) {
this.x = posX;
this.y = posY;
this.w = w;
this.h = h;
this.type = itemType;
this.num=itemNum;
this.bins=['general', 'paper', 'cans and plastic']
}
check(){
if(this.type==1 && this.num==1){
}
}
// display() {
// if (this.type == 1) {
// image(trash[0], this.x, this.y, this.w, this.h);
// }
// if (this.type == 1) {
// image(trash[1], this.x, this.y, this.w, this.h);
// }
// if (this.type == 1) {
// image(trash[2], this.x, this.y, 90, 100);
// }
// if (this.type == 2) {
// image(trash[3], this.x, this.y, 40, 30);
// }
// if (this.type == 2) {
// image(chocolate_wrap, this.x, this.y, 80, 40);
// }
// if (this.type == 3) {
// image(trash[4], this.x, this.y, this.w, 30);
// }
// if (this.type == 3) {
// image(trash[5], this.x, this.y, this.w, this.h);
// }
// }
display() {
if (this.type == 1) {
image(paper, this.x, this.y, this.w, this.h);
}
if (this.type == 1) {
image(letter, this.x, this.y, this.w, this.h);
}
if (this.type == 1) {
image(pizza_box, this.x, this.y, 90, 100);
}
if (this.type == 2) {
image(can, this.x, this.y, 40, 30);
}
if (this.type == 2) {
image(chocolate_wrap, this.x, this.y, 80, 40);
}
if (this.type == 3) {
image(apple, this.x, this.y, this.w, 30);
}
if (this.type == 3) {
image(banana, this.x, this.y, this.w, this.h);
}
}
moveDown() {
this.y = this.y + speed;
}
moveRight() {
if (this.x < width - this.w - speed) {
this.x += speed;
}
}
moveLeft() {
if (this.x > 0 + this.w - speed) {
this.x -= speed;
}
}
// pressDown(){
// if (keyCode == DOWN_ARROW) {
// this.y+=speed;
// }
}
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)
}
}