* the bomb is now part of the standard fire button effect. * overlay for life and special weapon jauges. git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/ttyvaders/trunk@62 92316355-f0b4-4df1-b90c-862c8a59935fmaster
| @@ -22,16 +22,17 @@ ttyvaders_SOURCES = \ | |||
| aliens.c \ | |||
| bonus.c \ | |||
| ceo.c \ | |||
| collide.c \ | |||
| common.h \ | |||
| explosions.c \ | |||
| graphics.c \ | |||
| main.c \ | |||
| math.c \ | |||
| starfield.c \ | |||
| weapons.c \ | |||
| collide.c \ | |||
| graphics.c \ | |||
| overlay.c \ | |||
| player.c \ | |||
| starfield.c \ | |||
| tunnel.c \ | |||
| weapons.c \ | |||
| $(NULL) | |||
| ttyvaders_CPPFLAGS = $(CPPFLAGS_slang) $(CPPFLAGS_ncurses) | |||
| @@ -3,7 +3,7 @@ | |||
| * Copyright (c) 2002 Sam Hocevar <sam@zoy.org> | |||
| * All Rights Reserved | |||
| * | |||
| * $Id: common.h,v 1.13 2002/12/23 13:46:27 sam Exp $ | |||
| * $Id: common.h,v 1.14 2002/12/23 15:06:13 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,14 +20,28 @@ | |||
| * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |||
| */ | |||
| #define MAX_LIFE 1000 | |||
| /* | |||
| * Compile-time limits | |||
| */ | |||
| #define STARS 50 | |||
| #define WEAPONS 200 | |||
| #define BONUS 30 | |||
| #define ALIENS 30 | |||
| #define EXPLOSIONS 200 | |||
| /* | |||
| * Game defines | |||
| */ | |||
| #define MAX_LIFE 1000 | |||
| #define MAX_SPECIAL 200 | |||
| #define COST_NUKE (100*MAX_SPECIAL/100) | |||
| #define COST_BEAM (75*MAX_SPECIAL/100) | |||
| #define COST_FRAGBOMB (50*MAX_SPECIAL/100) | |||
| /* | |||
| * Graphics primitives | |||
| */ | |||
| #ifdef USE_SLANG | |||
| # include <slang.h> | |||
| # define gfx_color(x) SLsmg_set_color(x) | |||
| @@ -49,10 +63,16 @@ | |||
| #define gfx_putcharTO(x,y,c) do{ gfx_goto(x,y); gfx_putchar(c); }while(0) | |||
| /* | |||
| * Useful macros | |||
| */ | |||
| #define GET_RAND(p,q) ((p)+(int)((1.0*((q)-(p)))*rand()/(RAND_MAX+1.0))) | |||
| #define GET_MAX(a,b) ((a)>(b)?(a):(b)) | |||
| #define GET_MIN(a,b) ((a)<(b)?(a):(b)) | |||
| /* | |||
| * Game structures | |||
| */ | |||
| typedef struct | |||
| { | |||
| int w, h, *left, *right; | |||
| @@ -105,7 +125,7 @@ typedef struct | |||
| { | |||
| int x, y; | |||
| int vx, vy; | |||
| int weapon, nuke; | |||
| int weapon, special; | |||
| int life, dead; | |||
| } player; | |||
| @@ -145,15 +165,45 @@ typedef struct | |||
| #define CYAN 9 | |||
| #define MAGENTA 10 | |||
| void collide_weapons_tunnel( game *g, weapons *wp, tunnel *t, explosions *ex ); | |||
| void collide_weapons_aliens( game *g, weapons *wp, aliens *al, explosions *ex ); | |||
| void collide_player_tunnel( game *g, player *p, tunnel *t, explosions *ex ); | |||
| /* | |||
| * From aliens.c | |||
| */ | |||
| void init_aliens( game *g, aliens *al ); | |||
| void draw_aliens( game *g, aliens *al ); | |||
| void update_aliens( game *g, aliens *al ); | |||
| void add_alien( game *g, aliens *al, int x, int y, int type ); | |||
| /* | |||
| * From bonus.c | |||
| */ | |||
| void init_bonus( game *g, bonus *bo ); | |||
| void draw_bonus( game *g, bonus *bo ); | |||
| void update_bonus( game *g, bonus *bo ); | |||
| void add_bonus( game *g, bonus *bo, int x, int y, int type ); | |||
| /* | |||
| * From ceo.c | |||
| */ | |||
| void ceo_alert( void ); | |||
| /* | |||
| * From collide.c | |||
| */ | |||
| void collide_weapons_tunnel( game *g, weapons *wp, tunnel *t, explosions *ex ); | |||
| void collide_weapons_aliens( game *g, weapons *wp, aliens *al, explosions *ex ); | |||
| void collide_player_tunnel( game *g, player *p, tunnel *t, explosions *ex ); | |||
| /* | |||
| * From explosions.c | |||
| */ | |||
| void init_explosions( game *g, explosions *ex ); | |||
| void add_explosion( game *g, explosions *ex, int x, int y, int vx, int vy, int type ); | |||
| void draw_explosions( game *g, explosions *ex ); | |||
| void update_explosions( game *g, explosions *ex ); | |||
| /* | |||
| * From graphics.c | |||
| */ | |||
| int init_graphics( void ); | |||
| void init_game( game *g ); | |||
| char get_key( void ); | |||
| @@ -161,37 +211,45 @@ void clear_graphics( void ); | |||
| void refresh_graphics( void ); | |||
| void end_graphics( void ); | |||
| /* | |||
| * From math.c | |||
| */ | |||
| int r00t( int a ); | |||
| /* | |||
| * From overlay.c | |||
| */ | |||
| void draw_overlay( game *g ); | |||
| /* | |||
| * From player.c | |||
| */ | |||
| player * create_player( game *g ); | |||
| void free_player( player *p ); | |||
| void draw_player( game *g, player *p ); | |||
| void update_player( game *g, player *p ); | |||
| void init_weapons( game *g, weapons *wp ); | |||
| void draw_weapons( game *g, weapons *wp ); | |||
| void update_weapons( game *g, weapons *wp ); | |||
| void add_weapon( game *g, weapons *wp, int x, int y, int vx, int vy, int type ); | |||
| void init_bonus( game *g, bonus *bo ); | |||
| void draw_bonus( game *g, bonus *bo ); | |||
| void update_bonus( game *g, bonus *bo ); | |||
| void add_bonus( game *g, bonus *bo, int x, int y, int type ); | |||
| /* | |||
| * From starfield.c | |||
| */ | |||
| starfield * create_starfield( game *g ); | |||
| void draw_starfield( game *g, starfield *s ); | |||
| void update_starfield( game *g, starfield *s ); | |||
| void free_starfield( game *g, starfield *s ); | |||
| /* | |||
| * From tunnel.c | |||
| */ | |||
| tunnel * create_tunnel( game *g, int w, int h ); | |||
| void free_tunnel( tunnel *t ); | |||
| void draw_tunnel( game *g, tunnel *t ); | |||
| void update_tunnel( game *g, tunnel *t ); | |||
| void init_explosions( game *g, explosions *ex ); | |||
| void add_explosion( game *g, explosions *ex, int x, int y, int vx, int vy, int type ); | |||
| void draw_explosions( game *g, explosions *ex ); | |||
| void update_explosions( game *g, explosions *ex ); | |||
| void ceo_alert( void ); | |||
| int r00t( int a ); | |||
| /* | |||
| * From weapons.c | |||
| */ | |||
| void init_weapons( game *g, weapons *wp ); | |||
| void draw_weapons( game *g, weapons *wp ); | |||
| void update_weapons( game *g, weapons *wp ); | |||
| void add_weapon( game *g, weapons *wp, int x, int y, int vx, int vy, int type ); | |||
| @@ -3,7 +3,7 @@ | |||
| * Copyright (c) 2002 Sam Hocevar <sam@zoy.org> | |||
| * All Rights Reserved | |||
| * | |||
| * $Id: main.c,v 1.14 2002/12/23 13:46:27 sam Exp $ | |||
| * $Id: main.c,v 1.15 2002/12/23 15:06:13 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 | |||
| @@ -84,19 +84,27 @@ static void start_game (game *g) | |||
| { | |||
| switch( key ) | |||
| { | |||
| case 'q': | |||
| quit = 1; | |||
| break; | |||
| case 'p': | |||
| poz = !poz; | |||
| break; | |||
| case '\t': | |||
| ceo_alert(); | |||
| poz = 1; | |||
| break; | |||
| case 's': | |||
| skip = 1; | |||
| case 'q': | |||
| quit = 1; | |||
| break; | |||
| case 'p': | |||
| poz = !poz; | |||
| break; | |||
| case '\t': | |||
| ceo_alert(); | |||
| poz = 1; | |||
| break; | |||
| case 's': | |||
| skip = 1; | |||
| break; | |||
| default: | |||
| if( g->p->dead ) | |||
| { | |||
| break; | |||
| } | |||
| switch( key ) | |||
| { | |||
| case 'h': | |||
| g->p->vx = -2; | |||
| break; | |||
| @@ -110,52 +118,49 @@ static void start_game (game *g) | |||
| g->p->vx = 2; | |||
| break; | |||
| case 'n': | |||
| if( g->p->nuke == 0 ) | |||
| if( g->p->special >= COST_NUKE ) | |||
| { | |||
| g->p->nuke = 40; | |||
| g->p->special -= COST_NUKE; | |||
| add_weapon( g, g->wp, (g->p->x + 2) << 4, g->p->y << 4, 0, 0, WEAPON_NUKE ); | |||
| } | |||
| break; | |||
| case '\r': | |||
| if( g->p->nuke == 0 ) | |||
| { | |||
| g->p->nuke = 40; | |||
| add_weapon( g, g->wp, (g->p->x + 2) << 4, g->p->y << 4, 0, 0, WEAPON_BEAM ); | |||
| } | |||
| break; | |||
| case 'f': | |||
| if( g->p->nuke == 0 ) | |||
| if( g->p->special >= COST_FRAGBOMB ) | |||
| { | |||
| g->p->nuke = 40; | |||
| g->p->special -= COST_FRAGBOMB; | |||
| 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 ) | |||
| if( g->p->special >= COST_BEAM ) | |||
| { | |||
| g->p->weapon = 4; | |||
| add_weapon( g, g->wp, (g->p->x + 2) << 4, g->p->y << 4, 0, -16, WEAPON_BOMB ); | |||
| g->p->special -= COST_BEAM; | |||
| add_weapon( g, g->wp, (g->p->x + 2) << 4, g->p->y << 4, 0, 0, WEAPON_BEAM ); | |||
| } | |||
| break; | |||
| case ' ': | |||
| if( g->p->weapon == 0 ) | |||
| { | |||
| g->p->weapon = 4; | |||
| add_weapon( g, g->wp, g->p->x << 4, g->p->y << 4, 0, -32, WEAPON_LASER ); | |||
| add_weapon( g, g->wp, (g->p->x + 5) << 4, g->p->y << 4, 0, -32, WEAPON_LASER ); | |||
| /* Extra shtuph */ | |||
| /* Extra schtuph */ | |||
| add_weapon( g, g->wp, g->p->x << 4, g->p->y << 4, -24, -16, WEAPON_SEEKER ); | |||
| add_weapon( g, g->wp, (g->p->x + 5) << 4, g->p->y << 4, 24, -16, WEAPON_SEEKER ); | |||
| /* More shtuph */ | |||
| /* More schtuph */ | |||
| add_weapon( g, g->wp, (g->p->x + 1) << 4, (g->p->y - 1) << 4, 0, -32, WEAPON_LASER ); | |||
| add_weapon( g, g->wp, (g->p->x + 4) << 4, (g->p->y - 1) << 4, 0, -32, WEAPON_LASER ); | |||
| /* Even more shtuph */ | |||
| /* Even more schtuph */ | |||
| add_weapon( g, g->wp, (g->p->x + 2) << 4, (g->p->y - 1) << 4, 0, -32, WEAPON_LASER ); | |||
| add_weapon( g, g->wp, (g->p->x + 3) << 4, (g->p->y - 1) << 4, 0, -32, WEAPON_LASER ); | |||
| /* Extra shtuph */ | |||
| /* Extra schtuph */ | |||
| add_weapon( g, g->wp, g->p->x << 4, g->p->y << 4, -32, 0, WEAPON_SEEKER ); | |||
| add_weapon( g, g->wp, (g->p->x + 5) << 4, g->p->y << 4, 32, 0, WEAPON_SEEKER ); | |||
| /* MORE SCHTUPH! */ | |||
| add_weapon( g, g->wp, (g->p->x + 2) << 4, g->p->y << 4, 0, -16, WEAPON_BOMB ); | |||
| } | |||
| break; | |||
| } | |||
| } | |||
| } | |||
| @@ -209,6 +214,7 @@ static void start_game (game *g) | |||
| draw_explosions( g, g->ex ); | |||
| draw_weapons( g, g->wp ); | |||
| draw_player( g, g->p ); | |||
| draw_overlay( g ); | |||
| /* Refresh */ | |||
| refresh_graphics(); | |||
| @@ -0,0 +1,86 @@ | |||
| /* | |||
| * ttyvaders Textmode shoot'em up | |||
| * Copyright (c) 2002 Sam Hocevar <sam@zoy.org> | |||
| * All Rights Reserved | |||
| * | |||
| * $Id: overlay.c,v 1.1 2002/12/23 15:06:13 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 | |||
| * the Free Software Foundation; either version 2 of the License, or | |||
| * (at your option) any later version. | |||
| * | |||
| * This program is distributed in the hope that it will be useful, | |||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
| * GNU General Public License for more details. | |||
| * | |||
| * You should have received a copy of the GNU General Public License | |||
| * along with this program; if not, write to the Free Software | |||
| * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |||
| */ | |||
| #include <stdlib.h> | |||
| #include "common.h" | |||
| void draw_overlay( game *g ) | |||
| { | |||
| static char dots30[] = "------------------------------"; | |||
| static char dashes30[] = "=============================="; | |||
| /* Draw life jauge */ | |||
| gfx_color( GRAY ); | |||
| gfx_goto( 2, 1 ); | |||
| gfx_putstr( dots30 ); | |||
| if( g->p->life > MAX_LIFE * 7 / 10 ) | |||
| { | |||
| gfx_color( GREEN ); | |||
| } | |||
| else if( g->p->life > MAX_LIFE * 3 / 10 ) | |||
| { | |||
| gfx_color( YELLOW ); | |||
| } | |||
| else | |||
| { | |||
| gfx_color( RED ); | |||
| } | |||
| gfx_goto( 2, 1 ); | |||
| gfx_putstr( dashes30 + ( MAX_LIFE - g->p->life ) * 30 / MAX_LIFE ); | |||
| gfx_color( WHITE ); | |||
| gfx_goto( 1, 1 ); | |||
| gfx_putstr( "|" ); | |||
| gfx_goto( 32, 1 ); | |||
| gfx_putstr( "| L" ); | |||
| /* Draw weapon jauge */ | |||
| gfx_color( GRAY ); | |||
| gfx_goto( 38, 1 ); | |||
| gfx_putstr( dots30 + 10 ); | |||
| if( g->p->special > MAX_SPECIAL * 9 / 10 ) | |||
| { | |||
| gfx_color( WHITE ); | |||
| } | |||
| else if( g->p->special > MAX_SPECIAL * 3 / 10 ) | |||
| { | |||
| gfx_color( CYAN ); | |||
| } | |||
| else | |||
| { | |||
| gfx_color( BLUE ); | |||
| } | |||
| gfx_goto( 38, 1 ); | |||
| gfx_putstr( dashes30 + 10 + ( MAX_SPECIAL - g->p->special ) * 20 / MAX_SPECIAL ); | |||
| gfx_color( WHITE ); | |||
| gfx_goto( 37, 1 ); | |||
| gfx_putstr( "|" ); | |||
| gfx_goto( 58, 1 ); | |||
| gfx_putstr( "| S" ); | |||
| } | |||
| @@ -3,7 +3,7 @@ | |||
| * Copyright (c) 2002 Sam Hocevar <sam@zoy.org> | |||
| * All Rights Reserved | |||
| * | |||
| * $Id: player.c,v 1.6 2002/12/23 13:46:27 sam Exp $ | |||
| * $Id: player.c,v 1.7 2002/12/23 15:06:13 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 | |||
| @@ -34,7 +34,7 @@ player * create_player( game *g ) | |||
| p->vx = 0; | |||
| p->vy = 0; | |||
| p->weapon = 0; | |||
| p->nuke = 0; | |||
| p->special = MAX_SPECIAL; | |||
| p->life = MAX_LIFE; | |||
| return p; | |||
| @@ -86,9 +86,9 @@ void update_player( game *g, player *p ) | |||
| p->weapon--; | |||
| } | |||
| if( p->nuke ) | |||
| if( p->special < MAX_SPECIAL ) | |||
| { | |||
| p->nuke--; | |||
| p->special++; | |||
| } | |||
| /* Update life */ | |||