Browse Source

* aliens are now named foo, bar and baz.

* beginning of life jauges.


git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/ttyvaders/trunk@60 92316355-f0b4-4df1-b90c-862c8a59935f
master
sam 22 years ago
parent
commit
0d33cbfaef
5 changed files with 61 additions and 25 deletions
  1. +19
    -19
      src/aliens.c
  2. +8
    -1
      src/collide.c
  3. +5
    -2
      src/common.h
  4. +2
    -2
      src/main.c
  5. +27
    -1
      src/player.c

+ 19
- 19
src/aliens.c View File

@@ -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: aliens.c,v 1.7 2002/12/22 22:17:41 sam Exp $
* $Id: aliens.c,v 1.8 2002/12/23 13:46:27 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,9 +24,9 @@


#include "common.h" #include "common.h"


static void draw_alien_poolp( game *g, int x, int y, int frame );
static void draw_alien_bool( game *g, int x, int y, int frame );
static void draw_alien_brah( game *g, int x, int y, int frame );
static void draw_alien_foo( game *g, int x, int y, int frame );
static void draw_alien_bar( game *g, int x, int y, int frame );
static void draw_alien_baz( game *g, int x, int y, int frame );


void init_aliens( game *g, aliens *al ) void init_aliens( game *g, aliens *al )
{ {
@@ -46,14 +46,14 @@ void draw_aliens( game *g, aliens *al )
{ {
switch( al->type[i] ) switch( al->type[i] )
{ {
case ALIEN_BRAH:
draw_alien_brah( g, al->x[i], al->y[i], al->img[i] % 8 );
case ALIEN_FOO:
draw_alien_foo( g, al->x[i], al->y[i], al->img[i] % 8 );
break; break;
case ALIEN_POOLP:
draw_alien_poolp( g, al->x[i], al->y[i], al->img[i] % 2 );
case ALIEN_BAR:
draw_alien_bar( g, al->x[i], al->y[i], al->img[i] % 2 );
break; break;
case ALIEN_BOOL:
draw_alien_bool( g, al->x[i], al->y[i], al->img[i] % 6 );
case ALIEN_BAZ:
draw_alien_baz( g, al->x[i], al->y[i], al->img[i] % 6 );
break; break;
case ALIEN_NONE: case ALIEN_NONE:
break; break;
@@ -78,9 +78,9 @@ void update_aliens( game *g, aliens *al )
/* Update coordinates */ /* Update coordinates */
switch( al->type[i] ) switch( al->type[i] )
{ {
case ALIEN_POOLP:
case ALIEN_BOOL:
case ALIEN_BRAH:
case ALIEN_FOO:
case ALIEN_BAR:
case ALIEN_BAZ:
al->x[i] = ((al->x[i] + 5) % (g->w + 3)) - 3; al->x[i] = ((al->x[i] + 5) % (g->w + 3)) - 3;
al->y[i] = al->y[i] + (rand() % 8) / 7 - (rand() % 8) / 7; al->y[i] = al->y[i] + (rand() % 8) / 7 - (rand() % 8) / 7;
al->img[i] = al->img[i] + 1; al->img[i] = al->img[i] + 1;
@@ -110,13 +110,13 @@ void add_alien( game *g, aliens *al, int x, int y, int type )


switch( al->type[i] ) switch( al->type[i] )
{ {
case ALIEN_POOLP:
case ALIEN_FOO:
al->life[i] = 3; al->life[i] = 3;
break; break;
case ALIEN_BOOL:
case ALIEN_BAR:
al->life[i] = 3; al->life[i] = 3;
break; break;
case ALIEN_BRAH:
case ALIEN_BAZ:
al->life[i] = 3; al->life[i] = 3;
break; break;
case ALIEN_NONE: case ALIEN_NONE:
@@ -128,7 +128,7 @@ void add_alien( game *g, aliens *al, int x, int y, int type )
} }
} }


static void draw_alien_poolp( game *g, int x, int y, int frame )
static void draw_alien_bar( game *g, int x, int y, int frame )
{ {
switch( frame ) switch( frame )
{ {
@@ -161,7 +161,7 @@ static void draw_alien_poolp( game *g, int x, int y, int frame )
} }
} }


static void draw_alien_bool( game *g, int x, int y, int frame )
static void draw_alien_baz( game *g, int x, int y, int frame )
{ {
gfx_color( GREEN ); gfx_color( GREEN );
gfx_goto( x, y-1 ); gfx_goto( x, y-1 );
@@ -199,7 +199,7 @@ static void draw_alien_bool( game *g, int x, int y, int frame )
gfx_putstr( "oo" ); gfx_putstr( "oo" );
} }


static void draw_alien_brah( game *g, int x, int y, int frame )
static void draw_alien_foo( game *g, int x, int y, int frame )
{ {
gfx_color( YELLOW ); gfx_color( YELLOW );




+ 8
- 1
src/collide.c View File

@@ -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.8 2002/12/23 09:28:37 sam Exp $
* $Id: collide.c,v 1.9 2002/12/23 13:46:27 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
@@ -261,15 +261,22 @@ void collide_weapons_aliens( game *g, weapons *wp, aliens *al, explosions *ex )


void collide_player_tunnel( game *g, player *p, tunnel *t, explosions *ex ) void collide_player_tunnel( game *g, player *p, tunnel *t, explosions *ex )
{ {
if( p->dead )
{
return;
}

if( p->x <= t->left[p->y] ) if( p->x <= t->left[p->y] )
{ {
p->x += 2; p->x += 2;
add_explosion( g, ex, p->x+1, p->y-2, 0, 0, EXPLOSION_SMALL ); add_explosion( g, ex, p->x+1, p->y-2, 0, 0, EXPLOSION_SMALL );
p->life -= 50;
} }
else if( p->x + 5 >= t->right[p->y] ) else if( p->x + 5 >= t->right[p->y] )
{ {
p->x -= 2; p->x -= 2;
add_explosion( g, ex, p->x+4, p->y-2, 0, 0, EXPLOSION_SMALL ); add_explosion( g, ex, p->x+4, p->y-2, 0, 0, EXPLOSION_SMALL );
p->life -= 50;
} }
} }



+ 5
- 2
src/common.h View File

@@ -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.12 2002/12/23 13:13:04 sam Exp $
* $Id: common.h,v 1.13 2002/12/23 13:46:27 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,6 +20,8 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */


#define MAX_LIFE 1000

#define STARS 50 #define STARS 50
#define WEAPONS 200 #define WEAPONS 200
#define BONUS 30 #define BONUS 30
@@ -104,12 +106,13 @@ typedef struct
int x, y; int x, y;
int vx, vy; int vx, vy;
int weapon, nuke; int weapon, nuke;
int life, dead;


} player; } player;


typedef struct typedef struct
{ {
enum { ALIEN_NONE, ALIEN_POOLP, ALIEN_BOOL, ALIEN_BRAH } type[ALIENS];
enum { ALIEN_NONE, ALIEN_FOO, ALIEN_BAR, ALIEN_BAZ } type[ALIENS];
int x[ALIENS]; int x[ALIENS];
int y[ALIENS]; int y[ALIENS];
int life[ALIENS]; int life[ALIENS];


+ 2
- 2
src/main.c View File

@@ -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.13 2002/12/23 13:13:04 sam Exp $
* $Id: main.c,v 1.14 2002/12/23 13:46:27 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
@@ -168,7 +168,7 @@ static void start_game (game *g)
/* XXX: to be removed */ /* XXX: to be removed */
if( GET_RAND(0,10) == 0 ) if( GET_RAND(0,10) == 0 )
{ {
int list[3] = { ALIEN_POOLP, ALIEN_BOOL, ALIEN_BRAH };
int list[3] = { ALIEN_FOO, ALIEN_BAR, ALIEN_BAZ };


add_alien( g, g->al, 0, rand() % g->h / 2, list[GET_RAND(0,3)] ); add_alien( g, g->al, 0, rand() % g->h / 2, list[GET_RAND(0,3)] );
} }


+ 27
- 1
src/player.c View File

@@ -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.5 2002/12/23 13:13:04 sam Exp $
* $Id: player.c,v 1.6 2002/12/23 13:46:27 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
@@ -35,6 +35,7 @@ player * create_player( game *g )
p->vy = 0; p->vy = 0;
p->weapon = 0; p->weapon = 0;
p->nuke = 0; p->nuke = 0;
p->life = MAX_LIFE;


return p; return p;
} }
@@ -46,6 +47,11 @@ void free_player( player *p )


void draw_player( game *g, player *p ) void draw_player( game *g, player *p )
{ {
if( p->dead )
{
return;
}

gfx_goto( p->x + 2, p->y - 2 ); gfx_goto( p->x + 2, p->y - 2 );
gfx_color( GREEN ); gfx_color( GREEN );
gfx_putstr( "/\\" ); gfx_putstr( "/\\" );
@@ -62,6 +68,19 @@ void draw_player( game *g, player *p )


void update_player( game *g, player *p ) void update_player( game *g, player *p )
{ {
if( p->dead )
{
return;
}

if( p->life <= 0 )
{
add_explosion( g, g->ex, p->x, p->y, 0, 0, EXPLOSION_SMALL );
p->dead = 1;
return;
}

/* Update weapon stats */
if( p->weapon ) if( p->weapon )
{ {
p->weapon--; p->weapon--;
@@ -72,6 +91,13 @@ void update_player( game *g, player *p )
p->nuke--; p->nuke--;
} }


/* Update life */
if( p->life < MAX_LIFE )
{
p->life++;
}

/* Update coords */
p->x += p->vx; p->x += p->vx;


if( p->vx < 0 ) if( p->vx < 0 )


Loading…
Cancel
Save