diff --git a/doc/shapes.txt b/doc/shapes.txt index d28f9f6..9f703fe 100644 --- a/doc/shapes.txt +++ b/doc/shapes.txt @@ -104,7 +104,7 @@ Shots ' ` -' `- ,-' `-. ,-' `-. ,-' `-. ,-' `-. ,-' `-. ,--. - ( () ) + ( ', ) `--' o O o ° diff --git a/src/aliens.c b/src/aliens.c index aeb7758..b4ab8e5 100644 --- a/src/aliens.c +++ b/src/aliens.c @@ -3,7 +3,7 @@ * Copyright (c) 2002 Sam Hocevar * All Rights Reserved * - * $Id: aliens.c,v 1.6 2002/12/22 18:44:12 sam Exp $ + * $Id: aliens.c,v 1.7 2002/12/22 22:17:41 sam Exp $ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -67,6 +67,15 @@ void update_aliens( game *g, aliens *al ) for( i = 0; i < ALIENS; i++ ) { + /* If alien died, make it explode */ + if( al->type[i] != ALIEN_NONE && al->life[i] < 0 ) + { + add_explosion( g, g->ex, al->x[i], al->y[i], 0, 0, EXPLOSION_MEDIUM ); + al->type[i] = ALIEN_NONE; + add_bonus( g, g->bo, al->x[i], al->y[i], GET_RAND(0,5) ? BONUS_GREEN : BONUS_LIFE ); + } + + /* Update coordinates */ switch( al->type[i] ) { case ALIEN_POOLP: diff --git a/src/ceo.c b/src/ceo.c index e9d438a..e451d66 100644 --- a/src/ceo.c +++ b/src/ceo.c @@ -3,7 +3,7 @@ * Copyright (c) 2002 Sam Hocevar * All Rights Reserved * - * $Id: ceo.c,v 1.3 2002/12/22 18:44:12 sam Exp $ + * $Id: ceo.c,v 1.4 2002/12/22 22:17:41 sam Exp $ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,12 +20,15 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#include "config.h" + +#include + #include "common.h" void ceo_alert( void ) { - char key; - int end = 0; + int end = 0; while( !end ) { diff --git a/src/collide.c b/src/collide.c index 28ae50f..e4b8bd2 100644 --- a/src/collide.c +++ b/src/collide.c @@ -3,7 +3,7 @@ * Copyright (c) 2002 Sam Hocevar * All Rights Reserved * - * $Id: collide.c,v 1.6 2002/12/22 18:44:12 sam Exp $ + * $Id: collide.c,v 1.7 2002/12/22 22:17:41 sam Exp $ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -35,83 +35,92 @@ void collide_weapons_tunnel( game *g, weapons *wp, tunnel *t, explosions *ex ) switch( wp->type[i] ) { - case WEAPON_NONE: - break; - case WEAPON_SEEKER: - case WEAPON_BOMB: - if( x <= t->left[y] - || x >= t->right[y] ) - { - int damage = wp->type[i] == WEAPON_SEEKER ? 1 : 2; - - add_explosion( g, ex, x, y, 0, 1, wp->type[i] == WEAPON_SEEKER ? EXPLOSION_SMALL : EXPLOSION_MEDIUM ); + case WEAPON_LIGHTNING: + case WEAPON_NONE: + break; + case WEAPON_SEEKER: + case WEAPON_BOMB: + case WEAPON_FRAGBOMB: + if( x <= t->left[y] + || x >= t->right[y] ) + { + int damage = wp->type[i] == WEAPON_SEEKER ? 1 : 2; - if( x <= t->left[y] ) - { - t->right[y-2] -= damage - 1; - t->left[y-1] -= damage; - t->left[y] -= damage + 1; - t->left[y+1] -= damage; - t->right[y+2] -= damage - 1; - } - else - { - t->right[y-2] += damage - 1; - t->right[y-1] += damage; - t->right[y] += damage + 1; - t->right[y+1] += damage; - t->right[y+2] += damage - 1; - } + add_explosion( g, ex, x, y, 0, 1, wp->type[i] == WEAPON_SEEKER ? EXPLOSION_SMALL : EXPLOSION_MEDIUM ); - wp->type[i] = WEAPON_NONE; + if( x <= t->left[y] ) + { + t->right[y-2] -= damage - 1; + t->left[y-1] -= damage; + t->left[y] -= damage + 1; + t->left[y+1] -= damage; + t->right[y+2] -= damage - 1; } - break; - case WEAPON_LASER: - if( x <= t->left[y+1] - || x >= t->right[y+1] ) + else { - add_explosion( g, ex, x, y+1, 0, 1, EXPLOSION_SMALL ); - - if( x <= t->left[y+1] ) - { - t->left[y]--; - t->left[y+1]-=2; - t->left[y+2]--; - } - else - { - t->right[y]++; - t->right[y+1]+=2; - t->right[y+2]++; - } + t->right[y-2] += damage - 1; + t->right[y-1] += damage; + t->right[y] += damage + 1; + t->right[y+1] += damage; + t->right[y+2] += damage - 1; + } + if( wp->type[i] == WEAPON_FRAGBOMB ) + { + wp->n[i] = -1; + } + else + { wp->type[i] = WEAPON_NONE; } - else if( x <= t->left[y] - || x >= t->right[y] ) + } + break; + case WEAPON_LASER: + if( x <= t->left[y+1] + || x >= t->right[y+1] ) + { + add_explosion( g, ex, x, y+1, 0, 1, EXPLOSION_SMALL ); + + if( x <= t->left[y+1] ) + { + t->left[y]--; + t->left[y+1]-=2; + t->left[y+2]--; + } + else { - add_explosion( g, ex, x, y, 0, 1, EXPLOSION_SMALL ); + t->right[y]++; + t->right[y+1]+=2; + t->right[y+2]++; + } - if( x <= t->left[y] ) - { - t->left[y-1]--; - t->left[y]-=2; - t->left[y+1]--; - } - else - { - t->right[y-1]++; - t->right[y]+=2; - t->right[y+1]++; - } + wp->type[i] = WEAPON_NONE; + } + else if( x <= t->left[y] + || x >= t->right[y] ) + { + add_explosion( g, ex, x, y, 0, 1, EXPLOSION_SMALL ); - wp->type[i] = WEAPON_NONE; + if( x <= t->left[y] ) + { + t->left[y-1]--; + t->left[y]-=2; + t->left[y+1]--; + } + else + { + t->right[y-1]++; + t->right[y]+=2; + t->right[y+1]++; } - break; - case WEAPON_NUKE: - case WEAPON_BEAM: - /* The nuke and the laser do not break the tunnel */ - break; + + wp->type[i] = WEAPON_NONE; + } + break; + case WEAPON_NUKE: + case WEAPON_BEAM: + /* The nuke and the laser do not break the tunnel */ + break; } } } @@ -130,125 +139,110 @@ void collide_weapons_aliens( game *g, weapons *wp, aliens *al, explosions *ex ) switch( wp->type[i] ) { - case WEAPON_NONE: - break; - case WEAPON_NUKE: - /* Big nuke */ - r = (29 - wp->n[i]) * (29 - wp->n[i]) / 8; + case WEAPON_LIGHTNING: + case WEAPON_NONE: + break; + case WEAPON_NUKE: + /* Big nuke */ + r = (29 - wp->n[i]) * (29 - wp->n[i]) / 8; - for( j = 0; j < ALIENS; j++ ) + for( j = 0; j < ALIENS; j++ ) + { + if( al->type[j] == ALIEN_NONE || al->life[j] < 0 ) { - if( al->type[j] == ALIEN_NONE ) - { - continue; - } - - if( wp->n[i] == 0 /* Nuke destroys _everything_ */ || - (al->x[j] - x) * (al->x[j] - x) - + 4 * (al->y[j] - y) * (al->y[j] - y) - <= r * r ) - { - /* Kill alien, not nuke */ - al->type[j] = ALIEN_NONE; - add_explosion( g, ex, al->x[j], al->y[j], 0, 0, EXPLOSION_MEDIUM ); - add_bonus( g, g->bo, al->x[j], al->y[j], GET_RAND(0,5) ? BONUS_GREEN : BONUS_LIFE ); - } + continue; } - break; - case WEAPON_BEAM: - r = (29 - wp->n[i]) * (29 - wp->n[i]) / 8; - for( j = 0; j < ALIENS; j++ ) + if( wp->n[i] == 0 /* Nuke destroys _everything_ */ || + (al->x[j] - x) * (al->x[j] - x) + + 4 * (al->y[j] - y) * (al->y[j] - y) + <= r * r ) { - if( al->type[j] == ALIEN_NONE ) - { - continue; - } + /* Kill alien, not nuke */ + al->life[j] -= 10; + } + } + break; + + case WEAPON_BEAM: + r = (29 - wp->n[i]) * (29 - wp->n[i]) / 8; - if( x >= al->x[j] && x <= al->x[j] + 4 - && y >= al->y[j] + 2 && y-5-r <= al->y[j] ) - { - al->life[j] -= 4; - if( al->life[j] <= 0 ) - { - al->type[j] = ALIEN_NONE; - add_explosion( g, ex, al->x[j], al->y[j], 0, 0, EXPLOSION_MEDIUM ); - add_bonus( g, g->bo, al->x[j], al->y[j], GET_RAND(0,5) ? BONUS_GREEN : BONUS_LIFE ); - } - } + for( j = 0; j < ALIENS; j++ ) + { + if( al->type[j] == ALIEN_NONE || al->life[j] < 0 ) + { + continue; } - break; - case WEAPON_LASER: - for( j = 0; j < ALIENS; j++ ) + if( x >= al->x[j] && x <= al->x[j] + 4 + && y >= al->y[j] + 2 && y-5-r <= al->y[j] ) { - if( al->type[j] == ALIEN_NONE ) - { - continue; - } + al->life[j] -= 4; + } + } + break; - if( x >= al->x[j] && x <= al->x[j] + 4 - && y >= al->y[j] && y <= al->y[j] + 2 ) - { - al->life[j]--; - if( al->life[j] <= 0 ) - { - al->type[j] = ALIEN_NONE; - add_explosion( g, ex, al->x[j], al->y[j], 0, 0, EXPLOSION_MEDIUM ); - add_bonus( g, g->bo, al->x[j], al->y[j], GET_RAND(0,5) ? BONUS_GREEN : BONUS_LIFE ); - } - ok = 1; - } - else if( x >= al->x[j] && x <= al->x[j] + 4 - && y+1 >= al->y[j] && y+1 <= al->y[j] + 2 ) - { - al->life[j]--; - if( al->life[j] <= 0 ) - { - al->type[j] = ALIEN_NONE; - add_explosion( g, ex, al->x[j], al->y[j]+1, 0, 0, EXPLOSION_MEDIUM ); - add_bonus( g, g->bo, al->x[j], al->y[j]+1, GET_RAND(0,5) ? BONUS_GREEN : BONUS_LIFE ); - } - ok = 1; - } + case WEAPON_LASER: + for( j = 0; j < ALIENS; j++ ) + { + if( al->type[j] == ALIEN_NONE || al->life[j] < 0 ) + { + continue; } - if( ok ) + if( x >= al->x[j] && x <= al->x[j] + 4 + && y >= al->y[j] && y <= al->y[j] + 2 ) { - add_explosion( g, ex, x, y+1, 0, 0, EXPLOSION_SMALL ); - wp->type[i] = WEAPON_NONE; + al->life[j]--; + ok = 1; } - break; + else if( x >= al->x[j] && x <= al->x[j] + 4 + && y+1 >= al->y[j] && y+1 <= al->y[j] + 2 ) + { + al->life[j]--; + ok = 1; + } + } - case WEAPON_SEEKER: - case WEAPON_BOMB: - for( j = 0; j < ALIENS; j++ ) + if( ok ) + { + add_explosion( g, ex, x, y+1, 0, 0, EXPLOSION_SMALL ); + wp->type[i] = WEAPON_NONE; + } + break; + + case WEAPON_SEEKER: + case WEAPON_BOMB: + case WEAPON_FRAGBOMB: + for( j = 0; j < ALIENS; j++ ) + { + if( al->type[j] == ALIEN_NONE || al->life[j] < 0 ) { - if( al->type[j] == ALIEN_NONE ) - { - continue; - } + continue; + } - if( x >= al->x[j] && x <= al->x[j] + 4 - && y >= al->y[j] && y <= al->y[j] + 2 ) - { - al->life[j] -= wp->type[i] == WEAPON_BOMB ? 5 : 1; - if( al->life[j] <= 0 ) - { - al->type[j] = ALIEN_NONE; - add_explosion( g, ex, al->x[j], al->y[j], 0, 0, EXPLOSION_MEDIUM ); - add_bonus( g, g->bo, al->x[j], al->y[j], GET_RAND(0,5) ? BONUS_GREEN : BONUS_LIFE ); - } - ok = 1; - } + if( x >= al->x[j] && x <= al->x[j] + 4 + && y >= al->y[j] && y <= al->y[j] + 2 ) + { + al->life[j] -= wp->type[i] == WEAPON_SEEKER ? 1 : 5; + ok = 1; } + } + + if( ok ) + { + add_explosion( g, ex, x, y+1, 0, 0, wp->type[i] == WEAPON_SEEKER ? EXPLOSION_SMALL : EXPLOSION_MEDIUM ); - if( ok ) + if( wp->type[i] == WEAPON_FRAGBOMB ) + { + wp->n[i] = -1; + } + else { - add_explosion( g, ex, x, y+1, 0, 0, wp->type[i] == WEAPON_SEEKER ? EXPLOSION_SMALL : EXPLOSION_MEDIUM ); wp->type[i] = WEAPON_NONE; } - break; + } + break; } } } diff --git a/src/common.h b/src/common.h index 8e3632f..5de390e 100644 --- a/src/common.h +++ b/src/common.h @@ -3,7 +3,7 @@ * Copyright (c) 2002 Sam Hocevar * All Rights Reserved * - * $Id: common.h,v 1.7 2002/12/22 18:44:12 sam Exp $ + * $Id: common.h,v 1.8 2002/12/22 22:17:41 sam Exp $ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -73,7 +73,7 @@ typedef struct typedef struct { - enum { WEAPON_NONE, WEAPON_LASER, WEAPON_SEEKER, WEAPON_NUKE, WEAPON_BEAM, WEAPON_LIGHTNING, WEAPON_BOMB } type[WEAPONS]; + enum { WEAPON_NONE, WEAPON_LASER, WEAPON_SEEKER, WEAPON_NUKE, WEAPON_BEAM, WEAPON_LIGHTNING, WEAPON_BOMB, WEAPON_FRAGBOMB } type[WEAPONS]; int x[WEAPONS]; int y[WEAPONS]; int x2[WEAPONS]; diff --git a/src/main.c b/src/main.c index 9e3f4d7..55492ea 100644 --- a/src/main.c +++ b/src/main.c @@ -3,7 +3,7 @@ * Copyright (c) 2002 Sam Hocevar * All Rights Reserved * - * $Id: main.c,v 1.7 2002/12/22 18:44:12 sam Exp $ + * $Id: main.c,v 1.8 2002/12/22 22:17:41 sam Exp $ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -129,6 +129,13 @@ static void start_game (game *g) add_weapon( g, g->wp, (g->p->x + 2) << 4, g->p->y << 4, 0, 0, WEAPON_BEAM ); } break; + case 'd': + if( g->p->nuke == 0 ) + { + g->p->nuke = 40; + add_weapon( g, g->wp, (g->p->x + 2) << 4, g->p->y << 4, 0, -16, WEAPON_FRAGBOMB ); + } + break; case 'b': if( g->p->weapon == 0 ) { @@ -205,9 +212,9 @@ static void start_game (game *g) draw_tunnel( g, g->t ); draw_bonus( g, g->bo ); draw_aliens( g, g->al ); - draw_player( g, g->p ); draw_explosions( g, g->ex ); draw_weapons( g, g->wp ); + draw_player( g, g->p ); /* Refresh */ refresh_graphics(); diff --git a/src/weapons.c b/src/weapons.c index bf21a94..fbc8c2a 100644 --- a/src/weapons.c +++ b/src/weapons.c @@ -3,7 +3,7 @@ * Copyright (c) 2002 Sam Hocevar * All Rights Reserved * - * $Id: weapons.c,v 1.7 2002/12/22 18:44:12 sam Exp $ + * $Id: weapons.c,v 1.8 2002/12/22 22:17:41 sam Exp $ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -29,6 +29,7 @@ static void draw_bomb( int x, int y, int vx, int vy ); static void draw_nuke( int x, int y, int frame ); static void draw_beam( int x, int y, int frame ); static void draw_circle( int x, int y, int r, char c ); +static void draw_fragbomb( int x, int y, int frame ); void init_weapons( game *g, weapons *wp ) { @@ -80,12 +81,16 @@ void draw_weapons( game *g, weapons *wp ) gfx_putchar( '.' ); draw_bomb( wp->x[i] >> 4, wp->y[i] >> 4, wp->vx[i], wp->vy[i] ); break; + case WEAPON_FRAGBOMB: + draw_fragbomb( wp->x[i] >> 4, wp->y[i] >> 4, wp->n[i] ); + break; case WEAPON_BEAM: draw_beam( wp->x[i] >> 4, wp->y[i] >> 4, wp->n[i] ); break; case WEAPON_NUKE: draw_nuke( wp->x[i] >> 4, wp->y[i] >> 4, wp->n[i] ); break; + case WEAPON_LIGHTNING: case WEAPON_NONE: break; } @@ -171,6 +176,33 @@ void update_weapons( game *g, weapons *wp ) wp->vy[i] = (7 * wp->vy[i] + (dy * 24) / sqrt(dx*dx+dy*dy) ) / 8; + break; + case WEAPON_FRAGBOMB: + /* If n was set to -1, the fragbomb exploded */ + if( wp->n[i] == -1 ) + { + add_weapon( g, g->wp, wp->x[i] + 24, wp->y[i], 24, 0, WEAPON_SEEKER ); + add_weapon( g, g->wp, wp->x[i] - 24, wp->y[i], -24, 0, WEAPON_SEEKER ); + add_weapon( g, g->wp, wp->x[i], wp->y[i] + 24, 0, 24, WEAPON_SEEKER ); + add_weapon( g, g->wp, wp->x[i], wp->y[i] - 24, 0, -24, WEAPON_SEEKER ); + add_weapon( g, g->wp, wp->x[i] + 24, wp->y[i] + 8, 24, 8, WEAPON_SEEKER ); + add_weapon( g, g->wp, wp->x[i] - 24, wp->y[i] + 8, -24, 8, WEAPON_SEEKER ); + add_weapon( g, g->wp, wp->x[i] + 24, wp->y[i] - 8, 24, -8, WEAPON_SEEKER ); + add_weapon( g, g->wp, wp->x[i] - 24, wp->y[i] - 8, -24, -8, WEAPON_SEEKER ); + add_weapon( g, g->wp, wp->x[i] + 16, wp->y[i] + 16, 16, 16, WEAPON_SEEKER ); + add_weapon( g, g->wp, wp->x[i] - 16, wp->y[i] + 16, -16, 16, WEAPON_SEEKER ); + add_weapon( g, g->wp, wp->x[i] + 16, wp->y[i] - 16, 16, -16, WEAPON_SEEKER ); + add_weapon( g, g->wp, wp->x[i] - 16, wp->y[i] - 16, -16, -16, WEAPON_SEEKER ); + wp->type[i] = WEAPON_NONE; + } + + wp->x[i] += wp->vx[i]; + wp->y[i] += wp->vy[i]; + wp->n[i]++; + if( wp->y[i] < 0 ) + { + wp->type[i] = WEAPON_NONE; + } break; case WEAPON_BEAM: wp->x[i] = (g->p->x + 2) << 4; @@ -188,6 +220,7 @@ void update_weapons( game *g, weapons *wp ) wp->type[i] = WEAPON_NONE; } break; + case WEAPON_LIGHTNING: case WEAPON_NONE: break; } @@ -207,10 +240,13 @@ void add_weapon( game *g, weapons *wp, int x, int y, int vx, int vy, int type ) wp->vx[i] = vx; wp->vy[i] = vy; wp->type[i] = type; + wp->n[i] = 0; switch( type ) { case WEAPON_LASER: break; + case WEAPON_FRAGBOMB: + break; case WEAPON_SEEKER: case WEAPON_BOMB: wp->x2[i] = x; @@ -412,6 +448,99 @@ static void draw_bomb( int x, int y, int vx, int vy ) } } +static void draw_fragbomb( int x, int y, int frame ) +{ + gfx_color( WHITE ); + + gfx_color( frame & 1 ? CYAN : WHITE ); + gfx_goto( x-2, y ); + gfx_putstr( "( )" ); + gfx_goto( x-1, y+1 ); + gfx_putstr( "`--'" ); + + gfx_color( frame & 1 ? WHITE : CYAN ); + gfx_goto( x-1, y-1 ); + gfx_putstr( ",--." ); + gfx_goto( x, y ); + gfx_putstr( "'," ); + + switch( frame % 4 ) + { + case 0: + gfx_color( CYAN ); + gfx_goto( x, y + 2 ); + gfx_putchar( 'O' ); + gfx_goto( x + 2, y + 2 ); + gfx_putchar( 'o' ); + gfx_goto( x + 1, y + 3 ); + gfx_putchar( 'o' ); + gfx_color( GRAY ); + gfx_goto( x - 1, y + 3 ); + gfx_putchar( '°' ); + gfx_goto( x + 2, y + 4 ); + gfx_putchar( '°' ); + gfx_goto( x, y + 4 ); + gfx_putchar( '.' ); + gfx_goto( x + 1, y + 5 ); + gfx_putchar( '.' ); + break; + case 1: + gfx_color( CYAN ); + //gfx_goto( x, y + 1 ); + //gfx_putchar( 'O' ); + gfx_goto( x + 1, y + 2 ); + gfx_putchar( 'O' ); + gfx_goto( x, y + 3 ); + gfx_putchar( 'o' ); + gfx_color( GRAY ); + gfx_goto( x + 2, y + 3 ); + gfx_putchar( '°' ); + gfx_goto( x + 1, y + 4 ); + gfx_putchar( '°' ); + gfx_goto( x - 1, y + 4 ); + gfx_putchar( '.' ); + gfx_goto( x + 2, y + 5 ); + gfx_putchar( '.' ); + break; + case 2: + gfx_color( CYAN ); + //gfx_goto( x - 1, y + 1 ); + //gfx_putchar( 'O' ); + gfx_goto( x + 2, y + 2 ); + gfx_putchar( 'O' ); + gfx_goto( x, y + 2 ); + gfx_putchar( 'o' ); + gfx_goto( x + 1, y + 3 ); + gfx_putchar( 'o' ); + gfx_color( GRAY ); + gfx_goto( x, y + 4 ); + gfx_putchar( '°' ); + gfx_goto( x + 2, y + 4 ); + gfx_putchar( '.' ); + gfx_goto( x + 1, y + 5 ); + gfx_putchar( '.' ); + break; + case 3: + gfx_color( CYAN ); + //gfx_goto( x + 2, y + 1 ); + //gfx_putchar( 'O' ); + gfx_goto( x + 1, y + 2 ); + gfx_putchar( 'O' ); + gfx_goto( x - 1, y + 2 ); + gfx_putchar( 'o' ); + gfx_goto( x + 2, y + 3 ); + gfx_putchar( 'o' ); + gfx_color( GRAY ); + gfx_goto( x, y + 3 ); + gfx_putchar( '°' ); + gfx_goto( x + 1, y + 4 ); + gfx_putchar( '°' ); + gfx_goto( x, y + 5 ); + gfx_putchar( '.' ); + break; + } +} + static void draw_beam( int x, int y, int frame ) { int r = (29 - frame) * (29 - frame) / 8;