JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
removed ship fade in code (unused)
[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         float xscroll = screendx * t_frame;
34         float yscroll = screendy * t_frame;
35         for(i=0; i<N_DUST_MOTES; i++) {
36                 motes[i].x -= xscroll / (1.3 + motes[i].z);
37                 motes[i].y -= yscroll / (1.3 + motes[i].z);
38                 if(motes[i].y >= XSIZE) motes[i].x -= XSIZE;
39                 else if(motes[i].x < 0) motes[i].x += XSIZE;
40                 if(motes[i].y > YSIZE) motes[i].y -= YSIZE;
41                 else if(motes[i].y < 0) motes[i].y += YSIZE;
42         }
43 }
44
45 void
46 draw_dust(SDL_Surface *s)
47 {
48         int i;
49         uint16_t *pixels = s->pixels;
50         for(i=0; i<N_DUST_MOTES; i++) {
51                 pixels[s->pitch/2*(int)motes[i].y + (int)motes[i].x] = motes[i].color;
52         }
53 }