1 | /* |
---|
2 | * ttyvaders Textmode shoot'em up |
---|
3 | * Copyright (c) 2002 Sam Hocevar <sam@zoy.org> |
---|
4 | * All Rights Reserved |
---|
5 | * |
---|
6 | * $Id: starfield.c,v 1.4 2002/12/22 18:44:12 sam Exp $ |
---|
7 | * |
---|
8 | * This program is free software; you can redistribute it and/or modify |
---|
9 | * it under the terms of the GNU General Public License as published by |
---|
10 | * the Free Software Foundation; either version 2 of the License, or |
---|
11 | * (at your option) any later version. |
---|
12 | * |
---|
13 | * This program is distributed in the hope that it will be useful, |
---|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
16 | * GNU General Public License for more details. |
---|
17 | * |
---|
18 | * You should have received a copy of the GNU General Public License |
---|
19 | * along with this program; if not, write to the Free Software |
---|
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
21 | */ |
---|
22 | |
---|
23 | #include <stdlib.h> |
---|
24 | |
---|
25 | #include "common.h" |
---|
26 | |
---|
27 | void init_starfield( game *g, starfield *s ) |
---|
28 | { |
---|
29 | int i; |
---|
30 | |
---|
31 | for( i = 0; i < STARS; i++ ) |
---|
32 | { |
---|
33 | s->x[i] = rand() % g->w; |
---|
34 | s->y[i] = rand() % g->h; |
---|
35 | s->z[i] = 1 + rand() % 3; |
---|
36 | s->ch[i] = (rand() % 2) ? '.' : '\''; |
---|
37 | s->c[i] = 6 + rand() % 2; |
---|
38 | } |
---|
39 | } |
---|
40 | |
---|
41 | void draw_starfield( game *g, starfield *s ) |
---|
42 | { |
---|
43 | int i; |
---|
44 | |
---|
45 | for( i = 0; i < STARS; i++ ) |
---|
46 | { |
---|
47 | if( s->x[i] >= 0 ) |
---|
48 | { |
---|
49 | gfx_color( s->c[i] ); |
---|
50 | gfx_goto( s->x[i], s->y[i] ); |
---|
51 | gfx_putchar( s->ch[i] ); |
---|
52 | } |
---|
53 | } |
---|
54 | } |
---|
55 | |
---|
56 | void update_starfield( game *g, starfield *s ) |
---|
57 | { |
---|
58 | int i; |
---|
59 | |
---|
60 | for( i = 0; i < STARS; i++ ) |
---|
61 | { |
---|
62 | if( s->x[i] < 0 ) |
---|
63 | { |
---|
64 | s->x[i] = rand() % g->w; |
---|
65 | s->y[i] = 0; |
---|
66 | s->z[i] = 1 + rand() % 2; |
---|
67 | s->ch[i] = (rand() % 2) ? '.' : '\''; |
---|
68 | s->c[i] = 6 + rand() % 2; |
---|
69 | } |
---|
70 | else if( s->y[i] < g->h-1 ) |
---|
71 | { |
---|
72 | s->y[i] += s->z[i]; |
---|
73 | } |
---|
74 | else |
---|
75 | { |
---|
76 | s->x[i] = -1; |
---|
77 | } |
---|
78 | } |
---|
79 | } |
---|
80 | |
---|