Просмотр исходного кода

* Coding style everywhere.

git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/ttyvaders/trunk@88 92316355-f0b4-4df1-b90c-862c8a59935f
master
sam 21 лет назад
Родитель
Сommit
5faeb00826
14 измененных файлов: 1005 добавлений и 1005 удалений
  1. +103
    -103
      src/aliens.c
  2. +35
    -35
      src/bonus.c
  3. +42
    -42
      src/box.c
  4. +5
    -5
      src/ceo.c
  5. +70
    -70
      src/collide.c
  6. +37
    -37
      src/common.h
  7. +109
    -109
      src/explosions.c
  8. +73
    -73
      src/main.c
  9. +3
    -3
      src/math.c
  10. +31
    -31
      src/overlay.c
  11. +28
    -28
      src/player.c
  12. +24
    -24
      src/starfield.c
  13. +54
    -54
      src/tunnel.c
  14. +391
    -391
      src/weapons.c

+ 103
- 103
src/aliens.c Просмотреть файл

@@ -24,36 +24,36 @@

#include "common.h"

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 );
static void draw_alien_foo(game *, int, int, int);
static void draw_alien_bar(game *, int, int, int);
static void draw_alien_baz(game *, int, int, int);

void init_aliens( game *g, aliens *al )
void init_aliens(game *g, aliens *al)
{
int i;

for( i = 0; i < ALIENS; i++ )
for(i = 0; i < ALIENS; i++)
{
al->type[i] = ALIEN_NONE;
}
}

