xxxxxxxxxx
301
let sceneNum = 1;
//position of the word Level
let levelStart = 50;
let levelButtonSize = 22;
let l;
let level = null;
let veggies = [];
let seeds = [];
let tools = [];
let plants = [];
let weeds = [];
//top of the ground
let groundValue = 300;
let planted = 10;
function setup() {
createCanvas(600, 400);
background(169, 235, 232);
noStroke();
//title Scene
textAlign(CENTER)
textSize(50);
text("Garden Grow", width / 2, 200);
//start game
textSize(30);
text("Click level to Start Game", width / 2, 300);
//choose level
textSize(30);
text("Level", levelStart, 50);
//Need to figure out how to check the level pressed...P2
for (let l = 0; l < 3; l++) {
//level buttons
fill(255);
rect(levelStart + (l * 30) + 50, 30, levelButtonSize, levelButtonSize);
//level #
textSize(25);
fill(0);
text(l + 1, levelStart + l * 30 + 60, 50);
// if(mousePressed==true && and mouseX <=levelStart + (l * 30) + 50, 30, levelButtonSize, levelButtonSize){
// sceneNum=1;
// }
}
//set up veggies/plants/seeds
for (let i = 0; i < 5; i++) {
veggies[i] = new Veggie(i * (width - 50) / 5 + 40, 50);
seeds[i] = new Seed(i * (width - 50) / 5 + 40 + 17, 50);
plants[i] = new Plant(i * (width - 50) / 5 + 40 + 11, groundValue);
}
//tools needed to grow garden
for (let i = 0; i < 4; i++) {
tools[i] = new Tool(555, ((height - 170) / 4) * i + 70);
}
for (let i = 0; i < 10; i++) {
weeds[i] = new Weed(random(0, width - 80), groundValue);
}
}
function draw() {
switch (sceneNum) {
//Title page
case 0:
//console.log('scene 0');
break;
// plant seed
case 1:
//console.log('scene 1');
break;
// harvest
case 2:
//console.log('scene 2');
break;
// compost
case 3:
//console.log('scene 3');
break;
}
if (sceneNum == 1) {
//redraw backround
background(169, 235, 232);
//ground
fill(115, 71, 10);
rect(0, groundValue, width, 150);
// tool section
fill(210);
rect(540, 0, 540, height);
for (let i = 0; i < 5; i++) {
veggies[i].body();
// seeds[i].body();
// seeds[i].move();
// if (seeds[i].y > groundValue + planted) {
// //console.log(groundValue+planted);
// //console.log(seeds.y);
// for (let j = 0; j < 5; j++) {
// plants[i].body();
// plants[i].move();
// }
// }
// }
//trying to get the seeds plant on mousePressed, which then will grow the plants. not working yet - P0
if (mouseIsPressed==true) {
seeds[i].body();
seeds[i].move();
console.log(seeds.y);
if (seeds[i].y > groundValue + planted) {
//console.log(groundValue+planted);
//console.log(seeds.y);
for (let j = 0; j < 5; j++) {
plants[i].body();
plants[i].move();
}
}
}
}
for (let i = 0; i < 4; i++) {
tools[i].body();
}
for (let i = 0; i < 4; i++) {
weeds[i].body();
weeds[i].move();
}
}
}
class Veggie {
constructor(x, y) {
this.x = x;
this.y = y;
this.c = color(227, 43, 18);
this.d;
}
body() {
fill(this.c);
rect(this.x, this.y, 30, 20);
//distance calculator
this.d = dist(mouseX,mouseY,this.x,this.y);
if(this.d<20 && mouseIsPressed==true){
console.log(this.d);
}
}
}
class Tool {
constructor(x, y) {
this.x = x;
this.y = y;
this.c = color(104, 115, 114);
}
body() {
fill(this.c);
rect(this.x, this.y, 30, 20);
}
}
class Seed {
constructor(x, y) {
this.x = x;
this.y = y;
this.c = color(145, 78, 49);
this.d;
}
body() {
fill(this.c);
ellipse(this.x, this.y, 15, 10);
}
move() {
if (this.y <= groundValue + planted) {
this.y++;
}
}
}
class Plant {
constructor(x, y) {
this.x = x;
this.y = y;
this.c = color(12, 128, 9);
}
//can I make this grow instead dynamically? P0
body() {
fill(this.c);
rect(this.x, groundValue, 10, -50);
}
move() {
if (this.y < groundValue && this.y > 100) {
this.y--;
}
}
}
class Weed {
constructor(x, y) {
this.x = x;
this.y = y;
this.c = color(172, 232, 144);
}
body() {
fill(this.c);
rect(this.x, groundValue, 15, -20);
}
move() {
if (this.y < groundValue) {
this.y--;
}
}
// Work in process - do I need collison for the end of the canvas?
checkCollision() {
if (weed.y == 0) {
console.log('weeds grew too much!');
numScene = 0; // reset game
//growLives--;
}
}
}
//enter game - will change the command
function keyPressed() {
//sceneNum++
}
//planting - will change the command for final
function mousePressed(){
//seeds
//levels
// if (mouseX>=levelStart + (l * 30) + 50, 30 && mouseX<=levelStart + (l * 30) + 50+levelButtonSize, 50+levelButtonSize){
// level = 1;
// console.log(l);
// console.log(level);
// }
//sceneNum++
}