JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
music pauses when game pauses and ends when game ends
[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 "float.h"
8 #include "mt.h"
9
10 struct dust_mote {
11         float x,y,z;
12         Uint16 color;
13 };
14
15 struct dust_mote motes[N_DUST_MOTES];
16
17 void
18 init_dust(void)
19 {
20         int i, b;
21         for(i=0; i<N_DUST_MOTES; i++) {
22                 motes[i].x = frnd()*(XSIZE-5);
23                 motes[i].y = frnd()*(YSIZE-5);
24                 motes[i].z = MAX_DUST_DEPTH*sqrt(frnd());
25                 b = (MAX_DUST_DEPTH - motes[i].z) * 255.0 / MAX_DUST_DEPTH;
26                 motes[i].color = SDL_MapRGB(surf_screen->format, b, b, b);
27         }
28 }
29
30 void
31 move_dust(void)
32 {
33         int i;
34         float xscroll = screendx * t_frame;
35         float yscroll = screendy * t_frame;
36         
37         for(i=0; i<N_DUST_MOTES; i++) {
38                 motes[i].x -= xscroll / (1.3 + motes[i].z);
39                 motes[i].x = fwrap(motes[i].x, XSIZE);
40
41                 motes[i].y -= yscroll / (1.3 + motes[i].z);
42                 motes[i].y = fwrap(motes[i].y, YSIZE);
43         }
44 }
45
46 void
47 draw_dust(void)
48 {
49         int i;
50         uint16_t *pixels = surf_screen->pixels;
51         for(i=0; i<N_DUST_MOTES; i++) {
52                 pixels[surf_screen->pitch/2*(int)motes[i].y + (int)motes[i].x] = motes[i].color;
53         }
54 }