Selaa lähdekoodia

* support for boxes

* application: pause box
tags/v0.99.beta14
Sam Hocevar sam 22 vuotta sitten
vanhempi
commit
34dc9bf436
6 muutettua tiedostoa jossa 169 lisäystä ja 7 poistoa
  1. +1
    -1
      TODO
  2. +1
    -0
      src/Makefile.am
  3. +123
    -0
      src/box.c
  4. +17
    -2
      src/common.h
  5. +25
    -2
      src/main.c
  6. +2
    -2
      src/overlay.c

+ 1
- 1
TODO Näytä tiedosto

@@ -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


+ 1
- 0
src/Makefile.am Näytä tiedosto

@@ -21,6 +21,7 @@ bin_PROGRAMS = ttyvaders
ttyvaders_SOURCES = \
aliens.c \
bonus.c \
box.c \
ceo.c \
collide.c \
common.h \


+ 123
- 0
src/box.c Näytä tiedosto

@@ -0,0 +1,123 @@
/*
* ttyvaders Textmode shoot'em up
* Copyright (c) 2002-2003 Sam Hocevar <sam@zoy.org>
* 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 <stdlib.h>

#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 );
}


+ 17
- 2
src/common.h Näytä tiedosto

@@ -3,7 +3,7 @@
* Copyright (c) 2002 Sam Hocevar <sam@zoy.org>
* 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


+ 25
- 2
src/main.c Näytä tiedosto

@@ -3,7 +3,7 @@
* Copyright (c) 2002 Sam Hocevar <sam@zoy.org>
* 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 );


+ 2
- 2
src/overlay.c Näytä tiedosto

@@ -3,7 +3,7 @@
* Copyright (c) 2002 Sam Hocevar <sam@zoy.org>
* 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[] = "==============================";


Ladataan…
Peruuta
Tallenna