JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
refactoring towards sprites, updated todo
[vor.git] / dust.c
1 #include <SDL.h>
2 #include <math.h>
3
4 #include "config.h"
5 #include "globals.h"
6 #include "dust.h"
7 #include "mt.h"
8
9 struct dust_mote {
10         float x,y,z;
11         Uint16 color;
12 };
13
14 struct dust_mote motes[N_DUST_MOTES];
15
16 void
17 init_dust(void)
18 {
19         int i, b;
20         for(i=0; i<N_DUST_MOTES; i++) {
21                 motes[i].x = frnd()*(XSIZE-5);
22                 motes[i].y = frnd()*(YSIZE-5);
23                 motes[i].z = MAX_DUST_DEPTH*sqrt(frnd());
24                 b = (MAX_DUST_DEPTH - motes[i].z) * 255.0 / MAX_DUST_DEPTH;
25                 motes[i].color = SDL_MapRGB(surf_screen->format, b, b, b);
26         }
27 }
28
29 void
30 move_dust(void)
31 {
32         int i;
33         for(i=0; i<N_DUST_MOTES; i++) {
34                 motes[i].x -= xscroll / (1.3 + motes[i].z);
35                 motes[i].y -= yscroll / (1.3 + motes[i].z);
36                 if(motes[i].y >= XSIZE) motes[i].x -= XSIZE;
37                 else if(motes[i].x < 0) motes[i].x += XSIZE;
38                 if(motes[i].y > YSIZE) motes[i].y -= YSIZE;
39                 else if(motes[i].y < 0) motes[i].y += YSIZE;
40         }
41 }
42
43 void
44 draw_dust(SDL_Surface *s)
45 {
46         int i;
47         uint16_t *pixels = s->pixels;
48         for(i=0; i<N_DUST_MOTES; i++) {
49                 pixels[s->pitch/2*(int)motes[i].y + (int)motes[i].x] = motes[i].color;
50         }
51 }