-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathParticle.c
More file actions
147 lines (124 loc) · 2.85 KB
/
Particle.c
File metadata and controls
147 lines (124 loc) · 2.85 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
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
#include <math.h>
#include <SDL/SDL.h>
#include "Entity.h" // for time singleton
#include "Draw.h"
#include "Particle.h"
#define ICE_PARTICLE_TIMEOUT 500
// Master list of all particles in motion
Particle* particleList = NULL; // set to NULL when uninitalized
int initalizeParticleList()
{
if (particleList != NULL)
{
return 1;
}
particleList = (Particle*)calloc(PARTICLE_LIST_MAX_SIZE, sizeof(Particle));
if (particleList == NULL)
{
return 0;
}
return 1;
}
void freeParticleList()
{
free(particleList);
particleList = NULL;
}
void updateParticles()
{
int i;
for (i = 0; i < PARTICLE_LIST_MAX_SIZE; i++)
{
if (particleList[i].type == NONE)
{
continue;
}
if (particleList[i].x > SCREEN_WIDTH - 3 || particleList[i].x < 1 || particleList[i].y > SCREEN_HEIGHT - 3 || particleList[i].y < 3)
{
particleList[i].type = NONE;
continue;
}
if (particleList[i].type == FIRE)
{
Uint32 delta = (getTimeSingleton() - particleList[i].startTime);
particleList[i].xVelo = (float)(3*sin(delta));
}
if (particleList[i].type == TELESPARK)
{
Uint32 delta = (getTimeSingleton() - particleList[i].startTime)/100;
particleList[i].x += particleList[i].xVelo;
particleList[i].y += (delta + exp(0.20 * delta) * sin(10.0 * delta)) * particleList[i].yVelo/2.0f;
}
else
{
particleList[i].x += particleList[i].xVelo;
particleList[i].y += particleList[i].yVelo;
}
//update any logic necessary
switch(particleList[i].type)
{
case TELESPARK:
case ICE:
if (getTimeSingleton() - particleList[i].startTime > 250)
{
particleList[i].type = NONE;
}
break;
case BLOOD:
case SWEAT:
particleList[i].yVelo += 0.4f;
if (getTimeSingleton() - particleList[i].startTime > 200)
{
particleList[i].type = NONE;
}
break;
case HEALTHSPARK:
case MUD:
if (getTimeSingleton() - particleList[i].startTime > 100)
{
particleList[i].type = NONE;
}
break;
case LIFETEXT:
if (getTimeSingleton() - particleList[i].startTime > 175)
{
particleList[i].type = NONE;
}
break;
case FIRE:
if (getTimeSingleton() - particleList[i].startTime > 350)
{
particleList[i].type = NONE;
}
break;
default:
break;
}
}
}
int pushParticle(ParticleType p, float newX, float newY, float newXSpeed, float newYSpeed)
{
int i;
for (i = 0; i < PARTICLE_LIST_MAX_SIZE; i++)
{
if (particleList[i].type != NONE)
{
continue;
}
else
{
particleList[i].type = p;
particleList[i].x = newX;
particleList[i].y = newY;
particleList[i].xVelo = newXSpeed;
particleList[i].yVelo = newYSpeed;
particleList[i].startTime = getTimeSingleton();
return 1;
}
}
return 0;
}
Particle* getParticleList()
{
return particleList;
}