source: ttyvaders/trunk/starfield.c @ 12

Last change on this file since 12 was 12, checked in by Sam Hocevar, 20 years ago
  • First commit. Scrolling works, some weaponry, controls, tunnel blowing, the nuke is still ugly, almost no collision detection. Nice demo :)
File size: 1.1 KB
Line 
1
2#include <stdlib.h>
3
4#include "common.h"
5
6void init_starfield( game *g, starfield *s )
7{
8    int i;
9
10    for( i = 0; i < STARS; i++ )
11    {
12        s->x[i] = rand() % g->w;
13        s->y[i] = rand() % g->h;
14        s->z[i] = 1 + rand() % 3;
15        s->ch[i] = (rand() % 2) ? '.' : '\'';
16        s->c[i] = 6 + rand() % 2;
17    }
18}
19
20void draw_starfield( game *g, starfield *s )
21{
22    int i;
23
24    for( i = 0; i < STARS; i++ )
25    {
26        if( s->x[i] >= 0 )
27        {
28            GFX_COLOR( s->c[i] );
29            GFX_GOTO( s->x[i], s->y[i] );
30            GFX_WRITE( s->ch[i] );
31        }
32    }
33}
34
35void update_starfield( game *g, starfield *s )
36{
37    int i;
38
39    for( i = 0; i < STARS; i++ )
40    {
41        if( s->x[i] < 0 )
42        {
43            s->x[i] = rand() % g->w;
44            s->y[i] = 0;
45            s->z[i] = 1 + rand() % 2;
46            s->ch[i] = (rand() % 2) ? '.' : '\'';
47            s->c[i] = 6 + rand() % 2;
48        }
49        else if( s->y[i] < g->h-1 )
50        {
51            s->y[i] += s->z[i];
52        }
53        else
54        {
55            s->x[i] = -1;
56        }
57    }
58}
59
Note: See TracBrowser for help on using the repository browser.