Changeset 50


Ignore:
Timestamp:
Dec 23, 2002, 10:28:37 AM (20 years ago)
Author:
Sam Hocevar
Message:
  • the beam now digs the tunnel.
  • the starfield is now an array of stars.
  • fixed wall rendering (offset issues and disappearing left wall).
  • 32 seekers on fragbomb explosion, not 16.
Location:
ttyvaders/trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • ttyvaders/trunk/TODO

    r32 r50  
    99 * sprite library
    1010
    11  * mega ball
     11 DONE 23 Dec 2002: mega ball
    1212
    1313 * spiral weapon (vertical sine)
    1414
    15  * fragmentation bomb (merge with mega-ball?)
     15 DONE 23 Dec 2002: fragmentation bomb (merge with mega-ball?)
    1616
    1717 * stick aliens to tunnel
     
    3131 * promote precision for all coordinates except screen
    3232
    33  * tunnel sometimes doesn't get drawn on the left
     33 DONE Dec 19 2002: tunnel sometimes doesn't get drawn on the left
    3434
    3535 * write a generic drawing library with automatic clipping
     
    3939 * animate the ship
    4040
     41 * the nuke should break the tunnel
     42
  • ttyvaders/trunk/src/collide.c

    r42 r50  
    44 *                 All Rights Reserved
    55 *
    6  *   $Id: collide.c,v 1.7 2002/12/22 22:17:41 sam Exp $
     6 *   $Id: collide.c,v 1.8 2002/12/23 09:28:37 sam Exp $
    77 *
    88 *   This program is free software; you can redistribute it and/or modify
     
    2727void collide_weapons_tunnel( game *g, weapons *wp, tunnel *t, explosions *ex )
    2828{
    29     int i, x, y;
     29    int i, j, x, y;
    3030
    3131    for( i = 0; i < WEAPONS; i++ )
     
    7777            break;
    7878        case WEAPON_LASER:
    79             if( x <= t->left[y+1]
    80                  || x >= t->right[y+1] )
    81             {
    82                 add_explosion( g, ex, x, y+1, 0, 1, EXPLOSION_SMALL );
    83 
    84                 if( x <= t->left[y+1] )
    85                 {
    86                     t->left[y]--;
    87                     t->left[y+1]-=2;
    88                     t->left[y+2]--;
    89                 }
    90                 else
    91                 {
    92                     t->right[y]++;
    93                     t->right[y+1]+=2;
    94                     t->right[y+2]++;
    95                 }
    96 
    97                 wp->type[i] = WEAPON_NONE;
    98             }
    99             else if( x <= t->left[y]
    100                       || x >= t->right[y] )
    101             {
    102                 add_explosion( g, ex, x, y, 0, 1, EXPLOSION_SMALL );
    103 
    104                 if( x <= t->left[y] )
    105                 {
    106                     t->left[y-1]--;
    107                     t->left[y]-=2;
    108                     t->left[y+1]--;
    109                 }
    110                 else
    111                 {
    112                     t->right[y-1]++;
    113                     t->right[y]+=2;
    114                     t->right[y+1]++;
    115                 }
    116 
    117                 wp->type[i] = WEAPON_NONE;
    118             }
    119             break;
     79            for( j = GET_MIN( 0, wp->vy[i] >> 4 ) ;
     80                 j < GET_MAX( 0, wp->vy[i] >> 4 ) ;
     81                 j++ )
     82            {
     83                if( x <= t->left[y+j] || x >= t->right[y+j] )
     84                {
     85                    add_explosion( g, ex, x, y+j, 0, 1, EXPLOSION_SMALL );
     86                    wp->type[i] = WEAPON_NONE;
     87
     88                    if( x <= t->left[y+j] )
     89                    {
     90                        t->left[y+j-1]--;
     91                        t->left[y+j] -= 2;
     92                        t->left[y+j+1]--;
     93                    }
     94                    else
     95                    {
     96                        t->right[y+j-1]++;
     97                        t->right[y+j] += 2;
     98                        t->right[y+j+1]++;
     99                    }
     100                    break;
     101                }
     102            }
     103            break;
     104        case WEAPON_BEAM:
     105            if( wp->n[i] > 19 )
     106            {
     107                break;
     108            }
     109
     110            j = (29 - wp->n[i]) * (29 - wp->n[i]) / 8;
     111            j = GET_MIN( y, j );
     112
     113            for( ; j > 0 ; j-- )
     114            {
     115                if( x - 2 <= t->left[y-j] )
     116                {
     117                    add_explosion( g, ex, GET_MIN(t->left[y-j], x+3), y-j, 0, 1, EXPLOSION_SMALL );
     118                    t->left[y-j] -= GET_RAND(0,3);
     119                }
     120                else if( x + 3 >= t->right[y-j] )
     121                {
     122                    add_explosion( g, ex, GET_MAX(t->right[y-j], x-2), y-j, 0, 1, EXPLOSION_SMALL );
     123                    t->right[y-j] += GET_RAND(0,3);
     124                }
     125            }
     126            break;
     127
    120128        case WEAPON_NUKE:
    121         case WEAPON_BEAM:
    122             /* The nuke and the laser do not break the tunnel */
     129            /* The nuke does not break the tunnel */
    123130            break;
    124131        }
     
    128135void collide_weapons_aliens( game *g, weapons *wp, aliens *al, explosions *ex )
    129136{
    130     int i, j, x, y;
     137    int i, j, k, x, y;
    131138
    132139    for( i = 0; i < WEAPONS; i++ )
     
    166173
    167174        case WEAPON_BEAM:
     175            if( wp->n[i] > 19 )
     176            {
     177                break;
     178            }
     179
    168180            r = (29 - wp->n[i]) * (29 - wp->n[i]) / 8;
    169181
     
    191203                }
    192204
    193                 if( x >= al->x[j] && x <= al->x[j] + 4
    194                      && y >= al->y[j] && y <= al->y[j] + 2 )
    195                 {
    196                     al->life[j]--;
    197                     ok = 1;
    198                 }
    199                 else if( x >= al->x[j] && x <= al->x[j] + 4
    200                           && y+1 >= al->y[j] && y+1 <= al->y[j] + 2 )
    201                 {
    202                     al->life[j]--;
    203                     ok = 1;
     205                for( k = GET_MIN( 0, wp->vy[i] >> 4 ) ;
     206                     k < GET_MAX( 0, wp->vy[i] >> 4 ) ;
     207                     k++ )
     208                {
     209                    if( x >= al->x[j] && x <= al->x[j] + 4
     210                         && y+k >= al->y[j] && y+k <= al->y[j] + 2 )
     211                    {
     212                        al->life[j]--;
     213                        ok = 1;
     214                        break;
     215                    }
    204216                }
    205217            }
  • ttyvaders/trunk/src/common.h

    r44 r50  
    44 *                 All Rights Reserved
    55 *
    6  *   $Id: common.h,v 1.9 2002/12/22 22:36:42 sam Exp $
     6 *   $Id: common.h,v 1.10 2002/12/23 09:28:37 sam Exp $
    77 *
    88 *   This program is free software; you can redistribute it and/or modify
     
    2222
    2323#define STARS 50
    24 #define WEAPONS 100
     24#define WEAPONS 200
    2525#define BONUS 30
    2626#define ALIENS 30
    27 #define EXPLOSIONS 100
     27#define EXPLOSIONS 200
    2828
    2929#ifdef USE_SLANG
     
    4444
    4545#define GET_RAND(p,q) ((p)+(int)((1.0*((q)-(p)))*rand()/(RAND_MAX+1.0)))
     46#define GET_MAX(a,b) ((a)>(b)?(a):(b))
     47#define GET_MIN(a,b) ((a)<(b)?(a):(b))
    4648
    4749typedef struct
     
    5355typedef struct
    5456{
    55     int x[STARS];
    56     int y[STARS];
    57     int z[STARS];
    58     char ch[STARS];
    59     int c[STARS];
     57    int x, y, z, c;
     58    char ch;
    6059
    6160} starfield;
     
    170169void add_bonus( game *g, bonus *bo, int x, int y, int type );
    171170
    172 void init_starfield( game *g, starfield *s );
     171starfield * create_starfield( game *g );
    173172void draw_starfield( game *g, starfield *s );
    174173void update_starfield( game *g, starfield *s );
     174void free_starfield( game *g, starfield *s );
    175175
    176176tunnel * create_tunnel( game *g, int w, int h );
  • ttyvaders/trunk/src/main.c

    r42 r50  
    44 *                 All Rights Reserved
    55 *
    6  *   $Id: main.c,v 1.8 2002/12/22 22:17:41 sam Exp $
     6 *   $Id: main.c,v 1.9 2002/12/23 09:28:37 sam Exp $
    77 *
    88 *   This program is free software; you can redistribute it and/or modify
     
    6262    int purcompteur = 0;
    6363
    64     g->sf = malloc(sizeof(starfield));
     64    g->sf = create_starfield( g );
    6565    g->wp = malloc(sizeof(weapons));
    6666    g->ex = malloc(sizeof(explosions));
     
    7070    g->al = malloc(sizeof(aliens));
    7171
    72     init_starfield( g, g->sf );
    7372    init_weapons( g, g->wp );
    7473    init_explosions( g, g->ex );
     
    223222    }
    224223
     224    free_starfield( g, g->sf );
     225
    225226#if 0
    226227    free_player( p );
  • ttyvaders/trunk/src/starfield.c

    r38 r50  
    44 *                 All Rights Reserved
    55 *
    6  *   $Id: starfield.c,v 1.4 2002/12/22 18:44:12 sam Exp $
     6 *   $Id: starfield.c,v 1.5 2002/12/23 09:28:37 sam Exp $
    77 *
    88 *   This program is free software; you can redistribute it and/or modify
     
    2525#include "common.h"
    2626
    27 void init_starfield( game *g, starfield *s )
     27starfield * create_starfield( game *g )
    2828{
    2929    int i;
     30    starfield *s;
     31
     32    s = malloc( STARS * sizeof(starfield) );
    3033
    3134    for( i = 0; i < STARS; i++ )
    3235    {
    33         s->x[i] = rand() % g->w;
    34         s->y[i] = rand() % g->h;
    35         s->z[i] = 1 + rand() % 3;
    36         s->ch[i] = (rand() % 2) ? '.' : '\'';
    37         s->c[i] = 6 + rand() % 2;
     36        s[i].x = GET_RAND( 0, g->w );
     37        s[i].y = GET_RAND( 0, g->h );
     38        s[i].z = GET_RAND( 1, 4 );
     39        s[i].c = GET_RAND( 6, 8 );
     40        s[i].ch = GET_RAND( 0, 2 ) ? '.' : '\'';
    3841    }
     42
     43    return s;
    3944}
    4045
     
    4550    for( i = 0; i < STARS; i++ )
    4651    {
    47         if( s->x[i] >= 0 )
     52        if( s[i].x >= 0 )
    4853        {
    49             gfx_color( s->c[i] );
    50             gfx_goto( s->x[i], s->y[i] );
    51             gfx_putchar( s->ch[i] );
     54            gfx_color( s[i].c );
     55            gfx_goto( s[i].x, s[i].y );
     56            gfx_putchar( s[i].ch );
    5257        }
    5358    }
     
    6065    for( i = 0; i < STARS; i++ )
    6166    {
    62         if( s->x[i] < 0 )
     67        if( s[i].x < 0 )
    6368        {
    64             s->x[i] = rand() % g->w;
    65             s->y[i] = 0;
    66             s->z[i] = 1 + rand() % 2;
    67             s->ch[i] = (rand() % 2) ? '.' : '\'';
    68             s->c[i] = 6 + rand() % 2;
     69            s[i].x = GET_RAND( 0, g->w );
     70            s[i].y = 0;
     71            s[i].z = GET_RAND( 1, 3 );
     72            s[i].c = GET_RAND( 6, 8 );
     73            s[i].ch = GET_RAND( 0, 2 ) ? '.' : '\'';
    6974        }
    70         else if( s->y[i] < g->h-1 )
     75        else if( s[i].y < g->h-1 )
    7176        {
    72             s->y[i] += s->z[i];
     77            s[i].y += s[i].z;
    7378        }
    7479        else
    7580        {
    76             s->x[i] = -1;
     81            s[i].x = -1;
    7782        }
    7883    }
    7984}
    8085
     86void free_starfield( game *g, starfield *s )
     87{
     88    free( s );
     89}
     90
  • ttyvaders/trunk/src/tunnel.c

    r38 r50  
    44 *                 All Rights Reserved
    55 *
    6  *   $Id: tunnel.c,v 1.4 2002/12/22 18:44:12 sam Exp $
     6 *   $Id: tunnel.c,v 1.5 2002/12/23 09:28:37 sam Exp $
    77 *
    88 *   This program is free software; you can redistribute it and/or modify
     
    2525#include "common.h"
    2626
    27 static void draw_wall( game *g, int *wall );
     27static void draw_wall( game *g, int *wall, int delta );
    2828
    2929/* Init tunnel */
     
    4040    if( t->w >= g->w )
    4141    {
    42         t->left[0] = -1;
    43         t->right[0] = g->w;
     42        t->left[0] = -10;
     43        t->right[0] = g->w + 10;
    4444        for( i = 0; i < g->h; i++ )
    4545        {
    46             t->left[i] = -1;
    47             t->right[i] = g->w;
     46            t->left[i] = -10;
     47            t->right[i] = g->w + 10;
    4848        }
    4949    }
     
    7272{
    7373    /* Print tunnel */
    74     draw_wall( g, t->left );
    75     draw_wall( g, t->right );
     74    draw_wall( g, t->left, -2 );
     75    draw_wall( g, t->right, -1 );
    7676}
    7777
    7878void update_tunnel( game *g, tunnel *t )
    7979{
    80     static int const delta[] = { -2, -1, 1, 2 };
     80    static int const delta[] = { -3, -2, -1, 1, 2, 3 };
    8181    int i,j,k;
    8282
     
    8989
    9090    /* Generate new values */
    91     i = delta[GET_RAND(0,4)];
    92     j = delta[GET_RAND(0,4)];
     91    i = delta[GET_RAND(0,6)];
     92    j = delta[GET_RAND(0,6)];
    9393
    9494    /* Check in which direction we need to alter tunnel */
     
    122122    else
    123123    {
    124         t->left[0] = -1;
    125         t->right[0] = g->w;
     124        t->left[0] = -10;
     125        t->right[0] = g->w + 10;
    126126    }
    127127
     
    152152}
    153153
    154 static void draw_wall( game *g, int *wall )
     154static void draw_wall( game *g, int *wall, int delta )
    155155{
    156156    int i;
     
    162162        char *str;
    163163
    164         if( wall[i] < 0 || wall[i] >= g->w )
     164        if( wall[i] < -10 || wall[i] >= g->w + 10 )
    165165        {
    166166            continue;
     
    178178        if( wall[i] == wall[i+1] + 2 )
    179179        {
    180             gfx_goto( wall[i] - 1, i );
     180            gfx_goto( wall[i] - 1 + delta, i );
    181181            gfx_putchar( '_' );
    182182        }
    183183
    184         gfx_goto( wall[i], i );
     184        gfx_goto( wall[i] + delta, i );
    185185        gfx_putstr( str );
    186186        if( wall[i] == wall[i+1] - 2 ) gfx_putchar( '_' );
  • ttyvaders/trunk/src/weapons.c

    r48 r50  
    44 *                 All Rights Reserved
    55 *
    6  *   $Id: weapons.c,v 1.11 2002/12/22 23:39:15 sam Exp $
     6 *   $Id: weapons.c,v 1.12 2002/12/23 09:28:37 sam Exp $
    77 *
    88 *   This program is free software; you can redistribute it and/or modify
     
    199199                    {
    200200                        32,  0,   -32,  0,    0,  16,     0, -16,
     201                        28,  8,   -28,  8,   28,  -8,   -28,  -8,
    201202                        24, 12,   -24, 12,   24, -12,   -24, -12,
    202                         28,  8,   -28,  8,   28,  -8,   -28,  -8,
    203203                        16, 14,   -16, 14,   16, -14,   -16, -14
    204204                    };
     
    206206                    for( j = 0 ; j < sizeof(coords) / sizeof(int) ; j += 2 )
    207207                    {
    208                         add_weapon( g, g->wp, wp->x[i] + coords[j], wp->y[i] + coords[j+1], coords[j], coords[j+1], WEAPON_SEEKER );
     208                        add_weapon( g, g->wp, wp->x[i] + coords[j], wp->y[i] + coords[j+1] / 2, coords[j], coords[j+1], WEAPON_SEEKER );
     209                        add_weapon( g, g->wp, wp->x[i] + coords[j] / 2, wp->y[i] + coords[j+1], coords[j], coords[j+1], WEAPON_SEEKER );
    209210                    }
    210211
Note: See TracChangeset for help on using the changeset viewer.