Browse Source

* cosmetic change: reworked draw_tunnel.

tags/v0.99.beta14
Sam Hocevar sam 22 years ago
parent
commit
9ed39975c0
3 changed files with 93 additions and 83 deletions
  1. +1
    -1
      TODO
  2. +1
    -2
      src/main.c
  3. +91
    -80
      src/tunnel.c

+ 1
- 1
TODO View File

@@ -18,7 +18,7 @@ Things to do


* change tunnel colour * change tunnel colour


* fill holes in the tunnel when |step| > 2
DONE Dec 23 2002: fill holes in the tunnel when |step| > 2


DONE Dec 18 2002: draw a 3rd alien type DONE Dec 18 2002: draw a 3rd alien type




+ 1
- 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.11 2002/12/23 12:03:31 sam Exp $
* $Id: main.c,v 1.12 2002/12/23 12:47:36 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,7 +55,6 @@ int main (int argc, char **argv)


static void start_game (game *g) static void start_game (game *g)
{ {
int i;
int quit = 0; int quit = 0;
int poz = 0; int poz = 0;
int skip = 0; int skip = 0;


+ 91
- 80
src/tunnel.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: tunnel.c,v 1.7 2002/12/23 12:03:31 sam Exp $
* $Id: tunnel.c,v 1.8 2002/12/23 12:47:36 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,12 +20,12 @@
* 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 "common.h" #include "common.h"


static void draw_wall( game *g, int *wall, int delta );

/* Init tunnel */ /* Init tunnel */
tunnel * create_tunnel( game *g, int w, int h ) tunnel * create_tunnel( game *g, int w, int h )
{ {
@@ -68,9 +68,92 @@ void free_tunnel( tunnel *t )


void draw_tunnel( game *g, tunnel *t ) void draw_tunnel( game *g, tunnel *t )
{ {
/* Print tunnel */
draw_wall( g, t->left, 1 );
draw_wall( g, t->right, -1 );
int i, j;
char c;

gfx_color( GREEN );

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

if( i + 1 == g->h || 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] ) ? '\\' : '<';
}

gfx_goto( t->left[i] + 1, i );
gfx_putchar( c );

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

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

if( i + 1 == g->h || 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] ) ? '\\' : '<';
}

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

gfx_goto( t->right[i] - 1, i );
gfx_putchar( c );
}

gfx_color( RED );

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

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


void update_tunnel( game *g, tunnel *t ) void update_tunnel( game *g, tunnel *t )
@@ -92,7 +175,7 @@ void update_tunnel( game *g, tunnel *t )
/* Check in which direction we need to alter tunnel */ /* 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 */
/* Not wide enough, make sure i <= j */
if( i > j ) if( i > j )
{ {
k = j; j = i; i = k; k = j; j = i; i = k;
@@ -100,7 +183,7 @@ void update_tunnel( game *g, tunnel *t )
} }
else if( t->right[1] - t->left[1] - 2 > t->w ) else if( t->right[1] - t->left[1] - 2 > t->w )
{ {
/* Too wide */
/* Too wide, make sure i >= j */
if( i < j ) if( i < j )
{ {
k = j; j = i; i = k; k = j; j = i; i = k;
@@ -149,75 +232,3 @@ void update_tunnel( game *g, tunnel *t )
} }
} }


static void draw_wall( game *g, int *wall, int delta )
{
int i, j;

gfx_color( RED );

if( delta == -1 )
{
for( i = 0; i < g->h ; i++ )
{
for( j = wall[i] ; j < g->w ; j++ )
{
gfx_goto( j, i );
gfx_putchar( '#' );
}
}
}
else
{
for( i = 0; i < g->h ; i++ )
{
for( j = 0 ; j <= wall[i]; j++ )
{
gfx_goto( j, i );
gfx_putchar( '#' );
}
}
}

gfx_color( GREEN );

for( i = 0; i < g->h ; i++ )
{
char c;

if( wall[i] <= -10 || wall[i] >= g->w + 10 )
{
continue;
}

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

if( delta == -1 && i + 1 < g->h )
{
for( j = 1; j < wall[i] - wall[i+1]; j++ )
{
gfx_goto( wall[i+1] + j - 1, i );
gfx_putchar( '_' );
}
}

gfx_goto( wall[i] + delta, i );
gfx_putchar( c );

if( delta == +1 && i + 1 < g->h )
{
for( j = 1; j < wall[i+1] - wall[i]; j++ )
{
gfx_goto( wall[i] + j + 1, i );
gfx_putchar( '_' );
}
}
}
}


Loading…
Cancel
Save