-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathWheat.pde
96 lines (83 loc) · 2.19 KB
/
Wheat.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
class Wheat extends Plant {
// Fields
int stemLength;
int stemThickness;
int leafNum;
// Constructor
Wheat(String name) {
super(name);
this.name = name;
this.lifespan = 400;
this.dying = false;
this.rangeS = 4;
this.rangeF = 4;
this.rangeW = 4;
this.growthFactor = 0.1;
this.leafNum = 0;
this.leaves = new ArrayList<Leaf>();
}
// Render and grow plant
void grow() {
// Name of plant
textSize(32);
fill(255);
text(name, 40, 60);
// Plant dying instances
if(!dying && time != 0) {
if (f > 4 && s < 1 && w < 1){
death();
}
else if (w > 4 && s < 1){
death();
}
else if (s > 4 && w < 1){
death();
}
}
// Attributes based on dying or not
if(dying) {
time = lifespan*2-time;
foliage = color(127, 127, 0);
flowerFoliage = color(191, 191, 0);
} else {
foliage = color(151, 135, 12);
flowerFoliage = color(255,255,0);
}
// Render and create new leaves
if(stemLength > (leafNum+1)*50) {
leaves.add(new Leaf(midX,groundLevel-(leafNum+1)*50,-2*PI/6,0.3,this));
leaves.add(new Leaf(midX,groundLevel-(leafNum+1)*50,-5*PI/6,0.3,this));
leaves.add(new Leaf(midX,groundLevel-(leafNum+1)*50,-6*PI/6,0.3,this));
leafNum++;
}
for(int i = 0; i < leaves.size(); i++) {
leaves.get(i).grow();
}
// Render stem and flower
stemLength = time;
stemThickness = 2+(time/70);
fill(foliage);
rect(midX-stemThickness,groundLevel,stemThickness,-stemLength);
// Check to see if plant has ceased to exist
if(dying) {
if(time <= 0) {
//plants.remove(plants.indexOf(this));
plants[plantIndex] = null;
}
time = lifespan*2-time;
}
// Only grow based on environment if living
if(time < lifespan){
exactTime += growth();
} else if(dying) {
exactTime++;
}
// exactTime is used to keep a more percise value of time, in case values less than 1 are added
time = round(exactTime);
}
// Called when the plant starts dying
void death() {
lifespan = time;
dying = true;
}
}