1 | /* |
---|
2 | * ttyvaders Textmode shoot'em up |
---|
3 | * Copyright (c) 2002 Sam Hocevar <sam@zoy.org> |
---|
4 | * All Rights Reserved |
---|
5 | * |
---|
6 | * $Id: tarass |
---|
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 <stdio.h> |
---|
24 | #include <stdlib.h> |
---|
25 | |
---|
26 | #include <string.h> |
---|
27 | #include <unistd.h> |
---|
28 | |
---|
29 | #include "common.h" |
---|
30 | |
---|
31 | static void start_game (game *); |
---|
32 | |
---|
33 | int main (int argc, char **argv) |
---|
34 | { |
---|
35 | game *g = malloc(sizeof(game)); |
---|
36 | |
---|
37 | //srand(time(NULL)); |
---|
38 | |
---|
39 | if( init_graphics() ) |
---|
40 | { |
---|
41 | return 1; |
---|
42 | } |
---|
43 | |
---|
44 | /* Initialize our program */ |
---|
45 | init_game(g); |
---|
46 | |
---|
47 | /* Go ! */ |
---|
48 | start_game(g); |
---|
49 | |
---|
50 | /* Clean up */ |
---|
51 | end_graphics(); |
---|
52 | |
---|
53 | return 0; |
---|
54 | } |
---|
55 | |
---|
56 | static void start_game (game *g) |
---|
57 | { |
---|
58 | int i; |
---|
59 | int quit = 0; |
---|
60 | int poz = 0; |
---|
61 | int skip = 0; |
---|
62 | int purcompteur = 0; |
---|
63 | |
---|
64 | g->sf = malloc(sizeof(starfield)); |
---|
65 | g->wp = malloc(sizeof(weapons)); |
---|
66 | g->ex = malloc(sizeof(explosions)); |
---|
67 | g->bo = malloc(sizeof(bonus)); |
---|
68 | g->t = create_tunnel( g, g->w, g->h ); |
---|
69 | g->p = create_player( g ); |
---|
70 | g->al = malloc(sizeof(aliens)); |
---|
71 | |
---|
72 | init_starfield( g, g->sf ); |
---|
73 | init_weapons( g, g->wp ); |
---|
74 | init_explosions( g, g->ex ); |
---|
75 | init_aliens( g, g->al ); |
---|
76 | |
---|
77 | /* Temporary stuff */ |
---|
78 | for( i = 0; i < 5; i++ ) |
---|
79 | { |
---|
80 | add_alien( g, g->al, rand() % g->w, rand() % g->h / 2, ALIEN_POOLP ); |
---|
81 | } |
---|
82 | |
---|
83 | g->t->w = 25; |
---|
84 | |
---|
85 | while( !quit ) |
---|
86 | { |
---|
87 | char key; |
---|
88 | |
---|
89 | while( ( key = get_key() ) ) |
---|
90 | { |
---|
91 | switch( key ) |
---|
92 | { |
---|
93 | case 'q': |
---|
94 | quit = 1; |
---|
95 | break; |
---|
96 | case 'p': |
---|
97 | poz = !poz; |
---|
98 | break; |
---|
99 | case '\t': |
---|
100 | ceo_alert(); |
---|
101 | poz = 1; |
---|
102 | break; |
---|
103 | case 's': |
---|
104 | skip = 1; |
---|
105 | break; |
---|
106 | case 'h': |
---|
107 | g->p->dir = -3; |
---|
108 | break; |
---|
109 | case 'j': |
---|
110 | if( g->p->y < g->h - 2 ) g->p->y += 1; |
---|
111 | break; |
---|
112 | case 'k': |
---|
113 | if( g->p->y > 1 ) g->p->y -= 1; |
---|
114 | break; |
---|
115 | case 'l': |
---|
116 | g->p->dir = 3; |
---|
117 | break; |
---|
118 | case 'n': |
---|
119 | if( g->p->nuke == 0 ) |
---|
120 | { |
---|
121 | g->p->nuke = 40; |
---|
122 | add_weapon( g, g->wp, (g->p->x + 2) << 4, g->p->y << 4, 0, 0, WEAPON_NUKE ); |
---|
123 | } |
---|
124 | break; |
---|
125 | case '\r': |
---|
126 | if( g->p->nuke == 0 ) |
---|
127 | { |
---|
128 | g->p->nuke = 40; |
---|
129 | add_weapon( g, g->wp, (g->p->x + 2) << 4, g->p->y << 4, 0, 0, WEAPON_BEAM ); |
---|
130 | } |
---|
131 | break; |
---|
132 | case 'b': |
---|
133 | if( g->p->weapon == 0 ) |
---|
134 | { |
---|
135 | g->p->weapon = 4; |
---|
136 | add_weapon( g, g->wp, (g->p->x + 2) << 4, g->p->y << 4, 0, -16, WEAPON_BOMB ); |
---|
137 | } |
---|
138 | case ' ': |
---|
139 | if( g->p->weapon == 0 ) |
---|
140 | { |
---|
141 | g->p->weapon = 4; |
---|
142 | add_weapon( g, g->wp, g->p->x << 4, g->p->y << 4, 0, -16, WEAPON_LASER ); |
---|
143 | add_weapon( g, g->wp, (g->p->x + 5) << 4, g->p->y << 4, 0, -16, WEAPON_LASER ); |
---|
144 | /* Extra shtuph */ |
---|
145 | add_weapon( g, g->wp, g->p->x << 4, g->p->y << 4, -24, -16, WEAPON_SEEKER ); |
---|
146 | add_weapon( g, g->wp, (g->p->x + 5) << 4, g->p->y << 4, 24, -16, WEAPON_SEEKER ); |
---|
147 | /* More shtuph */ |
---|
148 | add_weapon( g, g->wp, (g->p->x + 1) << 4, (g->p->y - 1) << 4, 0, -16, WEAPON_LASER ); |
---|
149 | add_weapon( g, g->wp, (g->p->x + 4) << 4, (g->p->y - 1) << 4, 0, -16, WEAPON_LASER ); |
---|
150 | /* Even more shtuph */ |
---|
151 | add_weapon( g, g->wp, (g->p->x + 2) << 4, (g->p->y - 1) << 4, 0, -16, WEAPON_LASER ); |
---|
152 | add_weapon( g, g->wp, (g->p->x + 3) << 4, (g->p->y - 1) << 4, 0, -16, WEAPON_LASER ); |
---|
153 | /* Extra shtuph */ |
---|
154 | add_weapon( g, g->wp, g->p->x << 4, g->p->y << 4, -32, 0, WEAPON_SEEKER ); |
---|
155 | add_weapon( g, g->wp, (g->p->x + 5) << 4, g->p->y << 4, 32, 0, WEAPON_SEEKER ); |
---|
156 | } |
---|
157 | break; |
---|
158 | } |
---|
159 | } |
---|
160 | |
---|
161 | usleep(40000); |
---|
162 | |
---|
163 | if( !poz || skip ) |
---|
164 | { |
---|
165 | skip = 0; |
---|
166 | |
---|
167 | /* XXX: to be removed */ |
---|
168 | if( GET_RAND(0,10) == 0 ) |
---|
169 | { |
---|
170 | int list[3] = { ALIEN_POOLP, ALIEN_BOOL, ALIEN_BRAH }; |
---|
171 | |
---|
172 | add_alien( g, g->al, 0, rand() % g->h / 2, list[GET_RAND(0,3)] ); |
---|
173 | } |
---|
174 | |
---|
175 | /* Update game rules */ |
---|
176 | if( g->t->right[1] - g->t->left[1] == g->t->w ) |
---|
177 | { |
---|
178 | g->t->w = 85 - g->t->w; |
---|
179 | } |
---|
180 | |
---|
181 | /* Scroll and update positions */ |
---|
182 | collide_player_tunnel( g, g->p, g->t, g->ex ); |
---|
183 | update_player( g, g->p ); |
---|
184 | collide_player_tunnel( g, g->p, g->t, g->ex ); |
---|
185 | |
---|
186 | update_starfield( g, g->sf ); |
---|
187 | update_bonus( g, g->bo ); |
---|
188 | update_aliens( g, g->al ); |
---|
189 | |
---|
190 | collide_weapons_tunnel( g, g->wp, g->t, g->ex ); |
---|
191 | collide_weapons_aliens( g, g->wp, g->al, g->ex ); |
---|
192 | update_weapons( g, g->wp ); |
---|
193 | collide_weapons_tunnel( g, g->wp, g->t, g->ex ); |
---|
194 | collide_weapons_aliens( g, g->wp, g->al, g->ex ); |
---|
195 | |
---|
196 | update_explosions( g, g->ex ); |
---|
197 | /*if(purcompteur%2)*/ update_tunnel( g, g->t ); |
---|
198 | } |
---|
199 | |
---|
200 | /* Clear screen */ |
---|
201 | clear_graphics(); |
---|
202 | |
---|
203 | /* Print starfield, tunnel, aliens, player and explosions */ |
---|
204 | draw_starfield( g, g->sf ); |
---|
205 | draw_tunnel( g, g->t ); |
---|
206 | draw_bonus( g, g->bo ); |
---|
207 | draw_aliens( g, g->al ); |
---|
208 | draw_player( g, g->p ); |
---|
209 | draw_explosions( g, g->ex ); |
---|
210 | draw_weapons( g, g->wp ); |
---|
211 | |
---|
212 | /* Refresh */ |
---|
213 | refresh_graphics(); |
---|
214 | |
---|
215 | purcompteur++; |
---|
216 | } |
---|
217 | |
---|
218 | #if 0 |
---|
219 | free_player( p ); |
---|
220 | free_tunnel( g->t ); |
---|
221 | #endif |
---|
222 | } |
---|
223 | |
---|