forked from APCSLowell/Chemotaxis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChemotaxis.pde
164 lines (149 loc) · 3.87 KB
/
Chemotaxis.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
PImage img, img2, img3;
Walker [] oldPplHome = new Walker [20];
int mySizeX = 100;
int mySizeY = 75;
int time = 0;
int time2 = 0;
int time3 = 0;
boolean eaten1 = false;
boolean eaten2 = false;
boolean eaten3 = false;
boolean eaten4 = false;
float health = 3;
color c1 = color(255, 255, 255);
void setup() {
size(1000, 1000);
frameRate(100);
img = loadImage("Pizza_Full.png");
img2= loadImage("Pizza_Half.png");
img3= loadImage("Pizza_fourth.png");
for (int i=0; i<20; i++) {
oldPplHome[i] = new Walker();
}
}
void draw() {
background(59, 183, 237);
textSize(50);
fill(255);
noStroke();
text( "Time Survived: "+millis()/1000, 16, 55);
text("Lives:",694,54);
image(img, 894, 12, 41,40);
image(img, 942, 12, 41,40);
image(img, 846, 12, 41,40);
for (int i = 0; i < oldPplHome.length; i++) { //choosing between each type of pizza
if (eaten1==false&&eaten2==false) { //if both "bites" are false
image(img, mouseX-20, mouseY-20, 41, 40);
}
if (dist(oldPplHome[i].myX, oldPplHome[i].myY, mouseX, mouseY) <= 20 && eaten1==false) {
eaten1=true;
time = millis();
health=3;
}
if (eaten1 == true && eaten2 == false) {
image(img2, mouseX-20, mouseY-20, 41, 40);
fill(59, 183, 237);
rect( 846, 12, 41,40);
//rect( 894, 12, 41,40);
//rect(942, 12, 41,40);
}
if (dist(oldPplHome[i].myX, oldPplHome[i].myY, mouseX, mouseY) <= 20 && eaten1==true && millis()-time>=4000 && eaten2 == false) {
eaten2=true;
time2 = millis();
health =2;
}
if (eaten2 == true && eaten3 == false) {
image(img3, mouseX-20, mouseY-20, 41, 40);
fill(59, 183, 237);
rect( 846, 12, 41,40);
rect( 894, 12, 41,40);
}
}
for (int i = 0; i< 20; i++) { //blob walks and shows
oldPplHome[i].walk();
oldPplHome[i].show();
}
for (int i = 0; i < oldPplHome.length; i++) {
if (dist(oldPplHome[i].myX, oldPplHome[i].myY, mouseX, mouseY) <= 20 && eaten2==true && millis()-time2>=4000) {
eaten3=true;
}
if (eaten3 == true) {
noLoop();
background(0);
fill(255);
text("GAME OVER", 350, 500, 500);
text("You Survived " +millis()/1000+ " Seconds!", 200,50,50);
}
}
for (int i = 0; i < oldPplHome.length; i++) {
if (dist(oldPplHome[i].myX, oldPplHome[i].myY, mouseX, mouseY) <= 20) { //blob expands
oldPplHome[i].expands();
oldPplHome[i].random = 6;
}
}
//for (int i = 0; i < oldPplHome.length; i++) {
// if (dist(oldPplHome[i].myX, oldPplHome[i].myY, mouseX, mouseY) <= 20 || eaten1==true && time>=3000) { //if it eats again, eaten2 == true;
// eaten2=true;
//}
// if (dist(oldPplHome[i].myX, oldPplHome[i].myY, mouseX, mouseY) <= 20 && (millis()-time) >= 3000) {
//oldPplHome[i].expands();
// oldPplHome[i].random = 6;
// }
// }
//}
}
class Walker
{
int myX, myY;
float x, y;
float random;
Walker()
{
myX=(int)(Math.random()*1000);
myY=(int)(Math.random()*1000);
x=30;
y=30;
random=4;
}
void walk()
{
if (mouseX>=myX) {
myX=myX+(int)(Math.random()*random);
} else {
myX-=(int)(Math.random()*random);
}
if (myY<0) {
myY=0;
}
if (mouseY>myY) {
myY=myY+(int)(Math.random()*random);
} else {
myY-=(int)(Math.random()*random);
}
if (myY<0) {
myY=0;
}
random*=1.0009;
}
void show()
{
fill(c1);
strokeWeight(2);
ellipse(myX, myY, x, y);
}
void expands() {
for (int i = 0; i < oldPplHome.length; i++) {
if (dist(oldPplHome[i].myX, oldPplHome[i].myY, mouseX, mouseY) <= 20) {
x+=1;
y+=1;
}
if (x>100) {
x=100;
}
if (y>100) {
y=100;
}
c1-=2;
}
}
}