* lots of sanity checks in collide.c. * moved usleep() to graphics.c. * added random key generator in the dummy driver. * cosmetic changes in the energy bars. git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/ttyvaders/trunk@64 92316355-f0b4-4df1-b90c-862c8a59935fmaster
@@ -1,13 +1,13 @@ | |||||
dnl Autoconf settings for ttyvaders | dnl Autoconf settings for ttyvaders | ||||
AC_INIT(ttyvaders,0.0cvs-20021218) | |||||
AC_INIT(ttyvaders,0.0cvs-20021223) | |||||
AC_PREREQ(2.50) | AC_PREREQ(2.50) | ||||
AC_CONFIG_SRCDIR(src/main.c) | AC_CONFIG_SRCDIR(src/main.c) | ||||
AC_CONFIG_AUX_DIR(autotools) | AC_CONFIG_AUX_DIR(autotools) | ||||
AC_CANONICAL_SYSTEM | AC_CANONICAL_SYSTEM | ||||
AM_INIT_AUTOMAKE(ttyvaders,0.0cvs-20021218) | |||||
AM_INIT_AUTOMAKE(ttyvaders,0.0cvs-20021223) | |||||
AM_CONFIG_HEADER(config.h) | AM_CONFIG_HEADER(config.h) | ||||
AM_PROG_CC_C_O | AM_PROG_CC_C_O | ||||
@@ -3,7 +3,7 @@ | |||||
* Copyright (c) 2002 Sam Hocevar <sam@zoy.org> | * Copyright (c) 2002 Sam Hocevar <sam@zoy.org> | ||||
* All Rights Reserved | * All Rights Reserved | ||||
* | * | ||||
* $Id: collide.c,v 1.9 2002/12/23 13:46:27 sam Exp $ | |||||
* $Id: collide.c,v 1.10 2002/12/23 16:21:38 sam Exp $ | |||||
* | * | ||||
* This program is free software; you can redistribute it and/or modify | * 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 | * it under the terms of the GNU General Public License as published by | ||||
@@ -41,6 +41,11 @@ void collide_weapons_tunnel( game *g, weapons *wp, tunnel *t, explosions *ex ) | |||||
case WEAPON_SEEKER: | case WEAPON_SEEKER: | ||||
case WEAPON_BOMB: | case WEAPON_BOMB: | ||||
case WEAPON_FRAGBOMB: | case WEAPON_FRAGBOMB: | ||||
if( y < 0 || y >= g->h ) | |||||
{ | |||||
break; | |||||
} | |||||
if( x <= t->left[y] | if( x <= t->left[y] | ||||
|| x >= t->right[y] ) | || x >= t->right[y] ) | ||||
{ | { | ||||
@@ -50,19 +55,19 @@ void collide_weapons_tunnel( game *g, weapons *wp, tunnel *t, explosions *ex ) | |||||
if( x <= t->left[y] ) | if( x <= t->left[y] ) | ||||
{ | { | ||||
t->right[y-2] -= damage - 1; | |||||
t->left[y-1] -= damage; | |||||
if( y-2 >= 0 ) t->right[y-2] -= damage - 1; | |||||
if( y-1 >= 0 ) t->left[y-1] -= damage; | |||||
t->left[y] -= damage + 1; | t->left[y] -= damage + 1; | ||||
t->left[y+1] -= damage; | |||||
t->right[y+2] -= damage - 1; | |||||
if( y+1 < g->h ) t->left[y+1] -= damage; | |||||
if( y+2 < g->h ) t->right[y+2] -= damage - 1; | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
t->right[y-2] += damage - 1; | |||||
t->right[y-1] += damage; | |||||
if( y-2 >= 0 ) t->right[y-2] += damage - 1; | |||||
if( y-1 >= 0 ) t->right[y-1] += damage; | |||||
t->right[y] += damage + 1; | t->right[y] += damage + 1; | ||||
t->right[y+1] += damage; | |||||
t->right[y+2] += damage - 1; | |||||
if( y+1 < g->h ) t->right[y+1] += damage; | |||||
if( y+2 < g->h ) t->right[y+2] += damage - 1; | |||||
} | } | ||||
if( wp->type[i] == WEAPON_FRAGBOMB ) | if( wp->type[i] == WEAPON_FRAGBOMB ) | ||||
@@ -80,6 +85,11 @@ void collide_weapons_tunnel( game *g, weapons *wp, tunnel *t, explosions *ex ) | |||||
j < GET_MAX( 0, wp->vy[i] >> 4 ) ; | j < GET_MAX( 0, wp->vy[i] >> 4 ) ; | ||||
j++ ) | j++ ) | ||||
{ | { | ||||
if( y+j >= g->h || y+j < 0 ) | |||||
{ | |||||
continue; | |||||
} | |||||
if( x <= t->left[y+j] || x >= t->right[y+j] ) | if( x <= t->left[y+j] || x >= t->right[y+j] ) | ||||
{ | { | ||||
add_explosion( g, ex, x, y+j, 0, 1, EXPLOSION_SMALL ); | add_explosion( g, ex, x, y+j, 0, 1, EXPLOSION_SMALL ); | ||||
@@ -87,15 +97,27 @@ void collide_weapons_tunnel( game *g, weapons *wp, tunnel *t, explosions *ex ) | |||||
if( x <= t->left[y+j] ) | if( x <= t->left[y+j] ) | ||||
{ | { | ||||
t->left[y+j-1]--; | |||||
if( y+j-1 >= 0 ) | |||||
{ | |||||
t->left[y+j-1]--; | |||||
} | |||||
t->left[y+j] -= 2; | t->left[y+j] -= 2; | ||||
t->left[y+j+1]--; | |||||
if( y+j+1 < g->h ) | |||||
{ | |||||
t->left[y+j+1]--; | |||||
} | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
t->right[y+j-1]++; | |||||
if( y+j-1 >= 0 ) | |||||
{ | |||||
t->right[y+j-1]++; | |||||
} | |||||
t->right[y+j] += 2; | t->right[y+j] += 2; | ||||
t->right[y+j+1]++; | |||||
if( y+j+1 < g->h ) | |||||
{ | |||||
t->right[y+j+1]++; | |||||
} | |||||
} | } | ||||
break; | break; | ||||
} | } | ||||
@@ -268,15 +290,17 @@ void collide_player_tunnel( game *g, player *p, tunnel *t, explosions *ex ) | |||||
if( p->x <= t->left[p->y] ) | if( p->x <= t->left[p->y] ) | ||||
{ | { | ||||
p->x += 2; | |||||
add_explosion( g, ex, p->x+1, p->y-2, 0, 0, EXPLOSION_SMALL ); | |||||
p->life -= 50; | |||||
p->x += 3; | |||||
p->vx = 2; | |||||
add_explosion( g, ex, p->x+1, p->y-1, 0, 0, EXPLOSION_SMALL ); | |||||
p->life -= 80; | |||||
} | } | ||||
else if( p->x + 5 >= t->right[p->y] ) | else if( p->x + 5 >= t->right[p->y] ) | ||||
{ | { | ||||
p->x -= 2; | |||||
add_explosion( g, ex, p->x+4, p->y-2, 0, 0, EXPLOSION_SMALL ); | |||||
p->life -= 50; | |||||
p->x -= 3; | |||||
p->vx = -2; | |||||
add_explosion( g, ex, p->x+4, p->y-1, 0, 0, EXPLOSION_SMALL ); | |||||
p->life -= 80; | |||||
} | } | ||||
} | } | ||||
@@ -3,7 +3,7 @@ | |||||
* Copyright (c) 2002 Sam Hocevar <sam@zoy.org> | * Copyright (c) 2002 Sam Hocevar <sam@zoy.org> | ||||
* All Rights Reserved | * All Rights Reserved | ||||
* | * | ||||
* $Id: common.h,v 1.14 2002/12/23 15:06:13 sam Exp $ | |||||
* $Id: common.h,v 1.15 2002/12/23 16:21:38 sam Exp $ | |||||
* | * | ||||
* This program is free software; you can redistribute it and/or modify | * 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 | * it under the terms of the GNU General Public License as published by | ||||
@@ -55,10 +55,10 @@ | |||||
# define gfx_putchar(x) addch(x) | # define gfx_putchar(x) addch(x) | ||||
# define gfx_putstr(x) addstr(x) | # define gfx_putstr(x) addstr(x) | ||||
#else | #else | ||||
# define gfx_color(x) do{}while(0) | |||||
# define gfx_goto(x,y) do{}while(0) | |||||
# define gfx_putchar(x) do{}while(0) | |||||
# define gfx_putstr(x) do{}while(0) | |||||
# define gfx_color(x) (void)(x) | |||||
# define gfx_goto(x,y) do{ (void)(x); (void)(y); } while(0) | |||||
# define gfx_putchar(x) (void)(x) | |||||
# define gfx_putstr(x) (void)(x) | |||||
#endif | #endif | ||||
#define gfx_putcharTO(x,y,c) do{ gfx_goto(x,y); gfx_putchar(c); }while(0) | #define gfx_putcharTO(x,y,c) do{ gfx_goto(x,y); gfx_putchar(c); }while(0) | ||||
@@ -207,6 +207,7 @@ void update_explosions( game *g, explosions *ex ); | |||||
int init_graphics( void ); | int init_graphics( void ); | ||||
void init_game( game *g ); | void init_game( game *g ); | ||||
char get_key( void ); | char get_key( void ); | ||||
void gfx_delay( void ); | |||||
void clear_graphics( void ); | void clear_graphics( void ); | ||||
void refresh_graphics( void ); | void refresh_graphics( void ); | ||||
void end_graphics( void ); | void end_graphics( void ); | ||||
@@ -3,7 +3,7 @@ | |||||
* Copyright (c) 2002 Sam Hocevar <sam@zoy.org> | * Copyright (c) 2002 Sam Hocevar <sam@zoy.org> | ||||
* All Rights Reserved | * All Rights Reserved | ||||
* | * | ||||
* $Id: graphics.c,v 1.5 2002/12/23 10:06:27 sam Exp $ | |||||
* $Id: graphics.c,v 1.6 2002/12/23 16:21:38 sam Exp $ | |||||
* | * | ||||
* This program is free software; you can redistribute it and/or modify | * 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 | * it under the terms of the GNU General Public License as published by | ||||
@@ -20,7 +20,10 @@ | |||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||||
*/ | */ | ||||
#include "config.h" | |||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <unistd.h> | |||||
#include "common.h" | #include "common.h" | ||||
@@ -121,11 +124,28 @@ char get_key( void ) | |||||
} | } | ||||
#else | #else | ||||
/* Use dummy driver */ | /* Use dummy driver */ | ||||
char key = GET_RAND(0,256); | |||||
if( key != 'q' && key != 'p' && key != '\t' ) | |||||
{ | |||||
return key; | |||||
} | |||||
#endif | #endif | ||||
return 0; | return 0; | ||||
} | } | ||||
void gfx_delay( void ) | |||||
{ | |||||
#ifdef USE_SLANG | |||||
usleep(40000); | |||||
#elif USE_NCURSES | |||||
usleep(40000); | |||||
#else | |||||
/* Use dummy driver */ | |||||
#endif | |||||
} | |||||
void clear_graphics( void ) | void clear_graphics( void ) | ||||
{ | { | ||||
#ifdef USE_SLANG | #ifdef USE_SLANG | ||||
@@ -3,7 +3,7 @@ | |||||
* Copyright (c) 2002 Sam Hocevar <sam@zoy.org> | * Copyright (c) 2002 Sam Hocevar <sam@zoy.org> | ||||
* All Rights Reserved | * All Rights Reserved | ||||
* | * | ||||
* $Id: main.c,v 1.15 2002/12/23 15:06:13 sam Exp $ | |||||
* $Id: main.c,v 1.16 2002/12/23 16:21:38 sam Exp $ | |||||
* | * | ||||
* This program is free software; you can redistribute it and/or modify | * 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 | * it under the terms of the GNU General Public License as published by | ||||
@@ -24,7 +24,8 @@ | |||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include <unistd.h> | |||||
#include <time.h> | |||||
#include "common.h" | #include "common.h" | ||||
@@ -34,7 +35,7 @@ int main (int argc, char **argv) | |||||
{ | { | ||||
game *g = malloc(sizeof(game)); | game *g = malloc(sizeof(game)); | ||||
//srand(time(NULL)); | |||||
srand(time(NULL)); | |||||
if( init_graphics() ) | if( init_graphics() ) | ||||
{ | { | ||||
@@ -164,7 +165,7 @@ static void start_game (game *g) | |||||
} | } | ||||
} | } | ||||
usleep(40000); | |||||
gfx_delay(); | |||||
if( !poz || skip ) | if( !poz || skip ) | ||||
{ | { | ||||
@@ -200,7 +201,7 @@ static void start_game (game *g) | |||||
collide_weapons_aliens( g, g->wp, g->al, g->ex ); | collide_weapons_aliens( g, g->wp, g->al, g->ex ); | ||||
update_explosions( g, g->ex ); | update_explosions( g, g->ex ); | ||||
/*if(purcompteur%2)*/ update_tunnel( g, g->t ); | |||||
update_tunnel( g, g->t ); | |||||
} | } | ||||
/* Clear screen */ | /* Clear screen */ | ||||
@@ -3,7 +3,7 @@ | |||||
* Copyright (c) 2002 Sam Hocevar <sam@zoy.org> | * Copyright (c) 2002 Sam Hocevar <sam@zoy.org> | ||||
* All Rights Reserved | * All Rights Reserved | ||||
* | * | ||||
* $Id: overlay.c,v 1.1 2002/12/23 15:06:13 sam Exp $ | |||||
* $Id: overlay.c,v 1.2 2002/12/23 16:21:38 sam Exp $ | |||||
* | * | ||||
* This program is free software; you can redistribute it and/or modify | * 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 | * it under the terms of the GNU General Public License as published by | ||||
@@ -31,7 +31,7 @@ void draw_overlay( game *g ) | |||||
/* Draw life jauge */ | /* Draw life jauge */ | ||||
gfx_color( GRAY ); | gfx_color( GRAY ); | ||||
gfx_goto( 2, 1 ); | |||||
gfx_goto( 4, 1 ); | |||||
gfx_putstr( dots30 ); | gfx_putstr( dots30 ); | ||||
if( g->p->life > MAX_LIFE * 7 / 10 ) | if( g->p->life > MAX_LIFE * 7 / 10 ) | ||||
@@ -47,18 +47,18 @@ void draw_overlay( game *g ) | |||||
gfx_color( RED ); | gfx_color( RED ); | ||||
} | } | ||||
gfx_goto( 2, 1 ); | |||||
gfx_goto( 4, 1 ); | |||||
gfx_putstr( dashes30 + ( MAX_LIFE - g->p->life ) * 30 / MAX_LIFE ); | gfx_putstr( dashes30 + ( MAX_LIFE - g->p->life ) * 30 / MAX_LIFE ); | ||||
gfx_color( WHITE ); | gfx_color( WHITE ); | ||||
gfx_goto( 1, 1 ); | gfx_goto( 1, 1 ); | ||||
gfx_putstr( "L |" ); | |||||
gfx_goto( 34, 1 ); | |||||
gfx_putstr( "|" ); | gfx_putstr( "|" ); | ||||
gfx_goto( 32, 1 ); | |||||
gfx_putstr( "| L" ); | |||||
/* Draw weapon jauge */ | /* Draw weapon jauge */ | ||||
gfx_color( GRAY ); | gfx_color( GRAY ); | ||||
gfx_goto( 38, 1 ); | |||||
gfx_goto( 42, 1 ); | |||||
gfx_putstr( dots30 + 10 ); | gfx_putstr( dots30 + 10 ); | ||||
if( g->p->special > MAX_SPECIAL * 9 / 10 ) | if( g->p->special > MAX_SPECIAL * 9 / 10 ) | ||||
@@ -74,13 +74,13 @@ void draw_overlay( game *g ) | |||||
gfx_color( BLUE ); | gfx_color( BLUE ); | ||||
} | } | ||||
gfx_goto( 38, 1 ); | |||||
gfx_goto( 42, 1 ); | |||||
gfx_putstr( dashes30 + 10 + ( MAX_SPECIAL - g->p->special ) * 20 / MAX_SPECIAL ); | gfx_putstr( dashes30 + 10 + ( MAX_SPECIAL - g->p->special ) * 20 / MAX_SPECIAL ); | ||||
gfx_color( WHITE ); | gfx_color( WHITE ); | ||||
gfx_goto( 37, 1 ); | |||||
gfx_goto( 39, 1 ); | |||||
gfx_putstr( "S |" ); | |||||
gfx_goto( 62, 1 ); | |||||
gfx_putstr( "|" ); | gfx_putstr( "|" ); | ||||
gfx_goto( 58, 1 ); | |||||
gfx_putstr( "| S" ); | |||||
} | } | ||||
@@ -3,7 +3,7 @@ | |||||
* Copyright (c) 2002 Sam Hocevar <sam@zoy.org> | * Copyright (c) 2002 Sam Hocevar <sam@zoy.org> | ||||
* All Rights Reserved | * All Rights Reserved | ||||
* | * | ||||
* $Id: player.c,v 1.7 2002/12/23 15:06:13 sam Exp $ | |||||
* $Id: player.c,v 1.8 2002/12/23 16:21:38 sam Exp $ | |||||
* | * | ||||
* This program is free software; you can redistribute it and/or modify | * 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 | * it under the terms of the GNU General Public License as published by | ||||
@@ -36,6 +36,7 @@ player * create_player( game *g ) | |||||
p->weapon = 0; | p->weapon = 0; | ||||
p->special = MAX_SPECIAL; | p->special = MAX_SPECIAL; | ||||
p->life = MAX_LIFE; | p->life = MAX_LIFE; | ||||
p->dead = 0; | |||||
return p; | return p; | ||||
} | } | ||||