forked from carykh/Utopia
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGut.pde
More file actions
57 lines (54 loc) · 1.44 KB
/
Gut.pde
File metadata and controls
57 lines (54 loc) · 1.44 KB
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
class Gut{
float[] location;
int when;
int PIECES = 5;
float[][] pieces_coor;
int DURATION = 60;
int species;
public Gut(float[] L, int w, int s){
location = L;
when = w;
species = s;
pieces_coor = new float[PIECES][6];
for(int p = 0; p < PIECES; p++){
float angle = random(0,2*PI);
float dist = random(3,7);
float vx = dist*cos(angle);
float vy = dist*sin(angle);
float vz = random(7,15);
float[] coor = {L[0]+vx,L[1]+vy,L[2]+vz,vx,vy,vz};
pieces_coor[p] = coor;
}
}
void doPhysics(){
float FAC = 0.7; // bouncing factor
for(int p = 0; p < PIECES; p++){
float[] coor = pieces_coor[p];
coor[5] -= 1; // gravity
for(int dim = 0; dim < 3; dim++){
coor[dim] += coor[dim+3];
}
float ground = map.getGroundLevel(coor);
if(coor[2] <= ground){
coor[2] = ground;
coor[3] *= FAC;
coor[4] *= FAC;
coor[5] = abs(coor[5])*FAC; // bouncing guts
}
}
}
void drawGut(){
float size = 1-(float)(ticks-when)/DURATION;
g.fill(SPECIES_COLORS[species]);
for(int p = 0; p < PIECES; p++){
float[] c = pieces_coor[p];
g.pushMatrix();
g.translate(unloop_two(c[0],camera[0]),unloop_two(c[1],camera[1]),c[2]);
g.sphere(12*size);
g.popMatrix();
}
}
boolean toDie(){
return (ticks-when >= DURATION);
}
}