source: ttyvaders/trunk/src/aliens.c @ 70

Last change on this file since 70 was 60, checked in by Sam Hocevar, 20 years ago
  • aliens are now named foo, bar and baz.
  • beginning of life jauges.
File size: 6.2 KB
Line 
1/*
2 *   ttyvaders     Textmode shoot'em up
3 *   Copyright (c) 2002 Sam Hocevar <sam@zoy.org>
4 *                 All Rights Reserved
5 *
6 *   $Id: aliens.c,v 1.8 2002/12/23 13:46:27 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
27static void draw_alien_foo( game *g, int x, int y, int frame );
28static void draw_alien_bar( game *g, int x, int y, int frame );
29static void draw_alien_baz( game *g, int x, int y, int frame );
30
31void init_aliens( game *g, aliens *al )
32{
33    int i;
34
35    for( i = 0; i < ALIENS; i++ )
36    {
37        al->type[i] = ALIEN_NONE;
38    }
39}
40
41void draw_aliens( game *g, aliens *al )
42{
43    int i;
44
45    for( i = 0; i < ALIENS; i++ )
46    {
47        switch( al->type[i] )
48        {
49            case ALIEN_FOO:
50                draw_alien_foo( g, al->x[i], al->y[i], al->img[i] % 8 );
51                break;
52            case ALIEN_BAR:
53                draw_alien_bar( g, al->x[i], al->y[i], al->img[i] % 2 );
54                break;
55            case ALIEN_BAZ:
56                draw_alien_baz( g, al->x[i], al->y[i], al->img[i] % 6 );
57                break;
58            case ALIEN_NONE:
59                break;
60        }
61    }
62}
63
64void update_aliens( game *g, aliens *al )
65{
66    int i;
67
68    for( i = 0; i < ALIENS; i++ )
69    {
70        /* If alien died, make it explode */
71        if( al->type[i] != ALIEN_NONE && al->life[i] < 0 )
72        {
73            add_explosion( g, g->ex, al->x[i], al->y[i], 0, 0, EXPLOSION_MEDIUM );
74            al->type[i] = ALIEN_NONE;
75            add_bonus( g, g->bo, al->x[i], al->y[i], GET_RAND(0,5) ? BONUS_GREEN : BONUS_LIFE );
76        }
77
78        /* Update coordinates */
79        switch( al->type[i] )
80        {
81            case ALIEN_FOO:
82            case ALIEN_BAR:
83            case ALIEN_BAZ:
84                al->x[i] = ((al->x[i] + 5) % (g->w + 3)) - 3;
85                al->y[i] = al->y[i] + (rand() % 8) / 7 - (rand() % 8) / 7;
86                al->img[i] = al->img[i] + 1;
87
88                /* Check bounds */
89                if( al->y[i] < 0 ) al->y[i] = 0;
90                if( al->y[i] > g->w - 1 ) al->y[i] = g->w - 1;
91                break;
92            case ALIEN_NONE:
93                break;
94        }
95    }
96}
97
98void add_alien( game *g, aliens *al, int x, int y, int type )
99{
100    int i;
101
102    for( i = 0; i < ALIENS; i++ )
103    {
104        if( al->type[i] == ALIEN_NONE )
105        {
106            al->type[i] = type;
107            al->x[i] = x;
108            al->y[i] = y;
109            al->img[i] = 0;
110
111            switch( al->type[i] )
112            {
113                case ALIEN_FOO:
114                    al->life[i] = 3;
115                    break;
116                case ALIEN_BAR:
117                    al->life[i] = 3;
118                    break;
119                case ALIEN_BAZ:
120                    al->life[i] = 3;
121                    break;
122                case ALIEN_NONE:
123                    break;
124            }
125
126            break;
127        }
128    }
129}
130
131static void draw_alien_bar( game *g, int x, int y, int frame )
132{
133    switch( frame )
134    {
135    case 0:
136        gfx_color( MAGENTA );
137        gfx_goto( x, y );
138        gfx_putstr( ",---." );
139        gfx_goto( x, y+1 );
140        gfx_putchar( '\\' );
141        gfx_color( WHITE );
142        gfx_putstr( "o O" );
143        gfx_color( MAGENTA );
144        gfx_putchar( '/' );
145        gfx_goto( x, y+2 );
146        gfx_putstr( "^^^^^" );
147        break;
148    case 1:
149        gfx_color( MAGENTA );
150        gfx_goto( x, y );
151        gfx_putstr( ",---." );
152        gfx_goto( x, y+1 );
153        gfx_putchar( '\\' );
154        gfx_color( WHITE );
155        gfx_putstr( "O o" );
156        gfx_color( MAGENTA );
157        gfx_putchar( '/' );
158        gfx_goto( x, y+2 );
159        gfx_putstr( "^^^^^" );
160        break;
161    }
162}
163
164static void draw_alien_baz( game *g, int x, int y, int frame )
165{
166    gfx_color( GREEN );
167    gfx_goto( x, y-1 );
168    gfx_putstr( "__" );
169
170    gfx_goto( x-1, y );
171    gfx_putchar( '/' );
172    gfx_goto( x+2, y );
173    gfx_putchar( '\\' );
174
175    switch( frame )
176    {
177    case 3:
178        gfx_goto( x-2, y+1 );
179        gfx_putstr( "//'`\\\\" );
180        break;
181    case 4:
182    case 2:
183        gfx_goto( x-2, y+1 );
184        gfx_putstr( "/(~~)\\" );
185        break;
186    case 5:
187    case 1:
188        gfx_goto( x-2, y+1 );
189        gfx_putstr( "((^^))" );
190        break;
191    case 0:
192        gfx_goto( x-1, y+1 );
193        gfx_putstr( "\\\\//" );
194        break;
195    }
196
197    gfx_color( WHITE );
198    gfx_goto( x, y );
199    gfx_putstr( "oo" );
200}
201
202static void draw_alien_foo( game *g, int x, int y, int frame )
203{
204    gfx_color( YELLOW );
205
206    switch( frame )
207    {
208    case 0:
209        gfx_goto( x, y );
210        gfx_putchar( '.' );
211        gfx_goto( x+6, y );
212        gfx_putchar( ',' );
213        gfx_goto( x+1, y+1 );
214        gfx_putstr( "\\ X /" );
215        break;
216    case 7:
217    case 1:
218        gfx_goto( x-1, y );
219        gfx_putchar( '.' );
220        gfx_goto( x+7, y );
221        gfx_putchar( ',' );
222        gfx_goto( x, y+1 );
223        gfx_putstr( "`- X -'" );
224        break;
225    case 6:
226    case 2:
227        gfx_goto( x-1, y+1 );
228        gfx_putstr( "`-- X --'" );
229        break;
230    case 5:
231    case 3:
232        gfx_goto( x, y+1 );
233        gfx_putstr( ",- X -." );
234        gfx_goto( x-1, y+2 );
235        gfx_putchar( '\'' );
236        gfx_goto( x+7, y+2 );
237        gfx_putchar( '`' );
238        break;
239    case 4:
240        gfx_goto( x+1, y+1 );
241        gfx_putstr( ", X ." );
242        gfx_goto( x, y+2 );
243        gfx_putchar( '/' );
244        gfx_goto( x+6, y+2 );
245        gfx_putchar( '\\' );
246        break;
247    }
248
249    gfx_goto( x+2, y+2 );
250    gfx_putstr( "`V'" );
251
252    gfx_color( WHITE );
253    gfx_goto( x+2, y+1 );
254    gfx_putchar( 'o' );
255    gfx_goto( x+4, y+1 );
256    gfx_putchar( 'o' );
257}
258
259
Note: See TracBrowser for help on using the repository browser.