void draw_aliens( game *g, aliens *al )
void draw_aliens(game *g, aliens *al)
{
int i;

for( i = 0; i < ALIENS; i++ )
for(i = 0; i < ALIENS; i++)
{
switch( al->type[i] )
switch(al->type[i])
{
case ALIEN_FOO:
draw_alien_foo( g, al->x[i], al->y[i], al->img[i] % 8 );
draw_alien_foo(g, al->x[i], al->y[i], al->img[i] % 8);
break;
case ALIEN_BAR:
draw_alien_bar( g, al->x[i], al->y[i], al->img[i] % 2 );
draw_alien_bar(g, al->x[i], al->y[i], al->img[i] % 2);
break;
case ALIEN_BAZ:
draw_alien_baz( g, al->x[i], al->y[i], al->img[i] % 6 );
draw_alien_baz(g, al->x[i], al->y[i], al->img[i] % 6);
break;
case ALIEN_NONE:
break;
@@ -61,22 +61,22 @@ void draw_aliens( game *g, aliens *al )
}
}

void update_aliens( game *g, aliens *al )
void update_aliens(game *g, aliens *al)
{
int i;

for( i = 0; i < ALIENS; i++ )
for(i = 0; i < ALIENS; i++)
{
/* If alien died, make it explode */
if( al->type[i] != ALIEN_NONE && al->life[i] < 0 )
if(al->type[i] != ALIEN_NONE && al->life[i] < 0)
{
add_explosion( g, g->ex, al->x[i], al->y[i], 0, 0, EXPLOSION_MEDIUM );
add_explosion(g, g->ex, al->x[i], al->y[i], 0, 0, EXPLOSION_MEDIUM);
al->type[i] = ALIEN_NONE;
add_bonus( g, g->bo, al->x[i], al->y[i], GET_RAND(0,5) ? BONUS_GREEN : BONUS_LIFE );
add_bonus(g, g->bo, al->x[i], al->y[i], GET_RAND(0,5) ? BONUS_GREEN : BONUS_LIFE);
}

/* Update coordinates */
switch( al->type[i] )
switch(al->type[i])
{
case ALIEN_FOO:
case ALIEN_BAR:
@@ -86,8 +86,8 @@ void update_aliens( game *g, aliens *al )
al->img[i] = al->img[i] + 1;

/* Check bounds */
if( al->y[i] < 0 ) al->y[i] = 0;
if( al->y[i] > g->w - 1 ) al->y[i] = g->w - 1;
if(al->y[i] < 0 ) al->y[i] = 0;
if(al->y[i] > g->w - 1 ) al->y[i] = g->w - 1;
break;
case ALIEN_NONE:
break;
@@ -95,20 +95,20 @@ void update_aliens( game *g, aliens *al )
}
}

void add_alien( game *g, aliens *al, int x, int y, int type )
void add_alien(game *g, aliens *al, int x, int y, int type)
{
int i;

for( i = 0; i < ALIENS; i++ )
for(i = 0; i < ALIENS; i++)
{
if( al->type[i] == ALIEN_NONE )
if(al->type[i] == ALIEN_NONE)
{
al->type[i] = type;
al->x[i] = x;
al->y[i] = y;
al->img[i] = 0;

switch( al->type[i] )
switch(al->type[i])
{
case ALIEN_FOO:
al->life[i] = 3;
@@ -128,132 +128,132 @@ void add_alien( game *g, aliens *al, int x, int y, int type )
}
}

static void draw_alien_bar( 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)
{
case 0:
ee_color( EE_MAGENTA );
ee_goto( x, y );
ee_putstr( ",---." );
ee_goto( x, y+1 );
ee_putchar( '\\' );
ee_color( EE_WHITE );
ee_putstr( "o O" );
ee_color( EE_MAGENTA );
ee_putchar( '/' );
ee_goto( x, y+2 );
ee_putstr( "^^^^^" );
ee_color(EE_MAGENTA);
ee_goto(x, y);
ee_putstr(",---.");
ee_goto(x, y+1);
ee_putchar('\\');
ee_color(EE_WHITE);
ee_putstr("o O");
ee_color(EE_MAGENTA);
ee_putchar('/');
ee_goto(x, y+2);
ee_putstr("^^^^^");
break;
case 1:
ee_color( EE_MAGENTA );
ee_goto( x, y );
ee_putstr( ",---." );
ee_goto( x, y+1 );
ee_putchar( '\\' );
ee_color( EE_WHITE );
ee_putstr( "O o" );
ee_color( EE_MAGENTA );
ee_putchar( '/' );
ee_goto( x, y+2 );
ee_putstr( "^^^^^" );
ee_color(EE_MAGENTA);
ee_goto(x, y);
ee_putstr(",---.");
ee_goto(x, y+1);
ee_putchar('\\');
ee_color(EE_WHITE);
ee_putstr("O o");
ee_color(EE_MAGENTA);
ee_putchar('/');
ee_goto(x, y+2);
ee_putstr("^^^^^");
break;
}
}

static void draw_alien_baz( game *g, int x, int y, int frame )
static void draw_alien_baz(game *g, int x, int y, int frame)
{
ee_color( EE_GREEN );
ee_goto( x, y-1 );
ee_putstr( "__" );
ee_color(EE_GREEN);
ee_goto(x, y-1);
ee_putstr("__");

ee_goto( x-1, y );
ee_putchar( '/' );
ee_goto( x+2, y );
ee_putchar( '\\' );
ee_goto(x-1, y);
ee_putchar('/');
ee_goto(x+2, y);
ee_putchar('\\');

switch( frame )
switch(frame)
{
case 3:
ee_goto( x-2, y+1 );
ee_putstr( "//'`\\\\" );
ee_goto(x-2, y+1);
ee_putstr("//'`\\\\");
break;
case 4:
case 2:
ee_goto( x-2, y+1 );
ee_putstr( "/(~~)\\" );
ee_goto(x-2, y+1);
ee_putstr("/(~~)\\");
break;
case 5:
case 1:
ee_goto( x-2, y+1 );
ee_putstr( "((^^))" );
ee_goto(x-2, y+1);
ee_putstr("((^^))");
break;
case 0:
ee_goto( x-1, y+1 );
ee_putstr( "\\\\//" );
ee_goto(x-1, y+1);
ee_putstr("\\\\//");
break;
}

ee_color( EE_WHITE );
ee_goto( x, y );
ee_putstr( "oo" );
ee_color(EE_WHITE);
ee_goto(x, y);
ee_putstr("oo");
}

static void draw_alien_foo( game *g, int x, int y, int frame )
static void draw_alien_foo(game *g, int x, int y, int frame)
{
ee_color( EE_YELLOW );
ee_color(EE_YELLOW);

switch( frame )
switch(frame)
{
case 0:
ee_goto( x, y );
ee_putchar( '.' );
ee_goto( x+6, y );
ee_putchar( ',' );
ee_goto( x+1, y+1 );
ee_putstr( "\\ X /" );
ee_goto(x, y);
ee_putchar('.');
ee_goto(x+6, y);
ee_putchar(',');
ee_goto(x+1, y+1);
ee_putstr("\\ X /");
break;
case 7:
case 1:
ee_goto( x-1, y );
ee_putchar( '.' );
ee_goto( x+7, y );
ee_putchar( ',' );
ee_goto( x, y+1 );
ee_putstr( "`- X -'" );
ee_goto(x-1, y);
ee_putchar('.');
ee_goto(x+7, y);
ee_putchar(',');
ee_goto(x, y+1);
ee_putstr("`- X -'");
break;
case 6:
case 2:
ee_goto( x-1, y+1 );
ee_putstr( "`-- X --'" );
ee_goto(x-1, y+1);
ee_putstr("`-- X --'");
break;
case 5:
case 3:
ee_goto( x, y+1 );
ee_putstr( ",- X -." );
ee_goto( x-1, y+2 );
ee_putchar( '\'' );
ee_goto( x+7, y+2 );
ee_putchar( '`' );
ee_goto(x, y+1);
ee_putstr(",- X -.");
ee_goto(x-1, y+2);
ee_putchar('\'');
ee_goto(x+7, y+2);
ee_putchar('`');
break;
case 4:
ee_goto( x+1, y+1 );
ee_putstr( ", X ." );
ee_goto( x, y+2 );
ee_putchar( '/' );
ee_goto( x+6, y+2 );
ee_putchar( '\\' );
ee_goto(x+1, y+1);
ee_putstr(", X .");
ee_goto(x, y+2);
ee_putchar('/');
ee_goto(x+6, y+2);
ee_putchar('\\');
break;
}

ee_goto( x+2, y+2 );
ee_putstr( "`V'" );
ee_goto(x+2, y+2);
ee_putstr("`V'");

ee_color( EE_WHITE );
ee_goto( x+2, y+1 );
ee_putchar( 'o' );
ee_goto( x+4, y+1 );
ee_putchar( 'o' );
ee_color(EE_WHITE);
ee_goto(x+2, y+1);
ee_putchar('o');
ee_goto(x+4, y+1);
ee_putchar('o');
}



+ 35
- 35
src/bonus.c Просмотреть файл

@@ -24,49 +24,49 @@

#include "common.h"

void init_bonus( game *g, bonus *bo )
void init_bonus(game *g, bonus *bo)
{
int i;

for( i = 0; i < BONUS; i++ )
for(i = 0; i < BONUS; i++)
{
bo->type[i] = BONUS_NONE;
}
}

void draw_bonus( game *g, bonus *bo )
void draw_bonus(game *g, bonus *bo)
{
int i;

for( i = 0; i < BONUS; i++ )
for(i = 0; i < BONUS; i++)
{
switch( bo->type[i] )
switch(bo->type[i])
{
case BONUS_GREEN:
ee_color( (bo->n[i]/2 % 3) ? EE_GREEN : EE_WHITE );
ee_goto( bo->x[i]+1, bo->y[i]-1 );
ee_putchar( '_' );
ee_goto( bo->x[i], bo->y[i] );
ee_putstr( "/ \\" );
ee_goto( bo->x[i], bo->y[i]+1 );
ee_putstr( "\\_/" );
ee_color( EE_WHITE );
ee_goto( bo->x[i]+1, bo->y[i] );
ee_putchar( 'g' );
ee_color((bo->n[i]/2 % 3) ? EE_GREEN : EE_WHITE);
ee_goto(bo->x[i]+1, bo->y[i]-1);
ee_putchar('_');
ee_goto(bo->x[i], bo->y[i]);
ee_putstr("/ \\");
ee_goto(bo->x[i], bo->y[i]+1);
ee_putstr("\\_/");
ee_color(EE_WHITE);
ee_goto(bo->x[i]+1, bo->y[i]);
ee_putchar('g');
break;
case BONUS_LIFE:
ee_color( (bo->n[i] % 3) ? EE_RED : EE_WHITE );
ee_goto( bo->x[i]+1, bo->y[i]-1 );
ee_putchar( '_' );
ee_goto( bo->x[i]+3, bo->y[i]-1 );
ee_putchar( '_' );
ee_goto( bo->x[i], bo->y[i] );
ee_putstr( "( ' )" );
ee_goto( bo->x[i]+1, bo->y[i]+1 );
ee_putstr( "`v'" );
ee_color( EE_WHITE );
ee_goto( bo->x[i]+3, bo->y[i] );
ee_putchar( '^' );
ee_color((bo->n[i] % 3) ? EE_RED : EE_WHITE);
ee_goto(bo->x[i]+1, bo->y[i]-1);
ee_putchar('_');
ee_goto(bo->x[i]+3, bo->y[i]-1);
ee_putchar('_');
ee_goto(bo->x[i], bo->y[i]);
ee_putstr("( ' )");
ee_goto(bo->x[i]+1, bo->y[i]+1);
ee_putstr("`v'");
ee_color(EE_WHITE);
ee_goto(bo->x[i]+3, bo->y[i]);
ee_putchar('^');
break;
case BONUS_NONE:
break;
@@ -74,18 +74,18 @@ void draw_bonus( game *g, bonus *bo )
}
}

void update_bonus( game *g, bonus *bo )
void update_bonus(game *g, bonus *bo)
{
int i;

for( i = 0; i < BONUS; i++ )
for(i = 0; i < BONUS; i++)
{
switch( bo->type[i] )
switch(bo->type[i])
{
case BONUS_GREEN:
bo->n[i]++;
bo->y[i]++;
if( bo->y[i] > g->h )
if(bo->y[i] > g->h)
{
bo->type[i] = BONUS_NONE;
}
@@ -93,7 +93,7 @@ void update_bonus( game *g, bonus *bo )
case BONUS_LIFE:
bo->n[i]++;
bo->y[i]++;
if( bo->y[i] > g->h )
if(bo->y[i] > g->h)
{
bo->type[i] = BONUS_NONE;
}
@@ -104,13 +104,13 @@ void update_bonus( game *g, bonus *bo )
}
}

void add_bonus( game *g, bonus *bo, int x, int y, int type )
void add_bonus(game *g, bonus *bo, int x, int y, int type)
{
int i;

for( i = 0; i < BONUS; i++ )
for(i = 0; i < BONUS; i++)
{
if( bo->type[i] == BONUS_NONE )
if(bo->type[i] == BONUS_NONE)
{
bo->type[i] = type;
bo->x[i] = x;


+ 42
- 42
src/box.c Просмотреть файл

@@ -24,9 +24,9 @@

#include "common.h"

box * create_box( game *g, int x, int y, int w, int h )
box * create_box(game *g, int x, int y, int w, int h)
{
box *b = malloc( sizeof( box ) );
box *b = malloc(sizeof( box ));

b->x = x;
b->y = y;
@@ -37,21 +37,21 @@ box * create_box( game *g, int x, int y, int w, int h )
return b;
}

void draw_box( game *g, box *b )
void draw_box(game *g, box *b)
{
int i, j, frame;

ee_color( EE_YELLOW );
ee_color(EE_YELLOW);

/* Draw the thin horizontal line */
if( b->frame < 8 )
if(b->frame < 8)
{
for( i = b->x - b->w * b->frame / 16 ;
for(i = b->x - b->w * b->frame / 16 ;
i < b->x + b->w * b->frame / 16 ;
i++ )
i++)
{
ee_goto( i, b->y );
ee_putchar( 'X' );
ee_goto(i, b->y);
ee_putchar('X');
}

return;
@@ -60,64 +60,64 @@ void draw_box( game *g, box *b )
/* Draw the frame */
frame = b->frame < 12 ? b->frame : 12;

for( i = b->x - b->w / 2 ;
for(i = b->x - b->w / 2 ;
i < b->x + b->w / 2 ;
i++ )
i++)
{
ee_goto( i, b->y - b->h * (frame - 8) / 8 );
ee_putchar( 'X' );
ee_goto( i, b->y + b->h * (frame - 8) / 8 );
ee_putchar( 'X' );
ee_goto(i, b->y - b->h * (frame - 8) / 8);
ee_putchar('X');
ee_goto(i, b->y + b->h * (frame - 8) / 8);
ee_putchar('X');
}

for( j = b->y - b->h * (frame - 8) / 8 ;
for(j = b->y - b->h * (frame - 8) / 8 ;
j < b->y + b->h * (frame - 8) / 8 ;
j++ )
j++)
{
ee_goto( b->x - b->w / 2, j );
ee_putchar( 'X' );
ee_goto( b->x + b->w / 2 - 1, j );
ee_putchar( 'X' );
ee_goto(b->x - b->w / 2, j);
ee_putchar('X');
ee_goto(b->x + b->w / 2 - 1, j);
ee_putchar('X');
}

ee_color( EE_BLACK );
ee_color(EE_BLACK);

for( j = b->y - b->h * (frame - 8) / 8 + 1 ;
for(j = b->y - b->h * (frame - 8) / 8 + 1 ;
j < b->y + b->h * (frame - 8) / 8 ;
j++ )
j++)
{
for( i = b->x - b->w / 2 + 1 ;
for(i = b->x - b->w / 2 + 1 ;
i < b->x + b->w / 2 - 1 ;
i++ )
i++)
{
ee_goto( i, j );
ee_putchar( 'X' );
ee_goto(i, j);
ee_putchar('X');
}
}

if( b->frame < 12 )
if(b->frame < 12)
{
return;
}

/* Draw the text inside the frame */
ee_color( EE_YELLOW );
ee_color(EE_YELLOW);

/* FIXME: use a font */
ee_goto( b->x - b->w / 2 + 12, b->y - b->h / 2 + 2 );
ee_putstr( "XXXX. .XXXX X X .XXXX .XXXX XXXX." );
ee_goto( b->x - b->w / 2 + 12, b->y - b->h / 2 + 3 );
ee_putstr( "X `X X' X X X X' X' X `X" );
ee_goto( b->x - b->w / 2 + 12, b->y - b->h / 2 + 4 );
ee_putstr( "XXXX' XXXXX X X `XXX XXXX X X" );
ee_goto( b->x - b->w / 2 + 12, b->y - b->h / 2 + 5 );
ee_putstr( "X' X' `X X. ,X `X X' X ,X" );
ee_goto( b->x - b->w / 2 + 12, b->y - b->h / 2 + 6 );
ee_putstr( "X X X `XXXX XXXX' `XXXX XXXX'" );
ee_goto(b->x - b->w / 2 + 12, b->y - b->h / 2 + 2);
ee_putstr("XXXX. .XXXX X X .XXXX .XXXX XXXX.");
ee_goto(b->x - b->w / 2 + 12, b->y - b->h / 2 + 3);
ee_putstr("X `X X' X X X X' X' X `X");
ee_goto(b->x - b->w / 2 + 12, b->y - b->h / 2 + 4);
ee_putstr("XXXX' XXXXX X X `XXX XXXX X X");
ee_goto(b->x - b->w / 2 + 12, b->y - b->h / 2 + 5);
ee_putstr("X' X' `X X. ,X `X X' X ,X");
ee_goto(b->x - b->w / 2 + 12, b->y - b->h / 2 + 6);
ee_putstr("X X X `XXXX XXXX' `XXXX XXXX'");
}

void free_box( box *b )
void free_box(box *b)
{
free( b );
free(b);
}


+ 5
- 5
src/ceo.c Просмотреть файл

@@ -27,23 +27,23 @@

#include "common.h"

void ceo_alert( game *g )
void ceo_alert(game *g)
{
int end = 0;

while( !end )
while(!end)
{
ee_clear();

if( ee_get_key() == '\t' )
if(ee_get_key() == '\t')
{
end = 1;
}

fprintf( stderr, "foo\n" );
fprintf(stderr, "foo\n");

ee_refresh();

usleep( 40000 );
usleep(40000);
}
}

+ 70
- 70
src/collide.c Просмотреть файл

@@ -3,7 +3,7 @@
* Copyright (c) 2002 Sam Hocevar <sam@zoy.org>
* All Rights Reserved
*
* $Id: collide.c,v 1.11 2003/01/06 12:22:58 sam Exp $
* $Id$
*
* 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,16 +24,16 @@

#include "common.h"

void collide_weapons_tunnel( game *g, weapons *wp, tunnel *t, explosions *ex )
void collide_weapons_tunnel(game *g, weapons *wp, tunnel *t, explosions *ex)
{
int i, j, x, y;

for( i = 0; i < WEAPONS; i++ )
for(i = 0; i < WEAPONS; i++)
{
x = wp->x[i] >> 4;
y = wp->y[i] >> 4;

switch( wp->type[i] )
switch(wp->type[i])
{
case WEAPON_LIGHTNING:
case WEAPON_NONE:
@@ -41,36 +41,36 @@ void collide_weapons_tunnel( game *g, weapons *wp, tunnel *t, explosions *ex )
case WEAPON_SEEKER:
case WEAPON_BOMB:
case WEAPON_FRAGBOMB:
if( y < 0 || y >= g->h )
if(y < 0 || y >= g->h)
{
break;
}

if( x <= t->left[y]
|| x >= t->right[y] )
if(x <= t->left[y]
|| x >= t->right[y])
{
int damage = wp->type[i] == WEAPON_SEEKER ? 1 : 2;

add_explosion( g, ex, x, y, 0, 1, wp->type[i] == WEAPON_SEEKER ? EXPLOSION_SMALL : EXPLOSION_MEDIUM );
add_explosion(g, ex, x, y, 0, 1, wp->type[i] == WEAPON_SEEKER ? EXPLOSION_SMALL : EXPLOSION_MEDIUM);

if( x <= t->left[y] )
if(x <= t->left[y])
{
if( y-2 >= 0 ) t->left[y-2] -= damage - 1;
if( y-1 >= 0 ) t->left[y-1] -= damage;
if(y-2 >= 0) t->left[y-2] -= damage - 1;
if(y-1 >= 0) t->left[y-1] -= damage;
t->left[y] -= damage + 1;
if( y+1 < g->h ) t->left[y+1] -= damage;
if( y+2 < g->h ) t->left[y+2] -= damage - 1;
if(y+1 < g->h) t->left[y+1] -= damage;
if(y+2 < g->h) t->left[y+2] -= damage - 1;
}
else
{
if( y-2 >= 0 ) t->right[y-2] += damage - 1;
if( y-1 >= 0 ) 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;
if( y+1 < g->h ) t->right[y+1] += damage;
if( y+2 < g->h ) 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)
{
wp->n[i] = -1;
}
@@ -81,55 +81,55 @@ void collide_weapons_tunnel( game *g, weapons *wp, tunnel *t, explosions *ex )
}
break;
case WEAPON_LASER:
for( j = GET_MIN( 0, wp->vy[i] >> 4 ) ;
j < GET_MAX( 0, wp->vy[i] >> 4 ) ;
j++ )
for(j = GET_MIN(0, wp->vy[i] >> 4);
j < GET_MAX(0, wp->vy[i] >> 4);
j++)
{
if( y+j >= g->h || y+j < 0 )
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);
wp->type[i] = WEAPON_NONE;

if( x <= t->left[y+j] )
if(x <= t->left[y+j])
{
if( y+j-1 >= 0 ) t->left[y+j-1]--;
if(y+j-1 >= 0) t->left[y+j-1]--;
t->left[y+j] -= 2;
if( y+j+1 < g->h ) t->left[y+j+1]--;
if(y+j+1 < g->h) t->left[y+j+1]--;
}
else
{
if( y+j-1 >= 0 ) t->right[y+j-1]++;
if(y+j-1 >= 0) t->right[y+j-1]++;
t->right[y+j] += 2;
if( y+j+1 < g->h ) t->right[y+j+1]++;
if(y+j+1 < g->h) t->right[y+j+1]++;
}
break;
}
}
break;
case WEAPON_BEAM:
if( wp->n[i] > 19 )
if(wp->n[i] > 19)
{
break;
}

j = (29 - wp->n[i]) * (29 - wp->n[i]) / 8;
j = GET_MIN( y, j );
j = GET_MIN(y, j);

for( ; j > 0 ; j-- )
for(; j > 0; j--)
{
if( x - 2 <= t->left[y-j] )
if(x - 2 <= t->left[y-j])
{
add_explosion( g, ex, GET_MIN(t->left[y-j], x+3), y-j, 0, 1, EXPLOSION_SMALL );
add_explosion(g, ex, GET_MIN(t->left[y-j], x+3), y-j, 0, 1, EXPLOSION_SMALL);
t->left[y-j] -= GET_RAND(0,3);
}
else if( x + 3 >= t->right[y-j] )
else if(x + 3 >= t->right[y-j])
{
add_explosion( g, ex, GET_MAX(t->right[y-j], x-2), y-j, 0, 1, EXPLOSION_SMALL );
add_explosion(g, ex, GET_MAX(t->right[y-j], x-2), y-j, 0, 1, EXPLOSION_SMALL);
t->right[y-j] += GET_RAND(0,3);
}
}
@@ -142,11 +142,11 @@ 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_weapons_aliens(game *g, weapons *wp, aliens *al, explosions *ex)
{
int i, j, k, x, y;

for( i = 0; i < WEAPONS; i++ )
for(i = 0; i < WEAPONS; i++)
{
int ok = 0;
int r;
@@ -154,7 +154,7 @@ void collide_weapons_aliens( game *g, weapons *wp, aliens *al, explosions *ex )
x = wp->x[i] >> 4;
y = wp->y[i] >> 4;

switch( wp->type[i] )
switch(wp->type[i])
{
case WEAPON_LIGHTNING:
case WEAPON_NONE:
@@ -163,17 +163,17 @@ void collide_weapons_aliens( game *g, weapons *wp, aliens *al, explosions *ex )
/* Big nuke */
r = (29 - wp->n[i]) * (29 - wp->n[i]) / 8;

for( j = 0; j < ALIENS; j++ )
for(j = 0; j < ALIENS; j++)
{
if( al->type[j] == ALIEN_NONE || al->life[j] < 0 )
if(al->type[j] == ALIEN_NONE || al->life[j] < 0)
{
continue;
}

if( wp->n[i] == 0 /* Nuke destroys _everything_ */ ||
if(wp->n[i] == 0 /* Nuke destroys _everything_ */ ||
(al->x[j] - x) * (al->x[j] - x)
+ 4 * (al->y[j] - y) * (al->y[j] - y)
<= r * r )
<= r * r)
{
/* Kill alien, not nuke */
al->life[j] -= 10;
@@ -182,22 +182,22 @@ void collide_weapons_aliens( game *g, weapons *wp, aliens *al, explosions *ex )
break;

case WEAPON_BEAM:
if( wp->n[i] > 19 )
if(wp->n[i] > 19)
{
break;
}

r = (29 - wp->n[i]) * (29 - wp->n[i]) / 8;

for( j = 0; j < ALIENS; j++ )
for(j = 0; j < ALIENS; j++)
{
if( al->type[j] == ALIEN_NONE || al->life[j] < 0 )
if(al->type[j] == ALIEN_NONE || al->life[j] < 0)
{
continue;
}

if( x >= al->x[j] && x <= al->x[j] + 4
&& y >= al->y[j] + 2 && y-5-r <= al->y[j] )
if(x >= al->x[j] && x <= al->x[j] + 4
&& y >= al->y[j] + 2 && y-5-r <= al->y[j])
{
al->life[j] -= 4;
}
@@ -205,19 +205,19 @@ void collide_weapons_aliens( game *g, weapons *wp, aliens *al, explosions *ex )
break;

case WEAPON_LASER:
for( j = 0; j < ALIENS; j++ )
for(j = 0; j < ALIENS; j++)
{
if( al->type[j] == ALIEN_NONE || al->life[j] < 0 )
if(al->type[j] == ALIEN_NONE || al->life[j] < 0)
{
continue;
}

for( k = GET_MIN( 0, wp->vy[i] >> 4 ) ;
k < GET_MAX( 0, wp->vy[i] >> 4 ) ;
k++ )
for(k = GET_MIN(0, wp->vy[i] >> 4);
k < GET_MAX(0, wp->vy[i] >> 4);
k++)
{
if( x >= al->x[j] && x <= al->x[j] + 4
&& y+k >= al->y[j] && y+k <= al->y[j] + 2 )
if(x >= al->x[j] && x <= al->x[j] + 4
&& y+k >= al->y[j] && y+k <= al->y[j] + 2)
{
al->life[j]--;
ok = 1;
@@ -226,9 +226,9 @@ void collide_weapons_aliens( game *g, weapons *wp, aliens *al, explosions *ex )
}
}

if( ok )
if(ok)
{
add_explosion( g, ex, x, y+1, 0, 0, EXPLOSION_SMALL );
add_explosion(g, ex, x, y+1, 0, 0, EXPLOSION_SMALL);
wp->type[i] = WEAPON_NONE;
}
break;
@@ -236,26 +236,26 @@ void collide_weapons_aliens( game *g, weapons *wp, aliens *al, explosions *ex )
case WEAPON_SEEKER:
case WEAPON_BOMB:
case WEAPON_FRAGBOMB:
for( j = 0; j < ALIENS; j++ )
for(j = 0; j < ALIENS; j++)
{
if( al->type[j] == ALIEN_NONE || al->life[j] < 0 )
if(al->type[j] == ALIEN_NONE || al->life[j] < 0)
{
continue;
}

if( x >= al->x[j] && x <= al->x[j] + 4
&& y >= al->y[j] && y <= al->y[j] + 2 )
if(x >= al->x[j] && x <= al->x[j] + 4
&& y >= al->y[j] && y <= al->y[j] + 2)
{
al->life[j] -= wp->type[i] == WEAPON_SEEKER ? 1 : 5;
ok = 1;
}
}

if( ok )
if(ok)
{
add_explosion( g, ex, x, y+1, 0, 0, wp->type[i] == WEAPON_SEEKER ? EXPLOSION_SMALL : EXPLOSION_MEDIUM );
add_explosion(g, ex, x, y+1, 0, 0, wp->type[i] == WEAPON_SEEKER ? EXPLOSION_SMALL : EXPLOSION_MEDIUM);

if( wp->type[i] == WEAPON_FRAGBOMB )
if(wp->type[i] == WEAPON_FRAGBOMB)
{
wp->n[i] = -1;
}
@@ -269,25 +269,25 @@ 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 )
if(p->dead)
{
return;
}

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


+ 37
- 37
src/common.h Просмотреть файл

@@ -146,85 +146,85 @@ typedef struct
/*
* 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 );
void init_aliens(game *, aliens *);
void draw_aliens(game *, aliens *);
void update_aliens(game *, aliens *);
void add_alien(game *, aliens *, int, int, int);

/*
* 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 );
void init_bonus(game *, bonus *);
void draw_bonus(game *, bonus *);
void update_bonus(game *, bonus *);
void add_bonus(game *, bonus *, int, int, int);

/*
* 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 );
box * create_box(game *, int, int, int, int);
void draw_box(game *, box *);
void free_box(box *);

/*
* From ceo.c
*/
void ceo_alert( game *g );
void ceo_alert(game *);

/*
* 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 );
void collide_weapons_tunnel(game *, weapons *, tunnel *, explosions *);
void collide_weapons_aliens(game *, weapons *, aliens *, explosions *);
void collide_player_tunnel(game *, player *, tunnel *, explosions *);

/*
* 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 );
void init_explosions(game *, explosions *);
void add_explosion(game *, explosions *, int, int, int, int, int);
void draw_explosions(game *, explosions *);
void update_explosions(game *, explosions *);

/*
* From math.c
*/
int r00t( int a );
int r00t(int);

/*
* From overlay.c
*/
void draw_status( game *g );
void draw_status(game *);

/*
* 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 );
player * create_player(game *);
void free_player(player *);
void draw_player(game *, player *);
void update_player(game *, player *);

/*
* 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 );
starfield * create_starfield(game *);
void draw_starfield(game *, starfield *);
void update_starfield(game *, starfield *);
void free_starfield(game *, starfield *);

/*
* 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 );
tunnel * create_tunnel(game *, int, int);
void free_tunnel(tunnel *);
void draw_tunnel(game *, tunnel *);
void update_tunnel(game *, tunnel *);

/*
* 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 );
void init_weapons(game *, weapons *);
void draw_weapons(game *, weapons *);
void update_weapons(game *, weapons *);
void add_weapon(game *, weapons *, int, int, int, int, int);


+ 109
- 109
src/explosions.c Просмотреть файл

@@ -24,33 +24,33 @@

#include "common.h"

static void draw_small_explosion( int x, int y, int frame );
static void draw_medium_explosion( int x, int y, int frame );
static void draw_small_explosion(int x, int y, int frame);
static void draw_medium_explosion(int x, int y, int frame);

void init_explosions( game *g, explosions *ex )
void init_explosions(game *g, explosions *ex)
{
int i;

for( i = 0; i < EXPLOSIONS; i++ )
for(i = 0; i < EXPLOSIONS; i++)
{
ex->type[i] = EXPLOSION_NONE;
}
}

void add_explosion( game *g, explosions *ex, int x, int y, int vx, int vy, int type )
void add_explosion(game *g, explosions *ex, int x, int y, int vx, int vy, int type)
{
int i;

for( i = 0; i < EXPLOSIONS; i++ )
for(i = 0; i < EXPLOSIONS; i++)
{
if( ex->type[i] == EXPLOSION_NONE )
if(ex->type[i] == EXPLOSION_NONE)
{
ex->type[i] = type;
ex->x[i] = x;
ex->y[i] = y;
ex->vx[i] = vx;
ex->vy[i] = vy;
switch( type )
switch(type)
{
case EXPLOSION_MEDIUM:
ex->n[i] = 11;
@@ -64,44 +64,44 @@ void add_explosion( game *g, explosions *ex, int x, int y, int vx, int vy, int t
}
}

void draw_explosions( game *g, explosions *ex )
void draw_explosions(game *g, explosions *ex)
{
int i;

for( i = 0; i < EXPLOSIONS; i++ )
for(i = 0; i < EXPLOSIONS; i++)
{
#if 0
ee_color( GREEN );
ee_goto( ex->x[i] + 3, ex->y[i] );
switch( GET_RAND(0,3) )
ee_color(GREEN);
ee_goto(ex->x[i] + 3, ex->y[i]);
switch(GET_RAND(0,3))
{
case 0:
ee_putchar( 'p' );
ee_putchar( 'i' );
ee_putchar( 'f' );
ee_putchar('p');
ee_putchar('i');
ee_putchar('f');
break;
case 1:
ee_putchar( 'p' );
ee_putchar( 'a' );
ee_putchar( 'f' );
ee_putchar('p');
ee_putchar('a');
ee_putchar('f');
break;
case 2:
ee_putchar( 'p' );
ee_putchar( 'o' );
ee_putchar( 'u' );
ee_putchar( 'f' );
ee_putchar('p');
ee_putchar('o');
ee_putchar('u');
ee_putchar('f');
break;
}
ee_putchar( '!' );
ee_putchar('!');
#endif

switch( ex->type[i] )
switch(ex->type[i])
{
case EXPLOSION_MEDIUM:
draw_medium_explosion( ex->x[i], ex->y[i], ex->n[i] );
draw_medium_explosion(ex->x[i], ex->y[i], ex->n[i]);
break;
case EXPLOSION_SMALL:
draw_small_explosion( ex->x[i], ex->y[i], ex->n[i] );
draw_small_explosion(ex->x[i], ex->y[i], ex->n[i]);
break;
case EXPLOSION_NONE:
break;
@@ -109,20 +109,20 @@ void draw_explosions( game *g, explosions *ex )
}
}

void update_explosions( game *g, explosions *ex )
void update_explosions(game *g, explosions *ex)
{
int i;

for( i = 0; i < EXPLOSIONS; i++ )
for(i = 0; i < EXPLOSIONS; i++)
{
switch( ex->type[i] )
switch(ex->type[i])
{
case EXPLOSION_MEDIUM:
case EXPLOSION_SMALL:
ex->x[i] += ex->vx[i];
ex->y[i] += ex->vy[i];
ex->n[i]--;
if( ex->n[i] < 0 )
if(ex->n[i] < 0)
{
ex->type[i] = EXPLOSION_NONE;
}
@@ -133,121 +133,121 @@ void update_explosions( game *g, explosions *ex )
}
}

static void draw_small_explosion( int x, int y, int frame )
static void draw_small_explosion(int x, int y, int frame)
{
switch( frame )
switch(frame)
{
case 6:
ee_color( EE_YELLOW );
ee_goto( x, y );
ee_putchar( '+' );
ee_color(EE_YELLOW);
ee_goto(x, y);
ee_putchar('+');
break;
case 5:
ee_color( EE_YELLOW );
ee_goto( x, y );
ee_putchar( 'o' );
ee_color(EE_YELLOW);
ee_goto(x, y);
ee_putchar('o');
break;
case 4:
ee_color( EE_YELLOW );
ee_goto( x, y-1 );
ee_putchar( '_' );
ee_goto( x-1, y );
ee_putstr( ")_(" );
ee_color(EE_YELLOW);
ee_goto(x, y-1);
ee_putchar('_');
ee_goto(x-1, y);
ee_putstr(")_(");
break;
case 3:
ee_color( EE_YELLOW );
ee_goto( x-1, y-1 );
ee_putstr( "._," );
ee_goto( x-1, y );
ee_putstr( ")_(" );
ee_goto( x-1, y+1 );
ee_putstr( "\' `" );
ee_color(EE_YELLOW);
ee_goto(x-1, y-1);
ee_putstr("._,");
ee_goto(x-1, y);
ee_putstr(")_(");
ee_goto(x-1, y+1);
ee_putstr("\' `");
break;
case 2:
ee_color( EE_YELLOW );
ee_goto( x-1, y-1 );
ee_putstr( ".v," );
ee_goto( x-1, y );
ee_putstr( "> <" );
ee_goto( x-1, y+1 );
ee_putstr( "\'^`" );
ee_color(EE_YELLOW);
ee_goto(x-1, y-1);
ee_putstr(".v,");
ee_goto(x-1, y);
ee_putstr("> <");
ee_goto(x-1, y+1);
ee_putstr("\'^`");
break;
case 1:
ee_color( EE_WHITE );
ee_goto( x-1, y-1 );
ee_putstr( ". ," );
ee_goto( x-1, y );
ee_putstr( " " );
ee_goto( x-1, y+1 );
ee_putstr( "\' `" );
ee_color(EE_WHITE);
ee_goto(x-1, y-1);
ee_putstr(". ,");
ee_goto(x-1, y);
ee_putstr(" ");
ee_goto(x-1, y+1);
ee_putstr("\' `");
break;
}
}

static void draw_medium_explosion( int x, int y, int frame )
static void draw_medium_explosion(int x, int y, int frame)
{
ee_color( EE_YELLOW );
ee_color(EE_YELLOW);

switch( frame )
switch(frame)
{
case 10:
ee_goto( x, y );
ee_putchar( '+' );
ee_goto(x, y);
ee_putchar('+');
break;
case 9:
ee_goto( x, y );
ee_putchar( 'o' );
ee_goto(x, y);
ee_putchar('o');
break;
case 8:
ee_goto( x, y-1 );
ee_putchar( '_' );
ee_goto( x-1, y );
ee_putstr( ")_(" );
ee_goto(x, y-1);
ee_putchar('_');
ee_goto(x-1, y);
ee_putstr(")_(");
break;
case 7:
ee_goto( x-1, y-1 );
ee_putstr( "._," );
ee_goto( x-1, y );
ee_putstr( ")_(" );
ee_goto( x-1, y+1 );
ee_putstr( "\' `" );
ee_goto(x-1, y-1);
ee_putstr("._,");
ee_goto(x-1, y);
ee_putstr(")_(");
ee_goto(x-1, y+1);
ee_putstr("\' `");
break;
case 6:
ee_goto( x-1, y-1 );
ee_putstr( ".v," );
ee_goto( x-1, y );
ee_putstr( "> <" );
ee_goto( x-1, y+1 );
ee_putstr( "\'^`" );
ee_goto(x-1, y-1);
ee_putstr(".v,");
ee_goto(x-1, y);
ee_putstr("> <");
ee_goto(x-1, y+1);
ee_putstr("\'^`");
break;
case 5:
ee_color( EE_RED );
ee_color(EE_RED);
case 4:
ee_goto( x-2, y-1 );
ee_putstr( "_\\~/_" );
ee_goto( x-2, y );
ee_putstr( "> <" );
ee_goto( x-2, y+1 );
ee_putstr( "~/_\\~" );
ee_goto(x-2, y-1);
ee_putstr("_\\~/_");
ee_goto(x-2, y);
ee_putstr("> <");
ee_goto(x-2, y+1);
ee_putstr("~/_\\~");
break;
case 3:
ee_color( EE_RED );
ee_color(EE_RED);
case 2:
ee_goto( x-2, y-1 );
ee_putstr( "_\\ /_" );
ee_goto( x-2, y );
ee_putstr( "_ _" );
ee_goto( x-2, y+1 );
ee_putstr( " / \\ " );
ee_goto(x-2, y-1);
ee_putstr("_\\ /_");
ee_goto(x-2, y);
ee_putstr("_ _");
ee_goto(x-2, y+1);
ee_putstr(" / \\ ");
break;
case 1:
ee_color( EE_WHITE );
ee_goto( x-2, y-1 );
ee_putstr( ". \' ," );
ee_goto( x-2, y );
ee_putstr( " " );
ee_goto( x-2, y+1 );
ee_putstr( "\' . `" );
ee_color(EE_WHITE);
ee_goto(x-2, y-1);
ee_putstr(". \' ,");
ee_goto(x-2, y);
ee_putstr(" ");
ee_goto(x-2, y+1);
ee_putstr("\' . `");
break;
}
}


+ 73
- 73
src/main.c Просмотреть файл

@@ -37,7 +37,7 @@ int main (int argc, char **argv)

srand(time(NULL));

if( ee_init() )
if(ee_init())
{
return 1;
}
@@ -64,174 +64,174 @@ static void start_game (game *g)

box *pausebox = NULL;

g->sf = create_starfield( g );
g->sf = create_starfield(g);
g->wp = malloc(sizeof(weapons));
g->ex = malloc(sizeof(explosions));
g->bo = malloc(sizeof(bonus));
g->t = create_tunnel( g, g->w, g->h );
g->p = create_player( g );
g->t = create_tunnel(g, g->w, g->h);
g->p = create_player(g);
g->al = malloc(sizeof(aliens));

init_bonus( g, g->bo );
init_weapons( g, g->wp );
init_explosions( g, g->ex );
init_aliens( g, g->al );
init_bonus(g, g->bo);
init_weapons(g, g->wp);
init_explosions(g, g->ex);
init_aliens(g, g->al);

/* Temporary stuff */
g->t->w = 25;

while( !quit )
while(!quit)
{
char key;

while( ( key = ee_get_key() ) )
while((key = ee_get_key()))
{
switch( key )
switch(key)
{
case 'q':
quit = 1;
break;
case 'p':
poz = !poz;
if( poz )
if(poz)
{
pausebox = create_box( g, g->w / 2, g->h / 2,
g->w - 16, 8 );
pausebox = create_box(g, g->w / 2, g->h / 2,
g->w - 16, 8);
}
else
{
free_box( pausebox );
free_box(pausebox);
}
break;
case '\t':
ceo_alert( g );
ceo_alert(g);
poz = 1;
break;
case 's':
skip = 1;
break;
default:
if( g->p->dead )
if(g->p->dead)
{
break;
}

switch( key )
switch(key)
{
case 'h':
g->p->vx = -2;
break;
case 'j':
if( g->p->y < g->h - 2 ) g->p->y += 1;
if(g->p->y < g->h - 2) g->p->y += 1;
break;
case 'k':
if( g->p->y > 1 ) g->p->y -= 1;
if(g->p->y > 1) g->p->y -= 1;
break;
case 'l':
g->p->vx = 2;
break;
case 'n':
if( g->p->special >= COST_NUKE )
if(g->p->special >= COST_NUKE)
{
g->p->special -= COST_NUKE;
add_weapon( g, g->wp, (g->p->x + 2) << 4, g->p->y << 4, 0, 0, WEAPON_NUKE );
add_weapon(g, g->wp, (g->p->x + 2) << 4, g->p->y << 4, 0, 0, WEAPON_NUKE);
}
break;
case 'f':
if( g->p->special >= COST_FRAGBOMB )
if(g->p->special >= COST_FRAGBOMB)
{
g->p->special -= COST_FRAGBOMB;
add_weapon( g, g->wp, (g->p->x + 2) << 4, g->p->y << 4, 0, -16, WEAPON_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->special >= COST_BEAM )
if(g->p->special >= COST_BEAM)
{
g->p->special -= COST_BEAM;
add_weapon( g, g->wp, (g->p->x + 2) << 4, g->p->y << 4, 0, 0, WEAPON_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 )
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 );
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 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 );
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 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 );
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 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 );
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 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 );
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 );
add_weapon(g, g->wp, (g->p->x + 2) << 4, g->p->y << 4, 0, -16, WEAPON_BOMB);
}
break;
}
}
}

if( !poz || skip )
if(!poz || skip)
{
skip = 0;

/* XXX: to be removed */
if( GET_RAND(0,10) == 0 )
if(GET_RAND(0,10) == 0)
{
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)]);
}

/* Update game rules */
if( g->t->right[1] - g->t->left[1] == g->t->w )
if(g->t->right[1] - g->t->left[1] == g->t->w)
{
g->t->w = 85 - g->t->w;
}

/* Scroll and update positions */
collide_player_tunnel( g, g->p, g->t, g->ex );
update_player( g, g->p );
collide_player_tunnel( g, g->p, g->t, g->ex );
update_starfield( g, g->sf );
update_bonus( g, g->bo );
update_aliens( g, g->al );
collide_weapons_tunnel( g, g->wp, g->t, g->ex );
collide_weapons_aliens( g, g->wp, g->al, g->ex );
update_weapons( g, g->wp );
collide_weapons_tunnel( g, g->wp, g->t, g->ex );
collide_weapons_aliens( g, g->wp, g->al, g->ex );
update_explosions( g, g->ex );
update_tunnel( g, g->t );
collide_player_tunnel(g, g->p, g->t, g->ex);
update_player(g, g->p);
collide_player_tunnel(g, g->p, g->t, g->ex);
update_starfield(g, g->sf);
update_bonus(g, g->bo);
update_aliens(g, g->al);
collide_weapons_tunnel(g, g->wp, g->t, g->ex);
collide_weapons_aliens(g, g->wp, g->al, g->ex);
update_weapons(g, g->wp);
collide_weapons_tunnel(g, g->wp, g->t, g->ex);
collide_weapons_aliens(g, g->wp, g->al, g->ex);
update_explosions(g, g->ex);
update_tunnel(g, g->t);
}

/* Clear screen */
ee_clear();

/* Print starfield, tunnel, aliens, player and explosions */
draw_starfield( g, g->sf );
draw_aliens( g, g->al );
draw_tunnel( g, g->t );
draw_bonus( g, g->bo );
draw_explosions( g, g->ex );
draw_weapons( g, g->wp );
draw_player( g, g->p );
draw_status( g );
draw_starfield(g, g->sf);
draw_aliens(g, g->al);
draw_tunnel(g, g->t);
draw_bonus(g, g->bo);
draw_explosions(g, g->ex);
draw_weapons(g, g->wp);
draw_player(g, g->p);
draw_status(g);

/* Print pause box if needed */
if( poz )
if(poz)
{
pausebox->frame++;
draw_box( g, pausebox );
draw_box(g, pausebox);
}

/* Refresh */
@@ -240,13 +240,13 @@ static void start_game (game *g)
purcompteur++;
}

if( pausebox )
if(pausebox)
{
free_box( pausebox );
free_box(pausebox);
}

free_starfield( g, g->sf );
free_tunnel( g->t );
free_player( g->p );
free_starfield(g, g->sf);
free_tunnel(g->t);
free_player(g->p);
}


+ 3
- 3
src/math.c Просмотреть файл

@@ -3,7 +3,7 @@
* Copyright (c) 2002 Sam Hocevar <sam@zoy.org>
* All Rights Reserved
*
* $Id: math.c,v 1.2 2002/12/22 23:01:35 sam Exp $
* $Id$
*
* 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
@@ -22,11 +22,11 @@

#include "common.h"

int r00t( int a )
int r00t(int a)
{
int x = a > 100000 ? 1000 : a > 1000 ? 100 : a > 10 ? 10 : 1;

if( a <= 0 )
if(a <= 0)
{
return 0;
}


+ 31
- 31
src/overlay.c Просмотреть файл

@@ -24,63 +24,63 @@

#include "common.h"

void draw_status( game *g )
void draw_status(game *g)
{
static char dots30[] = "------------------------------";
static char dashes30[] = "==============================";

/* Draw life jauge */
ee_color( EE_GRAY );
ee_goto( 4, 1 );
ee_putstr( dots30 );
ee_color(EE_GRAY);
ee_goto(4, 1);
ee_putstr(dots30);

if( g->p->life > MAX_LIFE * 7 / 10 )
if(g->p->life > MAX_LIFE * 7 / 10)
{
ee_color( EE_GREEN );
ee_color(EE_GREEN);
}
else if( g->p->life > MAX_LIFE * 3 / 10 )
else if(g->p->life > MAX_LIFE * 3 / 10)
{
ee_color( EE_YELLOW );
ee_color(EE_YELLOW);
}
else
{
ee_color( EE_RED );
ee_color(EE_RED);
}

ee_goto( 4, 1 );
ee_putstr( dashes30 + ( MAX_LIFE - g->p->life ) * 30 / MAX_LIFE );
ee_goto(4, 1);
ee_putstr(dashes30 + (MAX_LIFE - g->p->life) * 30 / MAX_LIFE);

ee_color( EE_WHITE );
ee_goto( 1, 1 );
ee_putstr( "L |" );
ee_goto( 34, 1 );
ee_putstr( "|" );
ee_color(EE_WHITE);
ee_goto(1, 1);
ee_putstr("L |");
ee_goto(34, 1);
ee_putstr("|");

/* Draw weapon jauge */
ee_color( EE_GRAY );
ee_goto( 42, 1 );
ee_putstr( dots30 + 10 );
ee_color(EE_GRAY);
ee_goto(42, 1);
ee_putstr(dots30 + 10);

if( g->p->special > MAX_SPECIAL * 9 / 10 )
if(g->p->special > MAX_SPECIAL * 9 / 10)
{
ee_color( EE_WHITE );
ee_color(EE_WHITE);
}
else if( g->p->special > MAX_SPECIAL * 3 / 10 )
else if(g->p->special > MAX_SPECIAL * 3 / 10)
{
ee_color( EE_CYAN );
ee_color(EE_CYAN);
}
else
{
ee_color( EE_BLUE );
ee_color(EE_BLUE);
}

ee_goto( 42, 1 );
ee_putstr( dashes30 + 10 + ( MAX_SPECIAL - g->p->special ) * 20 / MAX_SPECIAL );
ee_goto(42, 1);
ee_putstr(dashes30 + 10 + (MAX_SPECIAL - g->p->special) * 20 / MAX_SPECIAL);

ee_color( EE_WHITE );
ee_goto( 39, 1 );
ee_putstr( "S |" );
ee_goto( 62, 1 );
ee_putstr( "|" );
ee_color(EE_WHITE);
ee_goto(39, 1);
ee_putstr("S |");
ee_goto(62, 1);
ee_putstr("|");
}


+ 28
- 28
src/player.c Просмотреть файл

@@ -25,7 +25,7 @@
#include "common.h"

/* Init tunnel */
player * create_player( game *g )
player * create_player(game *g)
{
player *p = malloc(sizeof(player));

@@ -41,59 +41,59 @@ player * create_player( game *g )
return p;
}

void free_player( player *p )
void free_player(player *p)
{
free( p );
free(p);
}

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

ee_goto( p->x + 2, p->y - 2 );
ee_color( EE_GREEN );
ee_putstr( "/\\" );
ee_goto( p->x + 1, p->y - 1 );
ee_putchar( '(' );
ee_color( EE_YELLOW );
ee_putstr( "()" );
ee_color( EE_GREEN );
ee_putchar( ')' );
ee_goto( p->x, p->y );
ee_color( EE_GREEN );
ee_putstr( "I<__>I" );
ee_goto(p->x + 2, p->y - 2);
ee_color(EE_GREEN);
ee_putstr("/\\");
ee_goto(p->x + 1, p->y - 1);
ee_putchar('(');
ee_color(EE_YELLOW);
ee_putstr("()");
ee_color(EE_GREEN);
ee_putchar(')');
ee_goto(p->x, p->y);
ee_color(EE_GREEN);
ee_putstr("I<__>I");
}

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

if( p->life <= 0 )
if(p->life <= 0)
{
add_explosion( g, g->ex, p->x, p->y, 0, 0, EXPLOSION_SMALL );
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--;
}

if( p->special < MAX_SPECIAL )
if(p->special < MAX_SPECIAL)
{
p->special++;
}

/* Update life */
if( p->life < MAX_LIFE )
if(p->life < MAX_LIFE)
{
p->life++;
}
@@ -101,20 +101,20 @@ void update_player( game *g, player *p )
/* Update coords */
p->x += p->vx;

if( p->vx < 0 )
if(p->vx < 0)
{
p->vx++;
}
else if( p->vx > 0 )
else if(p->vx > 0)
{
p->vx--;
}

if( p->x < 1 )
if(p->x < 1)
{
p->x = 1;
}
else if( p->x > g->w - 7 )
else if(p->x > g->w - 7)
{
p->x = g->w - 7;
}


+ 24
- 24
src/starfield.c Просмотреть файл

@@ -24,55 +24,55 @@

#include "common.h"

starfield * create_starfield( game *g )
starfield * create_starfield(game *g)
{
int i;
starfield *s;

s = malloc( STARS * sizeof(starfield) );
s = malloc(STARS * sizeof(starfield));

for( i = 0; i < STARS; i++ )
for(i = 0; i < STARS; i++)
{
s[i].x = GET_RAND( 0, g->w );
s[i].y = GET_RAND( 0, g->h );
s[i].z = GET_RAND( 1, 4 );
s[i].c = GET_RAND( 6, 8 );
s[i].ch = GET_RAND( 0, 2 ) ? '.' : '\'';
s[i].x = GET_RAND(0, g->w);
s[i].y = GET_RAND(0, g->h);
s[i].z = GET_RAND(1, 4);
s[i].c = GET_RAND(6, 8);
s[i].ch = GET_RAND(0, 2) ? '.' : '\'';
}

return s;
}

void draw_starfield( game *g, starfield *s )
void draw_starfield(game *g, starfield *s)
{
int i;

for( i = 0; i < STARS; i++ )
for(i = 0; i < STARS; i++)
{
if( s[i].x >= 0 )
if(s[i].x >= 0)
{
ee_color( s[i].c );
ee_goto( s[i].x, s[i].y );
ee_putchar( s[i].ch );
ee_color(s[i].c);
ee_goto(s[i].x, s[i].y);
ee_putchar(s[i].ch);
}
}
}

void update_starfield( game *g, starfield *s )
void update_starfield(game *g, starfield *s)
{
int i;

for( i = 0; i < STARS; i++ )
for(i = 0; i < STARS; i++)
{
if( s[i].x < 0 )
if(s[i].x < 0)
{
s[i].x = GET_RAND( 0, g->w );
s[i].x = GET_RAND(0, g->w);
s[i].y = 0;
s[i].z = GET_RAND( 1, 3 );
s[i].c = GET_RAND( 6, 8 );
s[i].ch = GET_RAND( 0, 2 ) ? '.' : '\'';
s[i].z = GET_RAND(1, 3);
s[i].c = GET_RAND(6, 8);
s[i].ch = GET_RAND(0, 2) ? '.' : '\'';
}
else if( s[i].y < g->h-1 )
else if(s[i].y < g->h-1)
{
s[i].y += s[i].z;
}
@@ -83,8 +83,8 @@ void update_starfield( game *g, starfield *s )
}
}

void free_starfield( game *g, starfield *s )
void free_starfield(game *g, starfield *s)
{
free( s );
free(s);
}


+ 54
- 54
src/tunnel.c Просмотреть файл

@@ -27,7 +27,7 @@
#include "common.h"

/* Init tunnel */
tunnel * create_tunnel( game *g, int w, int h )
tunnel * create_tunnel(game *g, int w, int h)
{
int i;
tunnel *t = malloc(sizeof(tunnel));
@@ -37,9 +37,9 @@ tunnel * create_tunnel( game *g, int w, int h )
t->w = w;
t->h = h;

if( t->w >= g->w )
if(t->w >= g->w)
{
for( i = 0; i < g->h; i++ )
for(i = 0; i < g->h; i++)
{
t->left[i] = -10;
t->right[i] = g->w + 10;
@@ -50,119 +50,119 @@ tunnel * create_tunnel( game *g, int w, int h )
t->left[0] = (g->w - w) / 2;
t->right[0] = (g->w + w) / 2;
/* Yeah, sub-efficient, but less code to do :-) */
for( i = 0; i < g->h; i++ )
for(i = 0; i < g->h; i++)
{
update_tunnel( g, t );
update_tunnel(g, t);
}
}

return t;
}

void free_tunnel( tunnel *t )
void free_tunnel(tunnel *t)
{
free( t->left );
free( t->right );
free( t );
free(t->left);
free(t->right);
free(t);
}

void draw_tunnel( game *g, tunnel *t )
void draw_tunnel(game *g, tunnel *t)
{
int i, j;
char c;

ee_color( EE_GREEN );
ee_color(EE_GREEN);

/* Left border */
for( i = 0; i < g->h ; i++ )
for(i = 0; i < g->h ; i++)
{
if( t->left[i] <= -10 )
if(t->left[i] <= -10)
{
continue;
}

if( i + 1 == g->h || t->left[i] > t->left[i+1] )
if(i + 1 == g->h || t->left[i] > t->left[i+1])
{
c = ( i == 0 || t->left[i] > t->left[i-1] ) ? '>' : '/';
c = (i == 0 || t->left[i] > t->left[i-1]) ? '>' : '/';
}
else
{
c = ( i == 0 || t->left[i] > t->left[i-1] ) ? '\\' : '<';
c = (i == 0 || t->left[i] > t->left[i-1]) ? '\\' : '<';
}

ee_goto( t->left[i] + 1, i );
ee_putchar( c );
ee_goto(t->left[i] + 1, i);
ee_putchar(c);

if( i + 1 < g->h )
if(i + 1 < g->h)
{
for( j = 1; j < t->left[i+1] - t->left[i]; j++ )
for(j = 1; j < t->left[i+1] - t->left[i]; j++)
{
ee_goto( t->left[i] + j + 1, i );
ee_putchar( '_' );
ee_goto(t->left[i] + j + 1, i);
ee_putchar('_');
}
}
}

/* Right border */
for( i = 0; i < g->h ; i++ )
for(i = 0; i < g->h ; i++)
{
if( t->right[i] >= g->w + 10 )
if(t->right[i] >= g->w + 10)
{
continue;
}

if( i + 1 == g->h || t->right[i] > t->right[i+1] )
if(i + 1 == g->h || t->right[i] > t->right[i+1])
{
c = ( i == 0 || t->right[i] > t->right[i-1] ) ? '>' : '/';
c = (i == 0 || t->right[i] > t->right[i-1]) ? '>' : '/';
}
else
{
c = ( i == 0 || t->right[i] > t->right[i-1] ) ? '\\' : '<';
c = (i == 0 || t->right[i] > t->right[i-1]) ? '\\' : '<';
}

if( i + 1 < g->h )
if(i + 1 < g->h)
{
for( j = 1; j < t->right[i] - t->right[i+1]; j++ )
for(j = 1; j < t->right[i] - t->right[i+1]; j++)
{
ee_goto( t->right[i+1] + j - 1, i );
ee_putchar( '_' );
ee_goto(t->right[i+1] + j - 1, i);
ee_putchar('_');
}
}

ee_goto( t->right[i] - 1, i );
ee_putchar( c );
ee_goto(t->right[i] - 1, i);
ee_putchar(c);
}

ee_color( EE_RED );
ee_color(EE_RED);

/* Left concrete */
for( i = 0; i < g->h ; i++ )
for(i = 0; i < g->h ; i++)
{
for( j = 0 ; j <= t->left[i]; j++ )
for(j = 0 ; j <= t->left[i]; j++)
{
ee_goto( j, i );
ee_putchar( '#' );
ee_goto(j, i);
ee_putchar('#');
}
}

/* Right concrete */
for( i = 0; i < g->h ; i++ )
for(i = 0; i < g->h ; i++)
{
for( j = t->right[i] ; j < g->w ; j++ )
for(j = t->right[i] ; j < g->w ; j++)
{
ee_goto( j, i );
ee_putchar( '#' );
ee_goto(j, i);
ee_putchar('#');
}
}
}

void update_tunnel( game *g, tunnel *t )
void update_tunnel(game *g, tunnel *t)
{
static int const delta[] = { -3, -2, -1, 1, 2, 3 };
int i,j,k;

/* Slide tunnel one block vertically */
for( i = t->h - 1; i--; )
for(i = t->h - 1; i--;)
{
t->left[i+1] = t->left[i];
t->right[i+1] = t->right[i];
@@ -173,18 +173,18 @@ void update_tunnel( game *g, tunnel *t )
j = delta[GET_RAND(0,6)];

/* Check in which direction we need to alter tunnel */
if( t->right[1] - t->left[1] < t->w )
if(t->right[1] - t->left[1] < t->w)
{
/* Not wide enough, make sure i <= j */
if( i > j )
if(i > j)
{
k = j; j = i; i = k;
}
}
else if( t->right[1] - t->left[1] - 2 > t->w )
else if(t->right[1] - t->left[1] - 2 > t->w)
{
/* Too wide, make sure i >= j */
if( i < j )
if(i < j)
{
k = j; j = i; i = k;
}
@@ -195,7 +195,7 @@ void update_tunnel( game *g, tunnel *t )
}

/* If width doesn't exceed game size, update coords */
if( t->w <= g->w || t->right[1] - t->left[1] < t->w )
if(t->w <= g->w || t->right[1] - t->left[1] < t->w)
{
t->left[0] = t->left[1] + i;
t->right[0] = t->right[1] + j;
@@ -206,26 +206,26 @@ void update_tunnel( game *g, tunnel *t )
t->right[0] = g->w + 10;
}

if( t->w > g->w )
if(t->w > g->w)
{
if( t->left[0] < 0 && t->right[0] < g->w - 2 )
if(t->left[0] < 0 && t->right[0] < g->w - 2)
{
t->left[0] = t->left[1] + 1;
}

if( t->left[0] > 1 && t->right[0] > g->w - 1 )
if(t->left[0] > 1 && t->right[0] > g->w - 1)
{
t->right[0] = t->right[1] - 1;
}
}
else
{
if( t->left[0] < 0 )
if(t->left[0] < 0)
{
t->left[0] = t->left[1] + 1;
}

if( t->right[0] > g->w - 1 )
if(t->right[0] > g->w - 1)
{
t->right[0] = t->right[1] - 1;
}


+ 391
- 391
src/weapons.c
Разница между файлами не показана из-за своего большого размера
Просмотреть файл


Загрузка…
Отмена
Сохранить