-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParticle.cpp
122 lines (102 loc) · 1.54 KB
/
Particle.cpp
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
#include "Particle.h"
Particle::Particle()
{
mRect = { 0, 0, 0, 0 };
mForce = 1;
mAngle = 0;
mColor = { 0, 0, 0 };
mAlpha = 255;
mInitForce = 0;
mStartTime = SDL_GetTicks();
}
Particle::~Particle()
{
mRect = { 0, 0, 0, 0 };
mForce = 1;
mAngle = 0;
mColor = { 0, 0, 0 };
mAlpha = 0;
mStartTime = 0;
}
void Particle::setImpulse(int angle, int force)
{
mAngle = angle;
mForce = force;
mInitForce = force;
mDelay = 1000 / (double) force;
}
void Particle::setRect(SDL_Rect r)
{
mRect.x = r.x;
mRect.y = r.y;
mRect.w = r.w;
mRect.h = r.h;
}
void Particle::setColor(SDL_Color c)
{
mColor = c;
}
void Particle::setAlpha(int alpha)
{
mAlpha = alpha;
}
void Particle::modAlpha(int amt)
{
mAlpha += amt;
}
void Particle::move()
{
SDL_Point p;
p.x = mRect.x + (mForce * sin(mAngle * 3.14 / 180.0));
p.y = mRect.y + (mForce * -cos(mAngle * 3.14 / 180.0));
mRect.x = p.x;
mRect.y = p.y;
if (mForce > 1) {
mForce -= 1;
}
//if (mForce <= 0) {
//mForce = 1;
//}
if (mAngle > 180.0) {
mAngle -= 1 * (10 / mForce);
}
else if (mAngle < 180.0) {
mAngle += 1 * (10 / mForce);
}
}
SDL_Rect Particle::getRect()
{
return mRect;
}
SDL_Color Particle::getColor()
{
return mColor;
}
int Particle::getAngle()
{
return mAngle;
}
int Particle::getForce()
{
return mForce;
}
int Particle::getAlpha()
{
return mAlpha;
}
int Particle::getInitForce()
{
return mInitForce;
}
Uint32 Particle::getStartTime()
{
return mStartTime;
}
void Particle::resetTime()
{
mStartTime = SDL_GetTicks();
}
Uint32 Particle::getDelay()
{
return mDelay;
}