source: libcaca/trunk/src/aliens.c @ 35

Last change on this file since 35 was 35, checked in by Sam Hocevar, 20 years ago
  • added the COPYING file (GPLv2).
  • added GPL headers to source files.
File size: 5.8 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: 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 <stdlib.h>
24
25#include "common.h"
26
27static void draw_alien_poolp( game *g, int x, int y, int frame );
28static void draw_alien_bool( game *g, int x, int y, int frame );
29static void draw_alien_brah( 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_BRAH:
50                draw_alien_brah( g, al->x[i], al->y[i], al->img[i] % 8 );
51                break;
52            case ALIEN_POOLP:
53                draw_alien_poolp( g, al->x[i], al->y[i], al->img[i] % 2 );
54                break;
55            case ALIEN_BOOL:
56                draw_alien_bool( 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        switch( al->type[i] )
71        {
72            case ALIEN_POOLP:
73            case ALIEN_BOOL:
74            case ALIEN_BRAH:
75                al->x[i] = ((al->x[i] + 5) % (g->w + 3)) - 3;
76                al->y[i] = al->y[i] + (rand() % 8) / 7 - (rand() % 8) / 7;
77                al->img[i] = al->img[i] + 1;
78
79                /* Check bounds */
80                if( al->y[i] < 0 ) al->y[i] = 0;
81                if( al->y[i] > g->w - 1 ) al->y[i] = g->w - 1;
82                break;
83            case ALIEN_NONE:
84                break;
85        }
86    }
87}
88
89void add_alien( game *g, aliens *al, int x, int y, int type )
90{
91    int i;
92
93    for( i = 0; i < ALIENS; i++ )
94    {
95        if( al->type[i] == ALIEN_NONE )
96        {
97            al->type[i] = type;
98            al->x[i] = x;
99            al->y[i] = y;
100            al->img[i] = 0;
101
102            switch( al->type[i] )
103            {
104                case ALIEN_POOLP:
105                    al->life[i] = 3;
106                    break;
107                case ALIEN_BOOL:
108                    al->life[i] = 3;
109                    break;
110                case ALIEN_BRAH:
111                    al->life[i] = 3;
112                    break;
113                case ALIEN_NONE:
114                    break;
115            }
116
117            break;
118        }
119    }
120}
121
122static void draw_alien_poolp( game *g, int x, int y, int frame )
123{
124    switch( frame )
125    {
126    case 0:
127        gfx_color( MAGENTA );
128        gfx_goto( x, y );
129        gfx_putstr( ",---." );
130        gfx_goto( x, y+1 );
131        gfx_putchar( '\\' );
132        gfx_color( WHITE );
133        gfx_putstr( "o O" );
134        gfx_color( MAGENTA );
135        gfx_putchar( '/' );
136        gfx_goto( x, y+2 );
137        gfx_putstr( "^^^^^" );
138        break;
139    case 1:
140        gfx_color( MAGENTA );
141        gfx_goto( x, y );
142        gfx_putstr( ",---." );
143        gfx_goto( x, y+1 );
144        gfx_putchar( '\\' );
145        gfx_color( WHITE );
146        gfx_putstr( "O o" );
147        gfx_color( MAGENTA );
148        gfx_putchar( '/' );
149        gfx_goto( x, y+2 );
150        gfx_putstr( "^^^^^" );
151        break;
152    }
153}
154
155static void draw_alien_bool( game *g, int x, int y, int frame )
156{
157    gfx_color( GREEN );
158    gfx_goto( x, y-1 );
159    gfx_putstr( "__" );
160
161    gfx_goto( x-1, y );
162    gfx_putchar( '/' );
163    gfx_goto( x+2, y );
164    gfx_putchar( '\\' );
165
166    switch( frame )
167    {
168    case 3:
169        gfx_goto( x-2, y+1 );
170        gfx_putstr( "//'`\\\\" );
171        break;
172    case 4:
173    case 2:
174        gfx_goto( x-2, y+1 );
175        gfx_putstr( "/(~~)\\" );
176        break;
177    case 5:
178    case 1:
179        gfx_goto( x-2, y+1 );
180        gfx_putstr( "((^^))" );
181        break;
182    case 0:
183        gfx_goto( x-1, y+1 );
184        gfx_putstr( "\\\\//" );
185        break;
186    }
187
188    gfx_color( WHITE );
189    gfx_goto( x, y );
190    gfx_putstr( "oo" );
191}
192
193static void draw_alien_brah( game *g, int x, int y, int frame )
194{
195    gfx_color( YELLOW );
196
197    switch( frame )
198    {
199    case 0:
200        gfx_goto( x, y );
201        gfx_putchar( '.' );
202        gfx_goto( x+6, y );
203        gfx_putchar( ',' );
204        gfx_goto( x+1, y+1 );
205        gfx_putstr( "\\ X /" );
206        break;
207    case 7:
208    case 1:
209        gfx_goto( x-1, y );
210        gfx_putchar( '.' );
211        gfx_goto( x+7, y );
212        gfx_putchar( ',' );
213        gfx_goto( x, y+1 );
214        gfx_putstr( "`- X -'" );
215        break;
216    case 6:
217    case 2:
218        gfx_goto( x-1, y+1 );
219        gfx_putstr( "`-- X --'" );
220        break;
221    case 5:
222    case 3:
223        gfx_goto( x, y+1 );
224        gfx_putstr( ",- X -." );
225        gfx_goto( x-1, y+2 );
226        gfx_putchar( '\'' );
227        gfx_goto( x+7, y+2 );
228        gfx_putchar( '`' );
229        break;
230    case 4:
231        gfx_goto( x+1, y+1 );
232        gfx_putstr( ", X ." );
233        gfx_goto( x, y+2 );
234        gfx_putchar( '/' );
235        gfx_goto( x+6, y+2 );
236        gfx_putchar( '\\' );
237        break;
238    }
239
240    gfx_goto( x+2, y+2 );
241    gfx_putstr( "`V'" );
242
243    gfx_color( WHITE );
244    gfx_goto( x+2, y+1 );
245    gfx_putchar( 'o' );
246    gfx_goto( x+4, y+1 );
247    gfx_putchar( 'o' );
248}
249
250
Note: See TracBrowser for help on using the repository browser.