xxxxxxxxxx
306
let testVeggie;
let sceneNum = 0;
//position of the word Level
let levelStart = 50;
let levelButtonStart = 60;
let levelButtonSpacing = 30;
let levelButtonSize = 22;
let l;
//static for now to make it easier, but the goal would be for the level to be changed to add more plants and weeds to manage
let level = 0;
let veggies = [];
let veggieType = ['Tomato', 'Carrot', 'Garlic', 'Lettuce'];
let seedSizeX = 10;
let seedSizeY = 15;
let tools = [];
let toolType = ['Clippers', 'Compost', 'Water Can', 'Fingers'];
let toolActive = false;
let weeds = [];
let weedGrow = 1;
//top of the ground
let xMiddle = 300;
let groundValue = 300;
let groundMiddle = 350;
let planted = 10;
let plantGrow = 0;
function setup() {
createCanvas(600, 400);
rectMode(CENTER);
background(169, 235, 232);
noStroke();
//title Scene
textAlign(CENTER)
textSize(50);
text("Garden Grow", width / 2, 150);
//Description
textSize(30);
text("Take care of your garden", width / 2, 250);
textSize(30);
text("Watch the plants grow", width / 2, 280);
//start game
textSize(20);
text("Click level to Start Game", width / 2, 350);
//choose level
textSize(30);
text("Level", levelStart, 50);
//levels
for (let l = 0; l < 3; l++) {
//level buttons
fill(255);
rect(levelStart + (l * levelButtonSpacing) + levelButtonStart, 40, levelButtonSize, levelButtonSize);
//level #
textSize(25);
fill(0);
text(l + 1, levelStart + l * levelButtonSpacing + levelButtonStart, 50);
console.log(level);
}
// //set up veggies/plants/seeds
// testVeggie = new Veggie(100, 100, 'test');
//tools needed to grow garden
for (let i = 0; i < 4; i++) {
tools[i] = new Tool(555, ((height - 170) / 4) * i + 70, toolType[i]);
}
}
function draw() {
console.log(sceneNum);
switch (sceneNum) {
//Title page
case 0:
//console.log('scene 0');
break;
// clear weeds
case 1:
//console.log('scene 1');
break;
// clear weeds
case 2:
//console.log('scene 2');
break;
// plant / grow
case 3:
//console.log('scene 3');
break;
}
//select level
//distance for level 1 button
let levelDist1 = dist(mouseX, mouseY, levelStart + levelButtonSpacing + levelButtonStart / 2, 40);
//distance for level 2 button
let levelDist2 = dist(mouseX, mouseY, levelStart + 2 * levelButtonSpacing + levelButtonStart / 2, 40);
//distance for level 3 button
let levelDist3 = dist(mouseX, mouseY, levelStart + 3 * levelButtonSpacing + levelButtonStart / 2, 40);
//to select level and move to next scene
if (mouseIsPressed == true && sceneNum == 0) {
//change number of plants and weeds in the next level
if (levelDist1 < 10) {
level = 1;
weedLevel = 2;
} else if (levelDist2 < 10) {
level = 2;
weedLevel = 4;
} else if (levelDist3 < 10) {
level = 4;
weedLevel = 10;
} else {
return false;
}
//progress to scene 1 after clicking level
sceneNum = 1;
}
//scene 1 - get instructions for how to care for garden
if (sceneNum >= 1) {
//redraw backround
background(169, 235, 232);
// tool section
fill(210);
rect(570, height / 2, 100, height);
for (let i = 0; i < 4; i++) {
tools[i].body();
}
//ground
fill(115, 71, 10);
rect(xMiddle, groundMiddle, width, height - groundValue);
if (sceneNum == 1) {
textSize(20);
textAlign(CENTER);
let textStart = 50;
let textShift = 20;
text('Step 1: Prep the garden.', width / 2 - 50, textStart);
text('Remove weeds with clippers, add compost to soil', width / 2 - 50, textStart + textShift);
text('Step 2: Take care of the plants', width / 2 - 50, textStart + 4 * textShift);
text('Plant the seeds, water the plants and remove weeds', width / 2 - 50, textStart + 5 * textShift);
text('Step 3: Harvest the plants when they bloom', width / 2 - 50, textStart + 7 * textShift + textShift);
text('Use your fingers to pick veggies', width / 2 - 50, textStart + 8 * textShift + textShift);
//Note ---
fill(255);
textSize(25);
text("Remember: don't let the weeds get too high!", width / 2 - 50, height - 60);
textSize(20);
text("Click to begin", width / 2 - 50, height - 30);
}
}
//progress to scene 2 - weeds show up
if (mouseIsPressed == true && sceneNum == 1 && mouseY > 350) {
sceneNum = 2;
}
//weedGrow = random(10, 50);
console.log(sceneNum);
//weeds show up after clicking start from instructions
if (sceneNum == 2) {
// for (let i = 0; i < weedLevel; i++) {
// weedGrow = random(0,50);
// //console.log(i);
// weeds[i].body();
// }
//weeds that grow in the garden
// testWeed = new Weed(100,200);
for (let i = 0; i < 10; i++) {
let weedX = random(0, width - 100);
let weedY = random(50, 100);
//console.log(weedX);
weeds[i] = new Weed(weedX, groundValue - weedY);
}
}
//weeds growing - will switch the timer to
// if (millis() > 10000) {
// for (let i = 0; i < weedLevel; i++) {
// weeds[i].body();
// weedGrow = weedGrow--;
// //weeds[i].move();
// }
// }
// Work in process - how to make calculate weed height?
if (weedGrow > 350) {
console.log('weeds grew too much!');
numScene = 0; // reset game
}
}
class Tool {
constructor(x, y, t) { //only sets up once - STATIC
this.x = x;
this.y = y;
this.x1 = x;
this.y1 = y;
this.t = t;
this.c = color(104, 115, 114);
this.d; //continuous sensing of distance, not just once
this.toolGrabbed = false;
this.waterC = color(28, 120, 202);
this.waterX = x;
this.waterY = y;
this.waterPlant = false;
}
body() {
fill(this.c);
rect(this.x, this.y, 30, 20);
this.d = dist(mouseX, mouseY, this.x, this.y);
//Work in progress - set x,y back to original
if (toolActive == false && this.d < 40) {
if (mouseIsPressed == true) {
this.toolGrabbed = true;
toolActive = true;
} else {
this.toolGrabbed = false;
//this.x = this.x1;
//this.y = this.y1;
}
} else {
this.x = this.x1;
this.y = this.y1;
}
if (this.toolGrabbed == true) {
this.x = mouseX;
this.y = mouseY;
} else {
this.x = this.x1;
this.y = this.y1;
}
textSize(11);
text(this.t, this.x, this.y + 20);
}
}
class Weed {
constructor(x, y) {
this.x = x;
this.y;
this.c = color(172, 232, 144);
this.ySize;
this.centerY;
this.xSize = random(5, 15);
}
body() {
fill(this.c);
this.y = 2 * weedGrow;
this.centerY = groundValue - weedGrow;
rect(this.x, this.centerY, this.xSize, 2 * weedGrow);
}
}