-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDust.pde
executable file
·104 lines (88 loc) · 1.75 KB
/
Dust.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
class Dust
{
float x, y;
float velX, velY;
int type;
float angle, gyro;
boolean active;
int timeLeft;
Dust(float x, float y, float velX, float velY, int type)
{
this.x = x;
this.y = y;
this.velX = velX;
this.velY = velY;
this.type = type;
if(type == 1)
{
angle = random(TWO_PI);
gyro = random(1);
timeLeft = 90;
}
else
{
timeLeft = 30;
}
active = true;
}
void update()
{
if(active)
{
handleMovement();
display();
timeLeft--;
if(timeLeft <= 0)
active = false;
}
}
void handleMovement() //Counting rotation as movement so the name of this method isn't wrong
{
x += velX;
y += velY;
angle += gyro;
}
void display()
{
switch(type)
{
case 0: //Particles
ellipseMode(CENTER);
noStroke();
fill(255);
ellipse(x, y, 4, 4);
break;
case 1: //Lines - Can use on player death to look like player's broken apart
stroke(255);
noFill();
float[] pts = getPoints();
line(pts[0], pts[1], pts[2], pts[3]);
break;
}
}
float[] getPoints()
{
float[] pts = new float[4];
pts[0] = (20 * cos(angle)) + x; //x1
pts[1] = (20 * sin(angle)) + y; //y1
pts[2] = (-20 * cos(angle)) + x; //x2
pts[3] = (-20 * sin(angle)) + y; //y2
return pts;
}
void reset(float x, float y, float velX, float velY, int type)
{
this.x = x;
this.y = y;
this.velX = velX;
this.velY = velY;
this.type = type;
if(type == 1)
{
angle = random(TWO_PI);
gyro = random(1);
timeLeft = 150;
}
timeLeft = 45;
active = true;
}
}