Update oddball6x8 font.
[runemen.git] / src / SDL2_particles.c
blobccbee2ccb39a0e75c517c2d7e17d2636846076f2
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->ttl--;
22 p->x = nx;
23 p->y = ny;
24 x = nx;
25 y = ny;
27 void basic_particle_reset(particle_t *p)
29 #if 0
30 p->x = rand() % 120;
31 p->y = rand() % 120;
32 p->ttl = 20 + rand() % 100;
33 p->spd = 1;
34 p->ang = 45 + rand() % 90 ;
35 p->size = 2;
36 #else
37 p->x = 0;
38 p->y = 0;
39 p->ttl = rand() % 80 ;//+ rand() % 20;
40 p->spd = 1;
41 p->ang = rand() % 30 - 90 - 15;
42 p->size = 2;
43 #endif
46 void PS_Update(particle_system *ps) {
47 int i;
48 int done = 0;
49 for (i = 0; i < PARTICLES_PER_SYSTEM; i++) {
50 ps->move(&ps->particle[i]);
51 if (ps->particle[i].ttl <= 0) {
52 if (ps->spawn < ps->limit) {
53 ps->reset(&ps->particle[i]);
54 ps->spawn++;
55 } else done++;
58 if (done >= PARTICLES_PER_SYSTEM) {
59 ps->limit = 0;
63 void PS_Render(SDL_Renderer *target, particle_system *ps, SDL_Color *colors, int num_colors, Uint32 bx, Uint32 by) {
65 int i, j;
66 int colorquant = PARTICLES_PER_SYSTEM / num_colors;
67 for (i = 0; i < PARTICLES_PER_SYSTEM; i++) {
68 Uint32 x = ps->particle[i].x;
69 Uint32 y = ps->particle[i].y;
70 Sint32 ttl = ps->particle[i].ttl--;
71 //Uint8 size = ps->particle[i].size;
72 if (ttl <= 0) continue;
73 j = i % colorquant;
74 //Uint32 color = SDL_MapRGB(surface->format, reds[j].r, reds[j].g, reds[j].b);
75 //-//SDL_AlphaFill(surface, bx + x, by + y, size, size, color);
76 //-SDL_PutPixel(surface, bx + x, by + y, color+ttl);
77 SDL_SetRenderDrawColor(target, colors[j].r, colors[j].g, colors[j].b, 0);
78 SDL_RenderDrawPoint(target, bx + x, by + y);