From 45a62f2fc5cf0080a148d6ebc52c7e9d456dc1d3 Mon Sep 17 00:00:00 2001 From: sam Date: Sun, 9 Feb 2003 11:17:40 +0000 Subject: [PATCH] * support for boxes * application: pause box git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/ttyvaders/trunk@70 92316355-f0b4-4df1-b90c-862c8a59935f --- TODO | 2 +- src/Makefile.am | 1 + src/box.c | 123 ++++++++++++++++++++++++++++++++++++++++++++++++ src/common.h | 19 +++++++- src/main.c | 27 ++++++++++- src/overlay.c | 4 +- 6 files changed, 169 insertions(+), 7 deletions(-) create mode 100644 src/box.c diff --git a/TODO b/TODO index 45ee33b..c952e94 100644 --- a/TODO +++ b/TODO @@ -40,5 +40,5 @@ Things to do * the nuke should break the tunnel - * the laser stays alive when the ship exploded + * the laser stays alive when the ship explodes diff --git a/src/Makefile.am b/src/Makefile.am index dd81679..9a565b9 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -21,6 +21,7 @@ bin_PROGRAMS = ttyvaders ttyvaders_SOURCES = \ aliens.c \ bonus.c \ + box.c \ ceo.c \ collide.c \ common.h \ diff --git a/src/box.c b/src/box.c new file mode 100644 index 0000000..6e4ff08 --- /dev/null +++ b/src/box.c @@ -0,0 +1,123 @@ +/* + * ttyvaders Textmode shoot'em up + * Copyright (c) 2002-2003 Sam Hocevar + * All Rights Reserved + * + * $Id: box.c,v 1.1 2003/02/09 11:17:40 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 + +#include "common.h" + +box * create_box( game *g, int x, int y, int w, int h ) +{ + box *b = malloc( sizeof( box ) ); + + b->x = x; + b->y = y; + b->w = w; + b->h = h; + b->frame = 0; + + return b; +} + +void draw_box( game *g, box *b ) +{ + int i, j, frame; + + gfx_color( YELLOW ); + + /* Draw the thin horizontal line */ + if( b->frame < 8 ) + { + for( i = b->x - b->w * b->frame / 16 ; + i < b->x + b->w * b->frame / 16 ; + i++ ) + { + gfx_goto( i, b->y ); + gfx_putchar( 'X' ); + } + + return; + } + + /* Draw the frame */ + frame = b->frame < 12 ? b->frame : 12; + + for( i = b->x - b->w / 2 ; + i < b->x + b->w / 2 ; + i++ ) + { + gfx_goto( i, b->y - b->h * (frame - 8) / 8 ); + gfx_putchar( 'X' ); + gfx_goto( i, b->y + b->h * (frame - 8) / 8 ); + gfx_putchar( 'X' ); + } + + for( j = b->y - b->h * (frame - 8) / 8 ; + j < b->y + b->h * (frame - 8) / 8 ; + j++ ) + { + gfx_goto( b->x - b->w / 2, j ); + gfx_putchar( 'X' ); + gfx_goto( b->x + b->w / 2 - 1, j ); + gfx_putchar( 'X' ); + } + + gfx_color( BLACK ); + + for( j = b->y - b->h * (frame - 8) / 8 + 1 ; + j < b->y + b->h * (frame - 8) / 8 ; + j++ ) + { + for( i = b->x - b->w / 2 + 1 ; + i < b->x + b->w / 2 - 1 ; + i++ ) + { + gfx_goto( i, j ); + gfx_putchar( 'X' ); + } + } + + if( b->frame < 12 ) + { + return; + } + + /* Draw the text inside the frame */ + gfx_color( YELLOW ); + + /* FIXME: use a font */ + gfx_goto( b->x - b->w / 2 + 12, b->y - b->h / 2 + 2 ); + gfx_putstr( "XXXX. .XXXX X X .XXXX .XXXX XXXX." ); + gfx_goto( b->x - b->w / 2 + 12, b->y - b->h / 2 + 3 ); + gfx_putstr( "X `X X' X X X X' X' X `X" ); + gfx_goto( b->x - b->w / 2 + 12, b->y - b->h / 2 + 4 ); + gfx_putstr( "XXXX' XXXXX X X `XXX XXXX X X" ); + gfx_goto( b->x - b->w / 2 + 12, b->y - b->h / 2 + 5 ); + gfx_putstr( "X' X' `X X. ,X `X X' X ,X" ); + gfx_goto( b->x - b->w / 2 + 12, b->y - b->h / 2 + 6 ); + gfx_putstr( "X X X `XXXX XXXX' `XXXX XXXX'" ); +} + +void free_box( box *b ) +{ + free( b ); +} + diff --git a/src/common.h b/src/common.h index dad232e..5550322 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.15 2002/12/23 16:21:38 sam Exp $ + * $Id: common.h,v 1.16 2003/02/09 11:17:40 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 @@ -140,6 +140,14 @@ typedef struct } aliens; +typedef struct +{ + int w, h; + int x, y; + int frame; + +} box; + typedef struct { int w, h; @@ -181,6 +189,13 @@ 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 box.c + */ +box * create_box( game *g, int x, int y, int w, int h ); +void draw_box( game *g, box *b ); +void free_box( box *b ); + /* * From ceo.c */ @@ -220,7 +235,7 @@ int r00t( int a ); /* * From overlay.c */ -void draw_overlay( game *g ); +void draw_status( game *g ); /* * From player.c diff --git a/src/main.c b/src/main.c index 31d4fd3..e9398a9 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.16 2002/12/23 16:21:38 sam Exp $ + * $Id: main.c,v 1.17 2003/02/09 11:17:40 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 @@ -61,6 +61,8 @@ static void start_game (game *g) int skip = 0; int purcompteur = 0; + box *pausebox = NULL; + g->sf = create_starfield( g ); g->wp = malloc(sizeof(weapons)); g->ex = malloc(sizeof(explosions)); @@ -90,6 +92,15 @@ static void start_game (game *g) break; case 'p': poz = !poz; + if( poz ) + { + pausebox = create_box( g, g->w / 2, g->h / 2, + g->w - 16, 8 ); + } + else + { + free_box( pausebox ); + } break; case '\t': ceo_alert(); @@ -215,7 +226,14 @@ static void start_game (game *g) draw_explosions( g, g->ex ); draw_weapons( g, g->wp ); draw_player( g, g->p ); - draw_overlay( g ); + draw_status( g ); + + /* Print pause box if needed */ + if( poz ) + { + pausebox->frame++; + draw_box( g, pausebox ); + } /* Refresh */ refresh_graphics(); @@ -223,6 +241,11 @@ static void start_game (game *g) purcompteur++; } + if( pausebox ) + { + free_box( pausebox ); + } + free_starfield( g, g->sf ); free_tunnel( g->t ); free_player( g->p ); diff --git a/src/overlay.c b/src/overlay.c index c695235..37f663e 100644 --- a/src/overlay.c +++ b/src/overlay.c @@ -3,7 +3,7 @@ * Copyright (c) 2002 Sam Hocevar * All Rights Reserved * - * $Id: overlay.c,v 1.2 2002/12/23 16:21:38 sam Exp $ + * $Id: overlay.c,v 1.3 2003/02/09 11:17:40 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 @@ -24,7 +24,7 @@ #include "common.h" -void draw_overlay( game *g ) +void draw_status( game *g ) { static char dots30[] = "------------------------------"; static char dashes30[] = "==============================";