source: ttyvaders/trunk/src/starfield.c @ 28

Last change on this file since 28 was 20, checked in by Sam Hocevar, 18 years ago
  • real Debian package files.
  • two new types of aliens. only one rules.
  • removed gfx_write in favor of gfx_putchar and gfx_putstr.
  • added bonuses at alien death. they do nothing yet.
  • seeker missiles. 'b' to test.
  • weapon resolution is now 16*char. needs to be generalized.
  • fixed the supernova bugs. center could collide with the tunnel, and the last frame was badly displayed.
  • lots of cleanups everywhere.
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_putchar( 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.