Changeset 55


Ignore:
Timestamp:
Dec 23, 2002, 1:47:36 PM (20 years ago)
Author:
Sam Hocevar
Message:
  • cosmetic change: reworked draw_tunnel.
Location:
libcaca/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/TODO

    r49 r55  
    1919 * change tunnel colour
    2020
    21  * fill holes in the tunnel when |step| > 2
     21 DONE Dec 23 2002: fill holes in the tunnel when |step| > 2
    2222
    2323 DONE Dec 18 2002: draw a 3rd alien type
  • libcaca/trunk/src/main.c

    r53 r55  
    44 *                 All Rights Reserved
    55 *
    6  *   $Id: main.c,v 1.11 2002/12/23 12:03:31 sam Exp $
     6 *   $Id: main.c,v 1.12 2002/12/23 12:47:36 sam Exp $
    77 *
    88 *   This program is free software; you can redistribute it and/or modify
     
    5656static void start_game (game *g)
    5757{
    58     int i;
    5958    int quit = 0;
    6059    int poz = 0;
  • libcaca/trunk/src/tunnel.c

    r53 r55  
    44 *                 All Rights Reserved
    55 *
    6  *   $Id: tunnel.c,v 1.7 2002/12/23 12:03:31 sam Exp $
     6 *   $Id: tunnel.c,v 1.8 2002/12/23 12:47:36 sam Exp $
    77 *
    88 *   This program is free software; you can redistribute it and/or modify
     
    2121 */
    2222
     23#include "config.h"
     24
    2325#include <stdlib.h>
    2426
    2527#include "common.h"
    26 
    27 static void draw_wall( game *g, int *wall, int delta );
    2828
    2929/* Init tunnel */
     
    6969void draw_tunnel( game *g, tunnel *t )
    7070{
    71     /* Print tunnel */
    72     draw_wall( g, t->left, 1 );
    73     draw_wall( g, t->right, -1 );
     71    int i, j;
     72    char c;
     73
     74    gfx_color( GREEN );
     75
     76    /* Left border */
     77    for( i = 0; i < g->h ; i++ )
     78    {
     79        if( t->left[i] <= -10 )
     80        {
     81            continue;
     82        }
     83
     84        if( i + 1 == g->h || t->left[i] > t->left[i+1] )
     85        {
     86            c = ( i == 0 || t->left[i] > t->left[i-1] ) ? '>' : '/';
     87        }
     88        else
     89        {
     90            c = ( i == 0 || t->left[i] > t->left[i-1] ) ? '\\' : '<';
     91        }
     92
     93        gfx_goto( t->left[i] + 1, i );
     94        gfx_putchar( c );
     95
     96        if( i + 1 < g->h )
     97        {
     98            for( j = 1; j < t->left[i+1] - t->left[i]; j++ )
     99            {
     100                gfx_goto( t->left[i] + j + 1, i );
     101                gfx_putchar( '_' );
     102            }
     103        }
     104    }
     105
     106    /* Right border */
     107    for( i = 0; i < g->h ; i++ )
     108    {
     109        if( t->right[i] >= g->w + 10 )
     110        {
     111            continue;
     112        }
     113
     114        if( i + 1 == g->h || t->right[i] > t->right[i+1] )
     115        {
     116            c = ( i == 0 || t->right[i] > t->right[i-1] ) ? '>' : '/';
     117        }
     118        else
     119        {
     120            c = ( i == 0 || t->right[i] > t->right[i-1] ) ? '\\' : '<';
     121        }
     122
     123        if( i + 1 < g->h )
     124        {
     125            for( j = 1; j < t->right[i] - t->right[i+1]; j++ )
     126            {
     127                gfx_goto( t->right[i+1] + j - 1, i );
     128                gfx_putchar( '_' );
     129            }
     130        }
     131
     132        gfx_goto( t->right[i] - 1, i );
     133        gfx_putchar( c );
     134    }
     135
     136    gfx_color( RED );
     137
     138    /* Left concrete */
     139    for( i = 0; i < g->h ; i++ )
     140    {
     141        for( j = 0 ; j <= t->left[i]; j++ )
     142        {
     143            gfx_goto( j, i );
     144            gfx_putchar( '#' );
     145        }
     146    }
     147
     148    /* Right concrete */
     149    for( i = 0; i < g->h ; i++ )
     150    {
     151        for( j = t->right[i] ; j < g->w ; j++ )
     152        {
     153            gfx_goto( j, i );
     154            gfx_putchar( '#' );
     155        }
     156    }
    74157}
    75158
     
    93176    if( t->right[1] - t->left[1] < t->w )
    94177    {
    95         /* Not wide enough */
     178        /* Not wide enough, make sure i <= j */
    96179        if( i > j )
    97180        {
     
    101184    else if( t->right[1] - t->left[1] - 2 > t->w )
    102185    {
    103         /* Too wide */
     186        /* Too wide, make sure i >= j */
    104187        if( i < j )
    105188        {
     
    150233}
    151234
    152 static void draw_wall( game *g, int *wall, int delta )
    153 {
    154     int i, j;
    155 
    156     gfx_color( RED );
    157 
    158     if( delta == -1 )
    159     {
    160         for( i = 0; i < g->h ; i++ )
    161         {
    162             for( j = wall[i] ; j < g->w ; j++ )
    163             {
    164                 gfx_goto( j, i );
    165                 gfx_putchar( '#' );
    166             }
    167         }
    168     }
    169     else
    170     {
    171         for( i = 0; i < g->h ; i++ )
    172         {
    173             for( j = 0 ; j <= wall[i]; j++ )
    174             {
    175                 gfx_goto( j, i );
    176                 gfx_putchar( '#' );
    177             }
    178         }
    179     }
    180 
    181     gfx_color( GREEN );
    182 
    183     for( i = 0; i < g->h ; i++ )
    184     {
    185         char c;
    186 
    187         if( wall[i] <= -10 || wall[i] >= g->w + 10 )
    188         {
    189             continue;
    190         }
    191 
    192         if( i + 1 == g->h || wall[i] > wall[i+1] )
    193         {
    194             c = ( i == 0 || wall[i] > wall[i-1] ) ? '>' : '/';
    195         }
    196         else
    197         {
    198             c = ( i == 0 || wall[i] > wall[i-1] ) ? '\\' : '<';
    199         }
    200 
    201         if( delta == -1 && i + 1 < g->h )
    202         {
    203             for( j = 1; j < wall[i] - wall[i+1]; j++ )
    204             {
    205                 gfx_goto( wall[i+1] + j - 1, i );
    206                 gfx_putchar( '_' );
    207             }
    208         }
    209 
    210         gfx_goto( wall[i] + delta, i );
    211         gfx_putchar( c );
    212 
    213         if( delta == +1 && i + 1 < g->h )
    214         {
    215             for( j = 1; j < wall[i+1] - wall[i]; j++ )
    216             {
    217                 gfx_goto( wall[i] + j + 1, i );
    218                 gfx_putchar( '_' );
    219             }
    220         }
    221     }
    222 }
    223 
Note: See TracChangeset for help on using the changeset viewer.