1 #include "SDL2_particles.h"
3 void basic_particle_init(particle_t
*p
)
9 void basic_particle_move(particle_t
*p
)
13 //Sint32 ttl = p->ttl--;
14 //Uint8 size = p->size;
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
;
27 void basic_particle_reset(particle_t
*p
)
32 p
->ttl
= 20 + rand() % 100;
34 p
->ang
= 45 + rand() % 90 ;
39 p
->ttl
= rand() % 80 ;//+ rand() % 20;
41 p
->ang
= rand() % 30 - 90 - 15;
46 void PS_Update(particle_system
*ps
) {
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
]);
58 if (done
>= PARTICLES_PER_SYSTEM
) {
63 void PS_Render(SDL_Renderer
*target
, particle_system
*ps
, SDL_Color
*colors
, int num_colors
, Uint32 bx
, Uint32 by
) {
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;
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
);