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 87 2003-11-09 13:16:19Z sam $ |
---|
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 | starfield * create_starfield(game *g) |
---|
28 | { |
---|
29 | int i; |
---|
30 | starfield *s; |
---|
31 | |
---|
32 | s = malloc(STARS * sizeof(starfield)); |
---|
33 | |
---|
34 | for(i = 0; i < STARS; i++) |
---|
35 | { |
---|
36 | s[i].x = GET_RAND(0, g->w); |
---|
37 | s[i].y = GET_RAND(0, g->h); |
---|
38 | s[i].z = GET_RAND(1, 4); |
---|
39 | s[i].c = GET_RAND(6, 8); |
---|
40 | s[i].ch = GET_RAND(0, 2) ? '.' : '\''; |
---|
41 | } |
---|
42 | |
---|
43 | return s; |
---|
44 | } |
---|
45 | |
---|
46 | void draw_starfield(game *g, starfield *s) |
---|
47 | { |
---|
48 | int i; |
---|
49 | |
---|
50 | for(i = 0; i < STARS; i++) |
---|
51 | { |
---|
52 | if(s[i].x >= 0) |
---|
53 | { |
---|
54 | ee_color(s[i].c); |
---|
55 | ee_goto(s[i].x, s[i].y); |
---|
56 | ee_putchar(s[i].ch); |
---|
57 | } |
---|
58 | } |
---|
59 | } |
---|
60 | |
---|
61 | void update_starfield(game *g, starfield *s) |
---|
62 | { |
---|
63 | int i; |
---|
64 | |
---|
65 | for(i = 0; i < STARS; i++) |
---|
66 | { |
---|
67 | if(s[i].x < 0) |
---|
68 | { |
---|
69 | s[i].x = GET_RAND(0, g->w); |
---|
70 | s[i].y = 0; |
---|
71 | s[i].z = GET_RAND(1, 3); |
---|
72 | s[i].c = GET_RAND(6, 8); |
---|
73 | s[i].ch = GET_RAND(0, 2) ? '.' : '\''; |
---|
74 | } |
---|
75 | else if(s[i].y < g->h-1) |
---|
76 | { |
---|
77 | s[i].y += s[i].z; |
---|
78 | } |
---|
79 | else |
---|
80 | { |
---|
81 | s[i].x = -1; |
---|
82 | } |
---|
83 | } |
---|
84 | } |
---|
85 | |
---|
86 | void free_starfield(game *g, starfield *s) |
---|
87 | { |
---|
88 | free(s); |
---|
89 | } |
---|
90 | |
---|