-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparticle.wl
82 lines (71 loc) · 1.51 KB
/
particle.wl
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
use "importc"
import(C) "/usr/include/stdlib.h"
import(C) "/usr/include/stdio.h"
import(C) "/usr/include/SDL/SDL.h"
import "halo.wl"
import "main.wl"
import "list.wl"
struct Particle
{
float x
float y
float vx
float vy
uint timeout
}
List^ frag_list = null
Particle^ particle_new(float x, float y, float vx, float vy)
{
Particle^ p = malloc(32)
p.x = x
p.y = y
p.vx = vx
p.vy = vy
float r = rand()
r = r / float: RAND_MAX
p.timeout = 150 * r
return p
}
void particle_init()
{
if(frag_list == null)
{
frag_list = list_new()
}
}
void frag_new(float x, float y)
{
float rx = rand()
float ry = rand()
rx = ((rx / float: RAND_MAX) * 1.0) - 0.5
ry = 0.0 - (ry / float: RAND_MAX) * 1.0 - 0.5
Particle ^p = particle_new(x, y, rx, ry)
list_add(frag_list, p)
}
void frag_update()
{
list_begin(frag_list)
while(!list_end(frag_list))
{
Particle^ p = list_get(frag_list)
p.x = p.x + p.vx
p.y = p.y + p.vy
p.timeout--
if(p.timeout == 0) list_remove(frag_list)
list_next(frag_list)
}
}
void frag_draw(SDL_Surface ^su, SDL_Surface^ lit)
{
list_begin(frag_list)
while(!list_end(frag_list))
{
Particle^ p = list_get(frag_list)
uint cval = 128 + (128 << 8) + (200 << 16) + (150 << 24)
setPixel(su, p.x, p.y, cval)
//light
//setPixel(lit, p.x, p.y, lval)
halo_draw(lit, 1, p.x, p.y)
list_next(frag_list)
}
}