Update Makefile.
[runemen.git] / src / SDL2_particles.c
blob22007180fdc837537cf2b34fe0e894d84e618dd1
1 #include "SDL2_particles.h"
3 void basic_particle_init(particle_t *p)
5 p->x = 0;
6 p->y = 0;
9 void basic_particle_move(particle_t *p)
11 float x = p->x;
12 float y = p->y;
13 Sint32 ttl = p->ttl--;
14 Uint8 size = p->size;
15 float spd = p->spd;
16 float a = p->ang;
17 float c = cosf(a * M_PI / 180);
18 float s = sinf(a * M_PI / 180);
19 float nx = x + spd * c;
20 float ny = y + spd * s;
21 p->x = nx;
22 p->y = ny;
23 x = nx;
24 y = ny;
26 void basic_particle_reset(particle_t *p)
28 #if 0
29 p->x = rand() % 120;
30 p->y = rand() % 120;
31 p->ttl = 20 + rand() % 100;
32 p->spd = 1;
33 p->ang = 45 + rand() % 90 ;
34 p->size = 2;
35 #else
36 p->x = 0;
37 p->y = 0;
38 p->ttl = rand() % 80 ;//+ rand() % 20;
39 p->spd = 1;
40 p->ang = rand() % 30 - 90 - 15;
41 p->size = 2;
42 #endif
45 void PS_Update(particle_system *ps) {
46 int i;
47 int done = 0;
48 for (i = 0; i < PARTICLES_PER_SYSTEM; i++) {
49 ps->move(&ps->particle[i]);
50 if (ps->particle[i].ttl <= 0) {
51 if (ps->spawn < ps->limit) {
52 ps->reset(&ps->particle[i]);
53 ps->spawn++;
54 } else done++;
57 if (done >= PARTICLES_PER_SYSTEM) {
58 ps->limit = 0;
62 void PS_Render(SDL_Renderer *target, particle_system *ps, SDL_Color *colors, int num_colors, Uint32 bx, Uint32 by) {
64 int i, j;
65 int colorquant = PARTICLES_PER_SYSTEM / num_colors;
66 for (i = 0; i < PARTICLES_PER_SYSTEM; i++) {
67 Uint32 x = ps->particle[i].x;
68 Uint32 y = ps->particle[i].y;
69 Sint32 ttl = ps->particle[i].ttl--;
70 Uint8 size = ps->particle[i].size;
71 if (ttl <= 0) continue;
72 j = i % colorquant;
73 //Uint32 color = SDL_MapRGB(surface->format, reds[j].r, reds[j].g, reds[j].b);
74 //-//SDL_AlphaFill(surface, bx + x, by + y, size, size, color);
75 //-SDL_PutPixel(surface, bx + x, by + y, color+ttl);
76 SDL_SetRenderDrawColor(target, colors[j].r, colors[j].g, colors[j].b, 0);
77 SDL_RenderDrawPoint(target, bx + x, by + y);