Changeset 19


Ignore:
Timestamp:
Dec 15, 2002, 4:41:32 AM (20 years ago)
Author:
Sam Hocevar
Message:
  • real Debian package files.
  • two new types of aliens. only one rules.
  • removed gfx_write in favor of gfx_putchar and gfx_putstr.
  • added bonuses at alien death. they do nothing yet.
  • seeker missiles. 'b' to test.
  • weapon resolution is now 16*char. needs to be generalized.
  • fixed the supernova bugs. center could collide with the tunnel, and the last frame was badly displayed.
  • lots of cleanups everywhere.
Location:
libcaca/trunk
Files:
1 added
17 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/Makefile

    r17 r19  
    7777PACKAGE_BUGREPORT =
    7878PACKAGE_NAME = ttyvaders
    79 PACKAGE_STRING = ttyvaders 0.0-cvs
     79PACKAGE_STRING = ttyvaders 0.0cvs
    8080PACKAGE_TARNAME = ttyvaders
    81 PACKAGE_VERSION = 0.0-cvs
     81PACKAGE_VERSION = 0.0cvs
    8282PATH_SEPARATOR = :
    8383SET_MAKE =
     
    8686USE_NCURSES_FALSE =
    8787USE_NCURSES_TRUE = #
    88 VERSION = 0.0-cvs
     88VERSION = 0.0cvs
    8989ac_ct_CC = gcc
    9090ac_ct_STRIP =
  • libcaca/trunk/configure.ac

    r17 r19  
    11dnl Autoconf settings for ttyvaders
    22
    3 AC_INIT(ttyvaders,0.0-cvs)
     3AC_INIT(ttyvaders,0.0cvs)
    44
    55AC_PREREQ(2.50)
     
    77AC_CANONICAL_SYSTEM
    88
    9 AM_INIT_AUTOMAKE(ttyvaders,0.0-cvs)
     9AM_INIT_AUTOMAKE(ttyvaders,0.0cvs)
    1010AM_CONFIG_HEADER(config.h)
    1111
  • libcaca/trunk/debian/changelog

    r17 r19  
     1ttyvaders (0.0cvs-1) unstable; urgency=low
     2
     3  * Not yet released.
     4
     5 -- Samuel Hocevar <sam@zoy.org>  Sat, 14 Dec 2002 15:22:25 +0100
  • libcaca/trunk/debian/control

    r17 r19  
     1Source: ttyvaders
     2Section: games
     3Priority: optional
     4Maintainer: Samuel Hocevar <sam@zoy.org>
     5Build-Depends: debhelper (>=2.2.0), slang1-dev
     6Standards-Version: 3.5.6
     7
     8Package: ttyvaders
     9Section: games
     10Architecture: any
     11Depends: ${shlibs:Depends}
     12Description: A vertical shoot 'em up with text-mode graphics.
     13 TTYvaders is a vertical shoot 'em up for the console or the terminal.
     14 .
     15 It rules.
  • libcaca/trunk/debian/rules

    r17 r19  
     1#!/usr/bin/make -f
     2
     3#export DH_VERBOSE=1
     4export DH_COMPAT=3
     5export DEB_HOST_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
     6export DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
     7
     8# FOR AUTOCONF 2.52 AND NEWER ONLY
     9ifeq ($(DEB_BUILD_GNU_TYPE), $(DEB_HOST_GNU_TYPE))
     10  confflags += --build $(DEB_HOST_GNU_TYPE)
     11else
     12  confflags += --build $(DEB_BUILD_GNU_TYPE) --host $(DEB_HOST_GNU_TYPE)
     13endif
     14
     15confflags += --mandir=\$${prefix}/share/man --infodir=\$${prefix}/share/info
     16
     17configure: configure-stamp
     18configure-stamp:
     19        dh_testdir
     20        ./configure $(confflags) --prefix=/usr
     21        touch configure-stamp
     22
     23build: configure-stamp build-stamp
     24build-stamp:
     25        dh_testdir
     26        $(MAKE)
     27        touch build-stamp
     28
     29clean:
     30        dh_testdir
     31        dh_testroot
     32        rm -f build-stamp configure-stamp
     33        -$(MAKE) distclean
     34        dh_clean
     35
     36install: build
     37        dh_testdir
     38        dh_testroot
     39        dh_clean -k
     40        dh_installdirs
     41        DESTDIR=`pwd`/debian/ttyvaders/ $(MAKE) install prefix=/usr
     42
     43# Build architecture-independent files here.
     44binary-indep: build install
     45# We have nothing to do by default.
     46
     47# Build architecture-dependent files here.
     48binary-arch: build install
     49#       dh_testversion
     50        dh_testdir
     51        dh_testroot
     52#       dh_installdebconf       
     53        dh_installdocs
     54#       dh_installexamples
     55        dh_installmenu
     56#       dh_installemacsen
     57#       dh_installpam
     58#       dh_installinit
     59        dh_installcron
     60        dh_installmanpages
     61        dh_installinfo
     62#       dh_undocumented
     63        dh_installchangelogs
     64        dh_link
     65        dh_strip
     66        dh_compress
     67        dh_fixperms
     68#       dh_makeshlibs
     69        dh_installdeb
     70#       dh_perl
     71        dh_shlibdeps
     72        dh_gencontrol
     73        dh_md5sums
     74        dh_builddeb
     75
     76binary: binary-indep binary-arch
     77.PHONY: build clean binary-indep binary-arch binary install configure
  • libcaca/trunk/doc/shapes.txt

    r17 r19  
    33--------
    44
    5    /\
    6   (())
    7  I<__>I
     5   /\      /~\
     6  (())     ]O[
     7 I<__>I   I\#/I
    88
    99
     
    1414 \O o/  \o O/
    1515 ^^^^^  ^^^^^
     16 .     ,  .       ,
     17  \oXo/    `-oXo-'  `--oXo--'  ,-oXo-.    ,oXo.
     18   `V'       `V'       `V'    '  `V'  `  / `V' \
     19
     20  ,---.   ,---.   ,---.   ,---.   ,---.
     21 (_°_°_) (__°_°) (°__°_) (_°__°) (°_°__)
     22   ^ ^      ^ ^   ^  ^     ^  ^   ^ ^
     23  ,---.   ,---.   ,---.   ,---.   ,---.
     24 (((o))) ((((o)) (((o))) ((o)))) (((o)))
     25  `---'   `---'   `---'   `---'   `---'
     26 _o|o_
     27  T|T
     28
     29Bonus
     30-----
     31  _    _    _
     32 /|\  / \  /.\
     33 \|/  \_/  \_/
     34
     35 ,--.  ,--.  ,--.
     36 \VV/  \~~/  \  /
     37  \/    \/    \/
     38  _  _   _ _
     39 ( `' ) ( ' )
     40  \  /   `v'
     41   \/
     42   ___
     43  / g \
     44  \___/
    1645
    1746Shots
    1847-----
    1948
    20  |     /   _,  ___   \
    21  |    /   '           \
     49.o@  . o @   .  o  @
     50
     51.o()  . o ()   .  o  ()
     52
     53 |     /   _,  ___  ._   \
     54 |    /   '           `   \
    2255
    2356
  • libcaca/trunk/src/Makefile.am

    r17 r19  
    33###############################################################################
    44
    5 AM_CPPFLAGS = -g -O6 -fno-strength-reduce -fomit-frame-pointer
     5AM_CFLAGS = -g -O6 -fno-strength-reduce -fomit-frame-pointer
    66
    77# Code qui fait des warnings == code de porc == deux baffes dans ta gueule
    8 AM_CPPFLAGS += -Wall -Wpointer-arith -Wcast-align -Wcast-qual -Wstrict-prototypes -Wshadow -Waggregate-return -Wmissing-prototypes -Wnested-externs
     8AM_CFLAGS += -Wall -Wpointer-arith -Wcast-align -Wcast-qual -Wstrict-prototypes -Wshadow -Waggregate-return -Wmissing-prototypes -Wnested-externs
    99
    1010if USE_NCURSES
     
    2020ttyvaders_SOURCES = \
    2121        aliens.c \
     22        bonus.c \
    2223        common.h \
    2324        explosions.c \
  • libcaca/trunk/src/aliens.c

    r17 r19  
    44#include "common.h"
    55
    6 static void draw_alien( game *g, int x, int y, int type );
     6static void draw_alien_poolp( game *g, int x, int y, int frame );
     7static void draw_alien_bool( game *g, int x, int y, int frame );
     8static void draw_alien_brah( game *g, int x, int y, int frame );
    79
    810void init_aliens( game *g, aliens *al )
     
    1214    for( i = 0; i < ALIENS; i++ )
    1315    {
    14         al->x[i] = -1;
    15         al->y[i] = -1;
    16         al->img[i] = 0;
    17         al->life[i] = 0;
     16        al->type[i] = ALIEN_NONE;
    1817    }
    1918}
     
    2524    for( i = 0; i < ALIENS; i++ )
    2625    {
    27         if( al->y[i] >= 0 )
     26        switch( al->type[i] )
    2827        {
    29             draw_alien( g, al->x[i], al->y[i], al->img[i] % 2 );
     28            case ALIEN_BRAH:
     29                draw_alien_brah( g, al->x[i], al->y[i], al->img[i] % 8 );
     30                break;
     31            case ALIEN_POOLP:
     32                draw_alien_poolp( g, al->x[i], al->y[i], al->img[i] % 2 );
     33                break;
     34            case ALIEN_BOOL:
     35                draw_alien_bool( g, al->x[i], al->y[i], al->img[i] % 5 );
     36                break;
     37            case ALIEN_NONE:
     38                break;
    3039        }
    3140    }
     
    3847    for( i = 0; i < ALIENS; i++ )
    3948    {
    40         if( al->y[i] < 0 )
     49        switch( al->type[i] )
    4150        {
    42             //al->x[i] = g->w;
     51            case ALIEN_POOLP:
     52            case ALIEN_BOOL:
     53            case ALIEN_BRAH:
     54                al->x[i] = ((al->x[i] + 5) % (g->w + 3)) - 3;
     55                al->y[i] = al->y[i] + (rand() % 8) / 7 - (rand() % 8) / 7;
     56                al->img[i] = al->img[i] + 1;
     57
     58                /* Check bounds */
     59                if( al->y[i] < 0 ) al->y[i] = 0;
     60                if( al->y[i] > g->w - 1 ) al->y[i] = g->w - 1;
     61                break;
     62            case ALIEN_NONE:
     63                break;
    4364        }
    44         else
     65    }
     66}
     67
     68void add_alien( game *g, aliens *al, int x, int y, int type )
     69{
     70    int i;
     71
     72    for( i = 0; i < ALIENS; i++ )
     73    {
     74        if( al->type[i] == ALIEN_NONE )
    4575        {
    46             al->x[i] = ((al->x[i] + 5) % (g->w + 3)) - 3;
    47             al->y[i] = al->y[i] + (rand() % 8) / 7 - (rand() % 8) / 7;
    48             al->img[i] = al->img[i] + rand() % 4;
    49 
    50             /* Check collisions */
    51             if( al->y[i] < 0 ) al->y[i] = 0;
    52             if( al->y[i] > g->w - 1 ) al->y[i] = g->w - 1;
    53         }
    54     }
    55 }
    56 
    57 void add_alien( game *g, aliens *al, int x, int y )
    58 {
    59     int i;
    60 
    61     for( i = 0; i < ALIENS; i++ )
    62     {
    63         if( al->y[i] < 0 )
    64         {
     76            al->type[i] = type;
    6577            al->x[i] = x;
    6678            al->y[i] = y;
    6779            al->img[i] = 0;
    68             al->life[i] = 2;
     80
     81            switch( al->type[i] )
     82            {
     83                case ALIEN_POOLP:
     84                    al->life[i] = 2;
     85                    break;
     86                case ALIEN_BOOL:
     87                    al->life[i] = 2;
     88                    break;
     89                case ALIEN_BRAH:
     90                    al->life[i] = 2;
     91                    break;
     92                case ALIEN_NONE:
     93                    break;
     94            }
     95
    6996            break;
    7097        }
     
    7299}
    73100
    74 static void draw_alien( game *g, int x, int y, int type )
    75 {
    76     switch( type )
     101static void draw_alien_poolp( game *g, int x, int y, int frame )
     102{
     103    switch( frame )
    77104    {
    78105    case 0:
    79         GFX_COLOR( MAGENTA );
    80         GFX_GOTO( x, y );
    81         GFX_WRITE( ',' );
    82         GFX_WRITE( '-' );
    83         GFX_WRITE( '-' );
    84         GFX_WRITE( '-' );
    85         GFX_WRITE( '.' );
    86         GFX_GOTO( x, y+1 );
    87         GFX_WRITE( '\\' );
    88         GFX_COLOR( WHITE );
    89         GFX_WRITE( 'o' );
    90         GFX_WRITE( ' ' );
    91         GFX_WRITE( 'O' );
    92         GFX_COLOR( MAGENTA );
    93         GFX_WRITE( '/' );
    94         GFX_GOTO( x, y+2 );
    95         GFX_WRITE( '^' );
    96         GFX_WRITE( '^' );
    97         GFX_WRITE( '^' );
    98         GFX_WRITE( '^' );
    99         GFX_WRITE( '^' );
     106        gfx_color( MAGENTA );
     107        gfx_goto( x, y );
     108        gfx_putstr( ",---." );
     109        gfx_goto( x, y+1 );
     110        gfx_putchar( '\\' );
     111        gfx_color( WHITE );
     112        gfx_putstr( "o O" );
     113        gfx_color( MAGENTA );
     114        gfx_putchar( '/' );
     115        gfx_goto( x, y+2 );
     116        gfx_putstr( "^^^^^" );
    100117        break;
    101118    case 1:
    102         GFX_COLOR( MAGENTA );
    103         GFX_GOTO( x, y );
    104         GFX_WRITE( ',' );
    105         GFX_WRITE( '-' );
    106         GFX_WRITE( '-' );
    107         GFX_WRITE( '-' );
    108         GFX_WRITE( '.' );
    109         GFX_GOTO( x, y+1 );
    110         GFX_WRITE( '\\' );
    111         GFX_COLOR( WHITE );
    112         GFX_WRITE( 'O' );
    113         GFX_WRITE( ' ' );
    114         GFX_WRITE( 'o' );
    115         GFX_COLOR( MAGENTA );
    116         GFX_WRITE( '/' );
    117         GFX_GOTO( x, y+2 );
    118         GFX_WRITE( '^' );
    119         GFX_WRITE( '^' );
    120         GFX_WRITE( '^' );
    121         GFX_WRITE( '^' );
    122         GFX_WRITE( '^' );
    123         break;
    124     }
    125 }
    126 
    127 #if 0
    128 void draw_rock( int x, int y, int type )
    129 {
    130     switch( type )
    131     {
     119        gfx_color( MAGENTA );
     120        gfx_goto( x, y );
     121        gfx_putstr( ",---." );
     122        gfx_goto( x, y+1 );
     123        gfx_putchar( '\\' );
     124        gfx_color( WHITE );
     125        gfx_putstr( "O o" );
     126        gfx_color( MAGENTA );
     127        gfx_putchar( '/' );
     128        gfx_goto( x, y+2 );
     129        gfx_putstr( "^^^^^" );
     130        break;
     131    }
     132}
     133
     134static void draw_alien_bool( game *g, int x, int y, int frame )
     135{
     136    gfx_color( GREEN );
     137    gfx_goto( x+1, y );
     138    gfx_putstr( ",---." );
     139
     140    gfx_goto( x, y+1 );
     141    gfx_putchar( '(' );
     142
     143    gfx_color( WHITE );
     144    switch( frame )
     145    {
     146    case 4:
     147        gfx_putstr( "##( )" );
     148        break;
     149    case 3:
     150        gfx_putstr( ")##( " );
     151        break;
     152    case 2:
     153        gfx_putstr( " )##(" );
     154        break;
     155    case 1:
     156        gfx_putstr( "( )##" );
     157        break;
    132158    case 0:
    133         GFX_COLOR( RED );
    134         GFX_GOTO( x, y );
    135         GFX_WRITE( '/' );
    136         GFX_WRITE( '\\' );
    137         GFX_WRITE( '_' );
    138         GFX_WRITE( '/' );
    139         GFX_WRITE( '\\' );
    140         GFX_GOTO( x, y+1 );
    141         GFX_WRITE( '>' );
    142         GFX_WRITE( ' ' );
    143         GFX_WRITE( ' ' );
    144         GFX_WRITE( ' ' );
    145         GFX_WRITE( '/' );
    146         GFX_GOTO( x, y+2 );
    147         GFX_WRITE( '\\' );
    148         GFX_WRITE( '/' );
    149         GFX_WRITE( '\\' );
    150         GFX_WRITE( '_' );
    151         GFX_WRITE( '>' );
    152         break;
     159        gfx_putstr( "#( )#" );
     160        break;
     161    }
     162
     163    gfx_color( GREEN );
     164    gfx_goto( x+6, y+1 );
     165    gfx_putchar( ')' );
     166
     167    gfx_goto( x+1, y+2 );
     168    gfx_putstr( "`---'" );
     169}
     170
     171static void draw_alien_brah( game *g, int x, int y, int frame )
     172{
     173    gfx_color( YELLOW );
     174
     175    switch( frame )
     176    {
     177    case 0:
     178        gfx_goto( x, y );
     179        gfx_putchar( '.' );
     180        gfx_goto( x+6, y );
     181        gfx_putchar( ',' );
     182        gfx_goto( x+1, y+1 );
     183        gfx_putstr( "\\ X /" );
     184        break;
     185    case 7:
    153186    case 1:
    154         GFX_COLOR( RED );
    155         GFX_GOTO( x, y );
    156         GFX_WRITE( '_' );
    157         GFX_WRITE( '/' );
    158         GFX_WRITE( '\\' );
    159         GFX_WRITE( '/' );
    160         GFX_WRITE( '>' );
    161         GFX_GOTO( x, y+1 );
    162         GFX_WRITE( '\\' );
    163         GFX_WRITE( ' ' );
    164         GFX_WRITE( ' ' );
    165         GFX_WRITE( ' ' );
    166         GFX_WRITE( '\\' );
    167         GFX_GOTO( x, y+2 );
    168         GFX_WRITE( '<' );
    169         GFX_WRITE( '_' );
    170         GFX_WRITE( '/' );
    171         GFX_WRITE( '\\' );
    172         GFX_WRITE( '/' );
    173         break;
    174     }
    175 }
    176 #endif
     187        gfx_goto( x-1, y );
     188        gfx_putchar( '.' );
     189        gfx_goto( x+7, y );
     190        gfx_putchar( ',' );
     191        gfx_goto( x, y+1 );
     192        gfx_putstr( "`- X -'" );
     193        break;
     194    case 6:
     195    case 2:
     196        gfx_goto( x-1, y+1 );
     197        gfx_putstr( "`-- X --'" );
     198        break;
     199    case 5:
     200    case 3:
     201        gfx_goto( x, y+1 );
     202        gfx_putstr( ",- X -." );
     203        gfx_goto( x-1, y+2 );
     204        gfx_putchar( '\'' );
     205        gfx_goto( x+7, y+2 );
     206        gfx_putchar( '`' );
     207        break;
     208    case 4:
     209        gfx_goto( x+1, y+1 );
     210        gfx_putstr( ", X ." );
     211        gfx_goto( x, y+2 );
     212        gfx_putchar( '/' );
     213        gfx_goto( x+6, y+2 );
     214        gfx_putchar( '\\' );
     215        break;
     216    }
     217
     218    gfx_goto( x+2, y+2 );
     219    gfx_putstr( "`V'" );
     220
     221    gfx_color( WHITE );
     222    gfx_goto( x+2, y+1 );
     223    gfx_putchar( 'o' );
     224    gfx_goto( x+4, y+1 );
     225    gfx_putchar( 'o' );
     226}
     227
     228
  • libcaca/trunk/src/collide.c

    r17 r19  
    66void collide_weapons_tunnel( game *g, weapons *wp, tunnel *t, explosions *ex )
    77{
    8     int i;
     8    int i, x, y;
    99
    1010    for( i = 0; i < WEAPONS; i++ )
    1111    {
    12         if( wp->y[i] >= 0 )
     12        x = wp->x[i] >> 4;
     13        y = wp->y[i] >> 4;
     14
     15        switch( wp->type[i] )
    1316        {
    14             if( wp->x[i] <= t->left[wp->y[i]+1]
    15                  || wp->x[i] >= t->right[wp->y[i]+1] )
    16             {
    17                 add_explosion( g, ex, wp->x[i], wp->y[i]+1, 0, 1, 0 );
    18 
    19                 if( wp->x[i] <= t->left[wp->y[i]+1] )
    20                 {
    21                     t->left[wp->y[i]]--;
    22                     t->left[wp->y[i]+1]-=2;
    23                     t->left[wp->y[i]+2]--;
    24                 }
    25                 else
    26                 {
    27                     t->right[wp->y[i]]++;
    28                     t->right[wp->y[i]+1]+=2;
    29                     t->right[wp->y[i]+2]++;
    30                 }
    31 
    32                 wp->y[i] = -1;
    33             }
    34             else if( wp->x[i] <= t->left[wp->y[i]]
    35                       || wp->x[i] >= t->right[wp->y[i]] )
    36             {
    37                 add_explosion( g, ex, wp->x[i], wp->y[i], 0, 1, 0 );
    38 
    39                 if( wp->x[i] <= t->left[wp->y[i]] )
    40                 {
    41                     t->left[wp->y[i]-1]--;
    42                     t->left[wp->y[i]]-=2;
    43                     t->left[wp->y[i]+1]--;
    44                 }
    45                 else
    46                 {
    47                     t->right[wp->y[i]-1]++;
    48                     t->right[wp->y[i]]+=2;
    49                     t->right[wp->y[i]+1]++;
    50                 }
    51 
    52                 wp->y[i] = -1;
    53             }
     17            case WEAPON_NONE:
     18                break;
     19            case WEAPON_SEEKER:
     20                if( x <= t->left[y]
     21                     || x >= t->right[y] )
     22                {
     23                    add_explosion( g, ex, x, y, 0, 1, EXPLOSION_SMALL );
     24
     25                    if( x <= t->left[y] )
     26                    {
     27                        t->left[y-1]--;
     28                        t->left[y]-=2;
     29                        t->left[y+1]--;
     30                    }
     31                    else
     32                    {
     33                        t->right[y-1]++;
     34                        t->right[y]+=2;
     35                        t->right[y+1]++;
     36                    }
     37
     38                    wp->type[i] = WEAPON_NONE;
     39                }
     40                break;
     41            case WEAPON_LASER:
     42                if( x <= t->left[y+1]
     43                     || x >= t->right[y+1] )
     44                {
     45                    add_explosion( g, ex, x, y+1, 0, 1, EXPLOSION_SMALL );
     46
     47                    if( x <= t->left[y+1] )
     48                    {
     49                        t->left[y]--;
     50                        t->left[y+1]-=2;
     51                        t->left[y+2]--;
     52                    }
     53                    else
     54                    {
     55                        t->right[y]++;
     56                        t->right[y+1]+=2;
     57                        t->right[y+2]++;
     58                    }
     59
     60                    wp->type[i] = WEAPON_NONE;
     61                }
     62                else if( x <= t->left[y]
     63                          || x >= t->right[y] )
     64                {
     65                    add_explosion( g, ex, x, y, 0, 1, EXPLOSION_SMALL );
     66
     67                    if( x <= t->left[y] )
     68                    {
     69                        t->left[y-1]--;
     70                        t->left[y]-=2;
     71                        t->left[y+1]--;
     72                    }
     73                    else
     74                    {
     75                        t->right[y-1]++;
     76                        t->right[y]+=2;
     77                        t->right[y+1]++;
     78                    }
     79
     80                    wp->type[i] = WEAPON_NONE;
     81                }
     82                break;
     83            case WEAPON_NUKE:
     84                /* The nuke does not break the tunnel */
     85                break;
    5486        }
    5587    }
     
    5890void collide_weapons_aliens( game *g, weapons *wp, aliens *al, explosions *ex )
    5991{
    60     int i, j;
     92    int i, j, x, y;
    6193
    6294    for( i = 0; i < WEAPONS; i++ )
    6395    {
    64         if( wp->y[i] >= 0 )
     96        int ok = 0;
     97        int r;
     98
     99        x = wp->x[i] >> 4;
     100        y = wp->y[i] >> 4;
     101
     102        switch( wp->type[i] )
    65103        {
    66             int ok = 0;
    67             int r;
    68 
    69             switch( wp->type[i] )
    70             {
    71             case 2:
     104            case WEAPON_NONE:
     105                break;
     106            case WEAPON_NUKE:
    72107                /* Big nuke */
    73                 r = (34 - wp->n[i]) * (34 - wp->n[i]) / 10;
     108                r = (29 - wp->n[i]) * (29 - wp->n[i]) / 8;
    74109
    75110                for( j = 0; j < ALIENS; j++ )
    76111                {
    77                     if( al->x[j] < 0 )
     112                    if( al->type[j] == ALIEN_NONE )
    78113                    {
    79114                        continue;
    80115                    }
    81116
    82                     if( (al->x[j] - wp->x[i]) * (al->x[j] - wp->x[i])
    83                           + 4 * (al->y[j] - wp->y[i]) * (al->y[j] - wp->y[i])
     117                    if( wp->n[i] == 0 /* Nuke destroys _everything_ */ ||
     118                        (al->x[j] - x) * (al->x[j] - x)
     119                          + 4 * (al->y[j] - y) * (al->y[j] - y)
    84120                        <= r * r )
    85121                    {
    86122                        /* Kill alien, not nuke */
    87                         add_explosion( g, ex, al->x[j], al->y[j], 0, 0, 1 );
    88                         al->x[j] = -1;
    89                         al->y[j] = -1;
    90                     }
    91                 }
    92                 break;
    93 
    94             case 1:
    95             default:
     123                        al->type[j] = ALIEN_NONE;
     124                        add_explosion( g, ex, al->x[j], al->y[j], 0, 0, EXPLOSION_MEDIUM );
     125                        add_bonus( g, g->bo, al->x[j], al->y[j], GET_RAND(0,5) ? BONUS_GREEN : BONUS_LIFE );
     126                    }
     127                }
     128                break;
     129            case WEAPON_LASER:
    96130                for( j = 0; j < ALIENS; j++ )
    97131                {
    98                     if( wp->x[i] >= al->x[j]
    99                          && wp->x[i] <= al->x[j] + 4
    100                          && wp->y[i] >= al->y[j]
    101                          && wp->y[i] <= al->y[j] + 2 )
     132                    if( al->type[j] == ALIEN_NONE )
     133                    {
     134                        continue;
     135                    }
     136
     137                    if( x >= al->x[j] && x <= al->x[j] + 4
     138                         && y >= al->y[j] && y <= al->y[j] + 2 )
    102139                    {
    103140                        al->life[j]--;
    104                         if( al->life[j] == 0 )
     141                        if( al->life[j] <= 0 )
    105142                        {
    106                             al->x[j] = -1;
    107                             al->y[j] = -1;
    108                             add_explosion( g, ex, wp->x[i], wp->y[i], 0, 0, 1 );
     143                            al->type[j] = ALIEN_NONE;
     144                            add_explosion( g, ex, x, y, 0, 0, EXPLOSION_MEDIUM );
     145                            add_bonus( g, g->bo, x, y, GET_RAND(0,5) ? BONUS_GREEN : BONUS_LIFE );
    109146                        }
    110147                        ok = 1;
    111148                    }
    112                     else if( wp->x[i] >= al->x[j]
    113                               && wp->x[i] <= al->x[j] + 4
    114                               && wp->y[i]+1 >= al->y[j]
    115                               && wp->y[i]+1 <= al->y[j] + 2 )
     149                    else if( x >= al->x[j] && x <= al->x[j] + 4
     150                              && y+1 >= al->y[j] && y+1 <= al->y[j] + 2 )
    116151                    {
    117152                        al->life[j]--;
    118                         if( al->life[j] == 0 )
     153                        if( al->life[j] <= 0 )
    119154                        {
    120                             al->x[j] = -1;
    121                             al->y[j] = -1;
    122                             add_explosion( g, ex, wp->x[i], wp->y[i]+1, 0, 0, 1 );
     155                            al->type[j] = ALIEN_NONE;
     156                            add_explosion( g, ex, x, y+1, 0, 0, EXPLOSION_MEDIUM );
     157                            add_bonus( g, g->bo, x, y+1, GET_RAND(0,5) ? BONUS_GREEN : BONUS_LIFE );
    123158                        }
    124159                        ok = 1;
     
    128163                if( ok )
    129164                {
    130                     wp->y[i] = -1;
    131                 }
    132                 break;
    133             }
     165                    wp->type[i] = WEAPON_NONE;
     166                }
     167                break;
     168
     169            case WEAPON_SEEKER:
     170                for( j = 0; j < ALIENS; j++ )
     171                {
     172                    if( al->type[j] == ALIEN_NONE )
     173                    {
     174                        continue;
     175                    }
     176
     177                    if( x >= al->x[j] && x <= al->x[j] + 4
     178                         && y >= al->y[j] && y <= al->y[j] + 2 )
     179                    {
     180                        al->life[j]--;
     181                        if( al->life[j] <= 0 )
     182                        {
     183                            al->type[j] = ALIEN_NONE;
     184                            add_explosion( g, ex, x, y, 0, 0, EXPLOSION_MEDIUM );
     185                            add_bonus( g, g->bo, x, y, GET_RAND(0,5) ? BONUS_GREEN : BONUS_LIFE );
     186                        }
     187                        ok = 1;
     188                    }
     189                }
     190
     191                if( ok )
     192                {
     193                    wp->type[i] = WEAPON_NONE;
     194                }
     195                break;
    134196        }
    135197    }
     
    140202    if( p->x <= t->left[p->y] )
    141203    {
    142         p->x += 3;
    143         //add_explosion( g, ex, x+1, y-2, 0, 1, 0 );
     204        p->x += 2;
     205        add_explosion( g, ex, p->x+1, p->y-2, 0, 0, EXPLOSION_SMALL );
    144206    }
    145207    else if( p->x + 5 >= t->right[p->y] )
    146208    {
    147         p->x -= 3;
    148         //add_explosion( g, ex, x+4, y-2, 0, 1, 0 );
     209        p->x -= 2;
     210        add_explosion( g, ex, p->x+4, p->y-2, 0, 0, EXPLOSION_SMALL );
    149211    }
    150212}
  • libcaca/trunk/src/common.h

    r17 r19  
    22#define STARS 50
    33#define WEAPONS 50
    4 #define ROCKS 10
    5 #define ALIENS 10
     4#define BONUS 30
     5#define ALIENS 30
    66#define EXPLOSIONS 20
    77
    88#ifdef USE_SLANG
    99#   include <slang.h>
    10 #   define GFX_COLOR(x) SLsmg_set_color(x)
    11 #   define GFX_GOTO(x,y) SLsmg_gotorc(y,x)
    12 #   define GFX_WRITE(x) SLsmg_write_char(x)
     10#   define gfx_color(x) SLsmg_set_color(x)
     11#   define gfx_goto(x,y) SLsmg_gotorc(y,x)
     12#   define gfx_putchar(x) SLsmg_write_char(x)
     13#   define gfx_putstr(x) SLsmg_write_string(x)
    1314#else
    1415#   include <curses.h>
    15 #   define GFX_COLOR(x) attrset(COLOR_PAIR(x))
    16 #   define GFX_GOTO(x,y) move(y,x)
    17 #   define GFX_WRITE(x) addch(x)
     16#   define gfx_color(x) attrset(COLOR_PAIR(x))
     17#   define gfx_goto(x,y) move(y,x)
     18#   define gfx_putchar(x) addch(x)
     19#   define gfx_putstr(x) addstr(x)
    1820#endif
    1921
    20 #define GFX_WRITETO(x,y,c) do{ GFX_GOTO(x,y); GFX_WRITE(c); }while(0)
     22#define gfx_putcharTO(x,y,c) do{ gfx_goto(x,y); gfx_putchar(c); }while(0)
    2123
    2224#define GET_RAND(p,q) ((p)+(int)((1.0*((q)-(p)))*rand()/(RAND_MAX+1.0)))
    23 
    24 typedef struct
    25 {
    26     int w, h;
    27 
    28 } game;
    2925
    3026typedef struct
     
    4642typedef struct
    4743{
     44    enum { EXPLOSION_NONE, EXPLOSION_SMALL, EXPLOSION_MEDIUM } type[EXPLOSIONS];
    4845    int x[EXPLOSIONS];
    4946    int y[EXPLOSIONS];
    5047    int vx[EXPLOSIONS];
    5148    int vy[EXPLOSIONS];
    52     int type[EXPLOSIONS];
    5349    int n[EXPLOSIONS];
    5450
     
    5753typedef struct
    5854{
     55    enum { WEAPON_NONE, WEAPON_LASER, WEAPON_SEEKER, WEAPON_NUKE } type[WEAPONS];
    5956    int x[WEAPONS];
    6057    int y[WEAPONS];
    61     int v[WEAPONS];
     58    int x2[WEAPONS];
     59    int y2[WEAPONS];
     60    int x3[WEAPONS];
     61    int y3[WEAPONS];
     62    int vx[WEAPONS];
     63    int vy[WEAPONS];
    6264    int n[WEAPONS];
    63     int type[WEAPONS];
    6465
    6566} weapons;
     67
     68typedef struct
     69{
     70    enum { BONUS_NONE, BONUS_LIFE, BONUS_GREEN } type[BONUS];
     71    int x[BONUS];
     72    int y[BONUS];
     73    int n[BONUS];
     74
     75} bonus;
    6676
    6777typedef struct
     
    7585typedef struct
    7686{
     87    enum { ALIEN_NONE, ALIEN_POOLP, ALIEN_BOOL, ALIEN_BRAH } type[ALIENS];
    7788    int x[ALIENS];
    7889    int y[ALIENS];
     
    8192
    8293} aliens;
     94
     95typedef struct
     96{
     97    int w, h;
     98
     99    starfield *sf;
     100    weapons *wp;
     101    explosions *ex;
     102    tunnel *t;
     103    player *p;
     104    aliens *al;
     105    bonus *bo;
     106
     107} game;
    83108
    84109#define BLACK 1
     
    100125void draw_aliens( game *g, aliens *al );
    101126void update_aliens( game *g, aliens *al );
    102 void add_alien( game *g, aliens *al, int x, int y );
     127void add_alien( game *g, aliens *al, int x, int y, int type );
    103128
    104129int init_graphics( void );
     
    117142void draw_weapons( game *g, weapons *wp );
    118143void update_weapons( game *g, weapons *wp );
    119 void add_weapon( game *g, weapons *wp, int x, int y, int type );
     144void add_weapon( game *g, weapons *wp, int x, int y, int vx, int vy, int type );
     145
     146void init_bonus( game *g, bonus *bo );
     147void draw_bonus( game *g, bonus *bo );
     148void update_bonus( game *g, bonus *bo );
     149void add_bonus( game *g, bonus *bo, int x, int y, int type );
    120150
    121151void init_starfield( game *g, starfield *s );
  • libcaca/trunk/src/explosions.c

    r17 r19  
    55
    66static void draw_small_explosion( int x, int y, int frame );
    7 static void draw_big_explosion( int x, int y, int frame );
     7static void draw_medium_explosion( int x, int y, int frame );
    88
    99void init_explosions( game *g, explosions *ex )
     
    1313    for( i = 0; i < EXPLOSIONS; i++ )
    1414    {
    15         ex->n[i] = 0;
    16         ex->x[i] = -1;
    17         ex->y[i] = -1;
    18         ex->vx[i] = -1;
    19         ex->vy[i] = -1;
    20         ex->type[i] = 0;
     15        ex->type[i] = EXPLOSION_NONE;
    2116    }
    2217}
     
    2823    for( i = 0; i < EXPLOSIONS; i++ )
    2924    {
    30         if( ex->n[i] <= 0 )
    31         {
     25        if( ex->type[i] == EXPLOSION_NONE )
     26        {
     27            ex->type[i] = type;
    3228            ex->x[i] = x;
    3329            ex->y[i] = y;
     
    3632            switch( type )
    3733            {
    38                 case 1: ex->n[i] = 13; break;
    39                 case 2: ex->n[i] = 30; break;
    40                 case 0: default: ex->n[i] = 7; break;
     34                case EXPLOSION_MEDIUM:
     35                    ex->n[i] = 11;
     36                    break;
     37                case EXPLOSION_SMALL:
     38                    ex->n[i] = 7;
     39                    break;
    4140            }
    42             ex->type[i] = type;
    4341            break;
    4442        }
     
    5250    for( i = 0; i < EXPLOSIONS; i++ )
    5351    {
    54         if( ex->n[i] <= 0 )
    55         {
    56             continue;
    57         }
    58 
    5952#if 0
    60         GFX_COLOR( GREEN );
    61         GFX_GOTO( ex->x[i] + 3, ex->y[i] );
     53        gfx_color( GREEN );
     54        gfx_goto( ex->x[i] + 3, ex->y[i] );
    6255        switch( GET_RAND(0,3) )
    6356        {
    6457        case 0:
    65             GFX_WRITE( 'p' );
    66             GFX_WRITE( 'i' );
    67             GFX_WRITE( 'f' );
     58            gfx_putchar( 'p' );
     59            gfx_putchar( 'i' );
     60            gfx_putchar( 'f' );
    6861            break;
    6962        case 1:
    70             GFX_WRITE( 'p' );
    71             GFX_WRITE( 'a' );
    72             GFX_WRITE( 'f' );
     63            gfx_putchar( 'p' );
     64            gfx_putchar( 'a' );
     65            gfx_putchar( 'f' );
    7366            break;
    7467        case 2:
    75             GFX_WRITE( 'p' );
    76             GFX_WRITE( 'o' );
    77             GFX_WRITE( 'u' );
    78             GFX_WRITE( 'f' );
    79             break;
    80         }
    81         GFX_WRITE( '!' );
     68            gfx_putchar( 'p' );
     69            gfx_putchar( 'o' );
     70            gfx_putchar( 'u' );
     71            gfx_putchar( 'f' );
     72            break;
     73        }
     74        gfx_putchar( '!' );
    8275#endif
    8376
    8477        switch( ex->type[i] )
    8578        {
    86             case 1:
    87                 draw_big_explosion( ex->x[i], ex->y[i], ex->n[i] );
    88                 break;
    89             case 0:
    90             default:
     79            case EXPLOSION_MEDIUM:
     80                draw_medium_explosion( ex->x[i], ex->y[i], ex->n[i] );
     81                break;
     82            case EXPLOSION_SMALL:
    9183                draw_small_explosion( ex->x[i], ex->y[i], ex->n[i] );
    9284                break;
    93         }
    94 
     85            case EXPLOSION_NONE:
     86                break;
     87        }
    9588    }
    9689}
     
    10295    for( i = 0; i < EXPLOSIONS; i++ )
    10396    {
    104         if( ex->n[i] > 0 )
    105         {
    106             ex->x[i] += ex->vx[i];
    107             ex->y[i] += ex->vy[i];
    108             ex->n[i]--;
     97        switch( ex->type[i] )
     98        {
     99            case EXPLOSION_MEDIUM:
     100            case EXPLOSION_SMALL:
     101                ex->x[i] += ex->vx[i];
     102                ex->y[i] += ex->vy[i];
     103                ex->n[i]--;
     104                if( ex->n[i] < 0 )
     105                {
     106                    ex->type[i] = EXPLOSION_NONE;
     107                }
     108                break;
     109            case EXPLOSION_NONE:
     110                break;
    109111        }
    110112    }
     
    115117    switch( frame )
    116118    {
    117     default:
    118119    case 6:
    119         GFX_COLOR( YELLOW );
    120         GFX_GOTO( x, y );
    121         GFX_WRITE( '+' );
     120        gfx_color( YELLOW );
     121        gfx_goto( x, y );
     122        gfx_putchar( '+' );
    122123        break;
    123124    case 5:
    124         GFX_COLOR( YELLOW );
    125         GFX_GOTO( x, y );
    126         GFX_WRITE( 'o' );
     125        gfx_color( YELLOW );
     126        gfx_goto( x, y );
     127        gfx_putchar( 'o' );
    127128        break;
    128129    case 4:
    129         GFX_COLOR( YELLOW );
    130         GFX_GOTO( x, y-1 );
    131         GFX_WRITE( '_' );
    132         GFX_GOTO( x-1, y );
    133         GFX_WRITE( ')' );
    134         GFX_WRITE( '_' );
    135         GFX_WRITE( '(' );
     130        gfx_color( YELLOW );
     131        gfx_goto( x, y-1 );
     132        gfx_putchar( '_' );
     133        gfx_goto( x-1, y );
     134        gfx_putstr( ")_(" );
    136135        break;
    137136    case 3:
    138         GFX_COLOR( YELLOW );
    139         GFX_GOTO( x-1, y-1 );
    140         GFX_WRITE( '.' );
    141         GFX_WRITE( '_' );
    142         GFX_WRITE( ',' );
    143         GFX_GOTO( x-1, y );
    144         GFX_WRITE( ')' );
    145         GFX_WRITE( '_' );
    146         GFX_WRITE( '(' );
    147         GFX_GOTO( x-1, y+1 );
    148         GFX_WRITE( '\'' );
    149         GFX_WRITE( ' ' );
    150         GFX_WRITE( '`' );
     137        gfx_color( YELLOW );
     138        gfx_goto( x-1, y-1 );
     139        gfx_putstr( "._," );
     140        gfx_goto( x-1, y );
     141        gfx_putstr( ")_(" );
     142        gfx_goto( x-1, y+1 );
     143        gfx_putstr( "\' `" );
    151144        break;
    152145    case 2:
    153         GFX_COLOR( YELLOW );
    154         GFX_GOTO( x-1, y-1 );
    155         GFX_WRITE( '.' );
    156         GFX_WRITE( 'v' );
    157         GFX_WRITE( ',' );
    158         GFX_GOTO( x-1, y );
    159         GFX_WRITE( '>' );
    160         GFX_WRITE( ' ' );
    161         GFX_WRITE( '<' );
    162         GFX_GOTO( x-1, y+1 );
    163         GFX_WRITE( '\'' );
    164         GFX_WRITE( '^' );
    165         GFX_WRITE( '`' );
     146        gfx_color( YELLOW );
     147        gfx_goto( x-1, y-1 );
     148        gfx_putstr( ".v," );
     149        gfx_goto( x-1, y );
     150        gfx_putstr( "> <" );
     151        gfx_goto( x-1, y+1 );
     152        gfx_putstr( "\'^`" );
    166153        break;
    167154    case 1:
    168         GFX_COLOR( WHITE );
    169         GFX_GOTO( x-1, y-1 );
    170         GFX_WRITE( '.' );
    171         GFX_WRITE( ' ' );
    172         GFX_WRITE( ',' );
    173         GFX_GOTO( x-1, y );
    174         GFX_WRITE( ' ' );
    175         GFX_WRITE( ' ' );
    176         GFX_WRITE( ' ' );
    177         GFX_GOTO( x-1, y+1 );
    178         GFX_WRITE( '\'' );
    179         GFX_WRITE( ' ' );
    180         GFX_WRITE( '`' );
    181         break;
    182     }
    183 }
    184 
    185 static void draw_big_explosion( int x, int y, int frame )
    186 {
    187     GFX_COLOR( YELLOW );
     155        gfx_color( WHITE );
     156        gfx_goto( x-1, y-1 );
     157        gfx_putstr( ". ," );
     158        gfx_goto( x-1, y );
     159        gfx_putstr( "   " );
     160        gfx_goto( x-1, y+1 );
     161        gfx_putstr( "\' `" );
     162        break;
     163    }
     164}
     165
     166static void draw_medium_explosion( int x, int y, int frame )
     167{
     168    gfx_color( YELLOW );
    188169
    189170    switch( frame )
    190171    {
    191     default:
    192     case 12:
    193         GFX_GOTO( x, y );
    194         GFX_WRITE( '+' );
    195         break;
    196     case 11:
    197         GFX_GOTO( x, y );
    198         GFX_WRITE( 'o' );
    199         break;
    200172    case 10:
    201         GFX_GOTO( x, y-1 );
    202         GFX_WRITE( '_' );
    203         GFX_GOTO( x-1, y );
    204         GFX_WRITE( ')' );
    205         GFX_WRITE( '_' );
    206         GFX_WRITE( '(' );
     173        gfx_goto( x, y );
     174        gfx_putchar( '+' );
    207175        break;
    208176    case 9:
    209         GFX_GOTO( x-1, y-1 );
    210         GFX_WRITE( '.' );
    211         GFX_WRITE( '_' );
    212         GFX_WRITE( ',' );
    213         GFX_GOTO( x-1, y );
    214         GFX_WRITE( ')' );
    215         GFX_WRITE( '_' );
    216         GFX_WRITE( '(' );
    217         GFX_GOTO( x-1, y+1 );
    218         GFX_WRITE( '\'' );
    219         GFX_WRITE( ' ' );
    220         GFX_WRITE( '`' );
     177        gfx_goto( x, y );
     178        gfx_putchar( 'o' );
    221179        break;
    222180    case 8:
    223         GFX_GOTO( x-1, y-1 );
    224         GFX_WRITE( '.' );
    225         GFX_WRITE( 'v' );
    226         GFX_WRITE( ',' );
    227         GFX_GOTO( x-1, y );
    228         GFX_WRITE( '>' );
    229         GFX_WRITE( ' ' );
    230         GFX_WRITE( '<' );
    231         GFX_GOTO( x-1, y+1 );
    232         GFX_WRITE( '\'' );
    233         GFX_WRITE( '^' );
    234         GFX_WRITE( '`' );
     181        gfx_goto( x, y-1 );
     182        gfx_putchar( '_' );
     183        gfx_goto( x-1, y );
     184        gfx_putstr( ")_(" );
     185        break;
     186    case 7:
     187        gfx_goto( x-1, y-1 );
     188        gfx_putstr( "._," );
     189        gfx_goto( x-1, y );
     190        gfx_putstr( ")_(" );
     191        gfx_goto( x-1, y+1 );
     192        gfx_putstr( "\' `" );
    235193        break;
    236194    case 6:
    237         GFX_COLOR( RED );
    238     case 7:
     195        gfx_goto( x-1, y-1 );
     196        gfx_putstr( ".v," );
     197        gfx_goto( x-1, y );
     198        gfx_putstr( "> <" );
     199        gfx_goto( x-1, y+1 );
     200        gfx_putstr( "\'^`" );
     201        break;
    239202    case 5:
    240         GFX_GOTO( x-2, y-1 );
    241         GFX_WRITE( '_' );
    242         GFX_WRITE( '\\' );
    243         GFX_WRITE( '~' );
    244         GFX_WRITE( '/' );
    245         GFX_WRITE( '_' );
    246         GFX_GOTO( x-2, y );
    247         GFX_WRITE( '>' );
    248         GFX_WRITE( ' ' );
    249         GFX_WRITE( ' ' );
    250         GFX_WRITE( ' ' );
    251         GFX_WRITE( '<' );
    252         GFX_GOTO( x-2, y+1 );
    253         GFX_WRITE( '~' );
    254         GFX_WRITE( '/' );
    255         GFX_WRITE( '_' );
    256         GFX_WRITE( '\\' );
    257         GFX_WRITE( '~' );
     203        gfx_color( RED );
     204    case 4:
     205        gfx_goto( x-2, y-1 );
     206        gfx_putstr( "_\\~/_" );
     207        gfx_goto( x-2, y );
     208        gfx_putstr( ">   <" );
     209        gfx_goto( x-2, y+1 );
     210        gfx_putstr( "~/_\\~" );
    258211        break;
    259212    case 3:
    260         GFX_COLOR( RED );
    261     case 4:
     213        gfx_color( RED );
    262214    case 2:
    263         GFX_GOTO( x-2, y-1 );
    264         GFX_WRITE( '_' );
    265         GFX_WRITE( '\\' );
    266         GFX_WRITE( ' ' );
    267         GFX_WRITE( '/' );
    268         GFX_WRITE( '_' );
    269         GFX_GOTO( x-2, y );
    270         GFX_WRITE( '_' );
    271         GFX_WRITE( ' ' );
    272         GFX_WRITE( ' ' );
    273         GFX_WRITE( ' ' );
    274         GFX_WRITE( '_' );
    275         GFX_GOTO( x-2, y+1 );
    276         GFX_WRITE( ' ' );
    277         GFX_WRITE( '/' );
    278         GFX_WRITE( ' ' );
    279         GFX_WRITE( '\\' );
    280         GFX_WRITE( ' ' );
     215        gfx_goto( x-2, y-1 );
     216        gfx_putstr( "_\\ /_" );
     217        gfx_goto( x-2, y );
     218        gfx_putstr( "_   _" );
     219        gfx_goto( x-2, y+1 );
     220        gfx_putstr( " / \\ " );
    281221        break;
    282222    case 1:
    283         GFX_COLOR( WHITE );
    284         GFX_GOTO( x-2, y-1 );
    285         GFX_WRITE( '.' );
    286         GFX_WRITE( ' ' );
    287         GFX_WRITE( '\'' );
    288         GFX_WRITE( ' ' );
    289         GFX_WRITE( ',' );
    290         GFX_GOTO( x-2, y );
    291         GFX_WRITE( ' ' );
    292         GFX_WRITE( ' ' );
    293         GFX_WRITE( ' ' );
    294         GFX_WRITE( ' ' );
    295         GFX_WRITE( ' ' );
    296         GFX_GOTO( x-2, y+1 );
    297         GFX_WRITE( '\'' );
    298         GFX_WRITE( ' ' );
    299         GFX_WRITE( '.' );
    300         GFX_WRITE( ' ' );
    301         GFX_WRITE( '`' );
    302         break;
    303     }
    304 }
    305 
     223        gfx_color( WHITE );
     224        gfx_goto( x-2, y-1 );
     225        gfx_putstr( ". \' ," );
     226        gfx_goto( x-2, y );
     227        gfx_putstr( "     " );
     228        gfx_goto( x-2, y+1 );
     229        gfx_putstr( "\' . `" );
     230        break;
     231    }
     232}
     233
  • libcaca/trunk/src/graphics.c

    r17 r19  
    109109void refresh_graphics( void )
    110110{
    111     GFX_GOTO( 0, 0 );
     111    gfx_goto( 0, 0 );
    112112#ifdef USE_SLANG
    113113    SLsmg_refresh();
  • libcaca/trunk/src/main.c

    r17 r19  
    3333    game *g = malloc(sizeof(game));
    3434
    35 //    srand(time(NULL));
     35    //srand(time(NULL));
    3636
    3737    if( init_graphics() )
     
    5858    int poz = 0;
    5959    int skip = 0;
    60 
    61     starfield *sf = malloc(sizeof(starfield));
    62     weapons *wp = malloc(sizeof(weapons));
    63     explosions *ex = malloc(sizeof(explosions));
    64     tunnel *t = create_tunnel( g, g->w, g->h );
    65     player *p = create_player( g );
    66     aliens *al = malloc(sizeof(aliens));
    67 
    68     init_starfield( g, sf );
    69     init_weapons( g, wp );
    70     init_explosions( g, ex );
    71     init_aliens( g, al );
     60    int purcompteur = 0;
     61
     62    g->sf = malloc(sizeof(starfield));
     63    g->wp = malloc(sizeof(weapons));
     64    g->ex = malloc(sizeof(explosions));
     65    g->bo = malloc(sizeof(bonus));
     66    g->t = create_tunnel( g, g->w, g->h );
     67    g->p = create_player( g );
     68    g->al = malloc(sizeof(aliens));
     69
     70    init_starfield( g, g->sf );
     71    init_weapons( g, g->wp );
     72    init_explosions( g, g->ex );
     73    init_aliens( g, g->al );
    7274
    7375    /* Temporary stuff */
    7476    for( i = 0; i < 5; i++ )
    7577    {
    76         add_alien( g, al, rand() % g->w, rand() % g->h / 2 );
     78        add_alien( g, g->al, rand() % g->w, rand() % g->h / 2, ALIEN_POOLP );
    7779    }
    78     t->w = 25;
     80
     81    g->t->w = 25;
    7982
    8083    while( !quit )
     
    9699                    break;
    97100                case 'h':
    98                     p->dir = -3;
     101                    g->p->dir = -3;
    99102                    break;
    100103                case 'j':
    101                     if( p->y < g->h - 2 ) p->y += 1;
     104                    if( g->p->y < g->h - 2 ) g->p->y += 1;
    102105                    break;
    103106                case 'k':
    104                     if( p->y > 1 ) p->y -= 1;
     107                    if( g->p->y > 1 ) g->p->y -= 1;
    105108                    break;
    106109                case 'l':
    107                     p->dir = 3;
     110                    g->p->dir = 3;
    108111                    break;
    109112                case '\r':
    110                     if( p->nuke == 0 )
     113                    if( g->p->nuke == 0 )
    111114                    {
    112                         p->nuke = 40;
    113                         add_weapon( g, wp, p->x + 2, p->y, 2 );
     115                        g->p->nuke = 40;
     116                        add_weapon( g, g->wp, (g->p->x + 2) << 4, g->p->y << 4, 0, 0, WEAPON_NUKE );
    114117                    }
    115118                    break;
     119                case 'b':
     120                    if( g->p->weapon == 0 )
     121                    {
     122                        g->p->weapon = 4;
     123                        add_weapon( g, g->wp, g->p->x << 4, g->p->y << 4, -24, -16, WEAPON_SEEKER );
     124                        add_weapon( g, g->wp, (g->p->x + 5) << 4, g->p->y << 4, 24, -16, WEAPON_SEEKER );
     125                    }
    116126                case ' ':
    117                     if( p->weapon == 0 )
     127                    if( g->p->weapon == 0 )
    118128                    {
    119                         p->weapon = 4;
    120                         add_weapon( g, wp, p->x, p->y, 1 );
    121                         add_weapon( g, wp, p->x + 5, p->y, 1 );
     129                        g->p->weapon = 4;
     130                        add_weapon( g, g->wp, g->p->x << 4, g->p->y << 4, 0, -16, WEAPON_LASER );
     131                        add_weapon( g, g->wp, (g->p->x + 5) << 4, g->p->y << 4, 0, -16, WEAPON_LASER );
    122132                    }
    123133                    break;
     
    129139        if( GET_RAND(0,10) == 0 )
    130140        {
    131             add_alien( g, al, 0, rand() % g->h / 2 );
     141            int list[3] = { ALIEN_POOLP, ALIEN_BOOL, ALIEN_BRAH };
     142
     143            add_alien( g, g->al, 0, rand() % g->h / 2, list[GET_RAND(0,3)] );
    132144        }
    133145
     
    144156        }
    145157
     158        /* Update game rules */
     159        if( g->t->right[1] - g->t->left[1] == g->t->w )
     160        {
     161            g->t->w = 85 - g->t->w;
     162        }
     163
    146164        /* Scroll and update positions */
    147         collide_player_tunnel( g, p, t, ex );
    148         update_player( g, p );
    149         collide_player_tunnel( g, p, t, ex );
    150 
    151         update_starfield( g, sf );
    152         update_aliens( g, al );
    153 
    154         collide_weapons_tunnel( g, wp, t, ex );
    155         collide_weapons_aliens( g, wp, al, ex );
    156         update_weapons( g, wp );
    157         collide_weapons_tunnel( g, wp, t, ex );
    158         collide_weapons_aliens( g, wp, al, ex );
    159 
    160         update_explosions( g, ex );
    161         update_tunnel( g, t );
     165        collide_player_tunnel( g, g->p, g->t, g->ex );
     166        update_player( g, g->p );
     167        collide_player_tunnel( g, g->p, g->t, g->ex );
     168
     169        update_starfield( g, g->sf );
     170        update_bonus( g, g->bo );
     171        update_aliens( g, g->al );
     172
     173        collide_weapons_tunnel( g, g->wp, g->t, g->ex );
     174        collide_weapons_aliens( g, g->wp, g->al, g->ex );
     175        update_weapons( g, g->wp );
     176        collide_weapons_tunnel( g, g->wp, g->t, g->ex );
     177        collide_weapons_aliens( g, g->wp, g->al, g->ex );
     178
     179        update_explosions( g, g->ex );
     180        /*if(purcompteur%2)*/ update_tunnel( g, g->t );
    162181
    163182        /* Clear screen */
     
    165184
    166185        /* Print starfield, tunnel, aliens, player and explosions */
    167         draw_starfield( g, sf );
    168         draw_tunnel( g, t );
    169         draw_aliens( g, al );
    170         draw_player( g, p );
    171         draw_weapons( g, wp );
    172         draw_explosions( g, ex );
     186        draw_starfield( g, g->sf );
     187        draw_tunnel( g, g->t );
     188        draw_bonus( g, g->bo );
     189        draw_aliens( g, g->al );
     190        draw_player( g, g->p );
     191        draw_weapons( g, g->wp );
     192        draw_explosions( g, g->ex );
    173193
    174194        /* Refresh */
    175195        refresh_graphics();
     196
     197        purcompteur++;
    176198    }
    177199
    178200#if 0
    179201    free_player( p );
    180     free_tunnel( t );
     202    free_tunnel( g->t );
    181203#endif
    182204}
  • libcaca/trunk/src/player.c

    r17 r19  
    1010
    1111    p->x = g->w / 2;
    12     p->y = g->h - 3;
     12    p->y = g->h - 2;
    1313    p->dir = 0;
    1414    p->weapon = 0;
     
    2525void draw_player( game *g, player *p )
    2626{
    27     GFX_GOTO( p->x + 2, p->y - 2 );
    28     GFX_COLOR( GREEN );
    29     GFX_WRITE( '/' );
    30     GFX_WRITE( '\\' );
    31     GFX_GOTO( p->x + 1, p->y - 1 );
    32     GFX_WRITE( '(' );
    33     GFX_COLOR( YELLOW );
    34     GFX_WRITE( '(' );
    35     GFX_WRITE( ')' );
    36     GFX_COLOR( GREEN );
    37     GFX_WRITE( ')' );
    38     GFX_GOTO( p->x, p->y );
    39     GFX_COLOR( GREEN );
    40     GFX_WRITE( 'I' );
    41     GFX_WRITE( '<' );
    42     GFX_WRITE( '_' );
    43     GFX_WRITE( '_' );
    44     GFX_WRITE( '>' );
    45     GFX_WRITE( 'I' );
     27    gfx_goto( p->x + 2, p->y - 2 );
     28    gfx_color( GREEN );
     29    gfx_putstr( "/\\" );
     30    gfx_goto( p->x + 1, p->y - 1 );
     31    gfx_putchar( '(' );
     32    gfx_color( YELLOW );
     33    gfx_putstr( "()" );
     34    gfx_color( GREEN );
     35    gfx_putchar( ')' );
     36    gfx_goto( p->x, p->y );
     37    gfx_color( GREEN );
     38    gfx_putstr( "I<__>I" );
    4639}
    4740
  • libcaca/trunk/src/starfield.c

    r17 r19  
    2626        if( s->x[i] >= 0 )
    2727        {
    28             GFX_COLOR( s->c[i] );
    29             GFX_GOTO( s->x[i], s->y[i] );
    30             GFX_WRITE( s->ch[i] );
     28            gfx_color( s->c[i] );
     29            gfx_goto( s->x[i], s->y[i] );
     30            gfx_putchar( s->ch[i] );
    3131        }
    3232    }
  • libcaca/trunk/src/tunnel.c

    r17 r19  
    135135    int i;
    136136
     137    gfx_color( RED );
     138
    137139    for( i = 0; i < g->h ; i++ )
    138140    {
    139         char c;
     141        char *str;
    140142
    141143        if( wall[i] < 0 || wall[i] >= g->w )
     
    146148        if( wall[i] > wall[i+1] )
    147149        {
    148             c = wall[i] > wall[i-1] ? '>' : '/';
     150            str = wall[i] > wall[i-1] ? ">##>" : "/##/";
    149151        }
    150152        else
    151153        {
    152             c = wall[i] > wall[i-1] ? '\\' : '<';
     154            str = wall[i] > wall[i-1] ? "\\##\\" : "<##<";
    153155        }
    154156
    155         GFX_COLOR( RED );
    156157        if( wall[i] == wall[i+1] + 2 )
    157158        {
    158             GFX_GOTO( wall[i] - 1, i );
    159             GFX_WRITE( '_' );
     159            gfx_goto( wall[i] - 1, i );
     160            gfx_putchar( '_' );
    160161        }
    161         else
    162         {
    163             GFX_GOTO( wall[i], i );
    164         }
    165         GFX_WRITE( c );
    166         GFX_WRITE( '#' );
    167         GFX_WRITE( c );
    168         if( wall[i] == wall[i+1] - 2 ) GFX_WRITE( '_' );
     162
     163        gfx_goto( wall[i], i );
     164        gfx_putstr( str );
     165        if( wall[i] == wall[i+1] - 2 ) gfx_putchar( '_' );
    169166    }
    170167}
  • libcaca/trunk/src/weapons.c

    r17 r19  
    11
    22#include <stdlib.h>
     3#include <math.h>
    34
    45#include "common.h"
    56
    67static void draw_nuke( int x, int y, int frame );
    7 static void draw_circle( int x, int y, int r );
     8static void draw_circle( int x, int y, int r, char c );
    89
    910void init_weapons( game *g, weapons *wp )
     
    1314    for( i = 0; i < WEAPONS; i++ )
    1415    {
    15         wp->x[i] = -1;
    16         wp->y[i] = -1;
    17         wp->v[i] = 0;
    18         wp->n[i] = 0;
    19         wp->type[i] = 0;
     16        wp->type[i] = WEAPON_NONE;
    2017    }
    2118}
     
    2724    for( i = 0; i < WEAPONS; i++ )
    2825    {
    29         if( wp->x[i] >= 0 )
     26        switch( wp->type[i] )
    3027        {
    31             switch( wp->type[i] )
    32             {
    33                 case 2:
    34                     draw_nuke( wp->x[i], wp->y[i], wp->n[i] );
    35                     break;
    36                 case 1:
    37                 default:
    38                     GFX_COLOR( WHITE );
    39                     GFX_GOTO( wp->x[i], wp->y[i] );
    40                     GFX_WRITE( '|' );
    41                     GFX_COLOR( CYAN );
    42                     GFX_GOTO( wp->x[i], wp->y[i] + 1 );
    43                     GFX_WRITE( '|' );
    44                     break;
    45             }
     28            case WEAPON_LASER:
     29                gfx_color( WHITE );
     30                gfx_goto( wp->x[i] >> 4, wp->y[i] >> 4 );
     31                gfx_putchar( '|' );
     32                gfx_color( CYAN );
     33                gfx_goto( wp->x[i] >> 4, (wp->y[i] >> 4) + 1 );
     34                gfx_putchar( '|' );
     35                break;
     36            case WEAPON_SEEKER:
     37                gfx_color( CYAN );
     38                gfx_goto( wp->x3[i] >> 4, wp->y3[i] >> 4 );
     39                gfx_putchar( '.' );
     40                gfx_goto( wp->x2[i] >> 4, wp->y2[i] >> 4 );
     41                gfx_putchar( 'o' );
     42                gfx_color( WHITE );
     43                gfx_goto( wp->x[i] >> 4, wp->y[i] >> 4 );
     44                gfx_putchar( '@' );
     45                break;
     46            case WEAPON_NUKE:
     47                draw_nuke( wp->x[i] >> 4, wp->y[i] >> 4, wp->n[i] );
     48                break;
     49            case WEAPON_NONE:
     50                break;
    4651        }
    4752    }
     
    5055void update_weapons( game *g, weapons *wp )
    5156{
     57    int i, j, dist, xmin, ymin, dx, dy, xnew, ynew;
     58
     59    for( i = 0; i < WEAPONS; i++ )
     60    {
     61        switch( wp->type[i] )
     62        {
     63            case WEAPON_LASER:
     64                wp->x[i] += wp->vx[i];
     65                wp->y[i] += wp->vy[i];
     66                if( wp->y[i] < 0 )
     67                {
     68                    wp->type[i] = WEAPON_NONE;
     69                }
     70                break;
     71            case WEAPON_SEEKER:
     72                /* Update tail */
     73                wp->x3[i] = wp->x2[i];
     74                wp->y3[i] = wp->y2[i];
     75
     76                wp->x2[i] = wp->x[i];
     77                wp->y2[i] = wp->y[i];
     78
     79                wp->x[i] += wp->vx[i];
     80                wp->y[i] += wp->vy[i];
     81
     82                if( wp->y[i] < 0 )
     83                {
     84                    wp->type[i] = WEAPON_NONE;
     85                    break;
     86                }
     87
     88                if( wp->n[i] < 0 )
     89                {
     90                    /* Stop updating direction */
     91                    break;
     92                }
     93
     94                wp->n[i]--;
     95
     96                /* Estimate our position in 2 frames */
     97                xnew = wp->x[i] + 4 * wp->vx[i];
     98                ynew = wp->y[i] + 4 * wp->vy[i];
     99
     100                xmin = xnew;
     101                ymin = - (g->h << 4);
     102                dist = (xnew - xmin) * (xnew - xmin)
     103                        + 4 * (ynew - ymin) * (ynew - ymin);
     104
     105                /* Find the nearest alien */
     106                for( j = 0; j < ALIENS; j++ )
     107                {
     108                    if( g->al->type[j] != ALIEN_NONE )
     109                    {
     110                        int alx = g->al->x[j] << 4;
     111                        int aly = g->al->y[j] << 4;
     112                        int new = (xnew - alx) * (xnew - alx)
     113                                   + 4 * (ynew - aly) * (ynew - aly);
     114                        if( new <= dist )
     115                        {
     116                            dist = new;
     117                            xmin = alx;
     118                            ymin = aly;
     119                        }
     120                    }
     121                }
     122
     123                /* Find our new direction */
     124                dx = xmin - wp->x[i];
     125                dy = ymin - wp->y[i];
     126
     127                /* Normalize and update speed */
     128                wp->vx[i] = (7 * wp->vx[i]
     129                              + (dx * 48) / sqrt(dx*dx+dy*dy) ) / 8;
     130                wp->vy[i] = (7 * wp->vy[i]
     131                              + (dy * 24) / sqrt(dx*dx+dy*dy) ) / 8;
     132
     133                break;
     134            case WEAPON_NUKE:
     135                wp->n[i]--;
     136                if( wp->n[i] < 0 )
     137                {
     138                    wp->type[i] = WEAPON_NONE;
     139                }
     140                break;
     141            case WEAPON_NONE:
     142                break;
     143        }
     144    }
     145}
     146
     147void add_weapon( game *g, weapons *wp, int x, int y, int vx, int vy, int type )
     148{
    52149    int i;
    53150
    54151    for( i = 0; i < WEAPONS; i++ )
    55152    {
    56         if( wp->y[i] < 0 )
    57         {
    58             wp->x[i] = -1;
    59             wp->y[i] = -1;
    60         }
    61         else
    62         {
    63             switch( wp->type[i] )
    64             {
    65             case 2:
    66                 wp->n[i]--;
    67                 if( wp->n[i]-- < 0 )
    68                 {
    69                     wp->y[i] = -1;
    70                 }
    71                 break;
    72             case 1:
    73             default:
    74                 wp->y[i] += wp->v[i];
    75                 break;
    76             }
    77 
    78             /* Check collisions */
    79         }
    80     }
    81 }
    82 
    83 void add_weapon( game *g, weapons *wp, int x, int y, int type )
    84 {
    85     int i;
    86 
    87     for( i = 0; i < WEAPONS; i++ )
    88     {
    89         if( wp->y[i] < 0 )
     153        if( wp->type[i] == WEAPON_NONE )
    90154        {
    91155            wp->x[i] = x;
    92156            wp->y[i] = y;
     157            wp->vx[i] = vx;
     158            wp->vy[i] = vy;
    93159            wp->type[i] = type;
    94             wp->v[i] = -2;
    95             wp->n[i] = 30;
     160            switch( type )
     161            {
     162                case WEAPON_LASER:
     163                    break;
     164                case WEAPON_SEEKER:
     165                    wp->x2[i] = x;
     166                    wp->y2[i] = y;
     167                    wp->x3[i] = x;
     168                    wp->y3[i] = y;
     169                    wp->n[i] = 10;
     170                    break;
     171                case WEAPON_NUKE:
     172                    wp->n[i] = 25;
     173                    break;
     174                case WEAPON_NONE:
     175                    break;
     176            }
    96177            break;
    97178        }
     
    101182static void draw_nuke( int x, int y, int frame )
    102183{
    103     int r = (34 - frame) * (34 - frame) / 10;
     184    int r = (29 - frame) * (29 - frame) / 8;
    104185
    105186    /* Lots of duplicate pixels, but we don't care */
    106     GFX_COLOR( BLUE );
    107     draw_circle( x, y, r++ );
    108     GFX_COLOR( CYAN );
    109     draw_circle( x, y, r++ );
    110     GFX_COLOR( WHITE );
    111     draw_circle( x, y, r++ );
    112     draw_circle( x, y, r++ );
    113 }
    114 
    115 static void draw_circle( int x, int y, int r )
     187    gfx_color( BLUE );
     188    draw_circle( x, y, r++, ':' );
     189    gfx_color( CYAN );
     190    draw_circle( x, y, r++, '%' );
     191    gfx_color( WHITE );
     192    draw_circle( x, y, r++, '#' );
     193    draw_circle( x, y, r++, '#' );
     194}
     195
     196static void draw_circle( int x, int y, int r, char c )
    116197{
    117198    int test, dx, dy;
     
    120201    for( test = 0, dx = 0, dy = r ; dx <= dy ; dx++ )
    121202    {
    122         GFX_WRITETO( x + dx, y + dy / 2, '#' );
    123         GFX_WRITETO( x - dx, y + dy / 2, '#' );
    124         GFX_WRITETO( x + dx, y - dy / 2, '#' );
    125         GFX_WRITETO( x - dx, y - dy / 2, '#' );
    126 
    127         GFX_WRITETO( x + dy, y + dx / 2, '#' );
    128         GFX_WRITETO( x - dy, y + dx / 2, '#' );
    129         GFX_WRITETO( x + dy, y - dx / 2, '#' );
    130         GFX_WRITETO( x - dy, y - dx / 2, '#' );
     203        gfx_putcharTO( x + dx, y + dy / 2, c );
     204        gfx_putcharTO( x - dx, y + dy / 2, c );
     205        gfx_putcharTO( x + dx, y - dy / 2, c );
     206        gfx_putcharTO( x - dx, y - dy / 2, c );
     207
     208        gfx_putcharTO( x + dy, y + dx / 2, c );
     209        gfx_putcharTO( x - dy, y + dx / 2, c );
     210        gfx_putcharTO( x + dy, y - dx / 2, c );
     211        gfx_putcharTO( x - dy, y - dx / 2, c );
    131212
    132213        test += test > 0 ? dx - dy-- : dx;
Note: See TracChangeset for help on using the changeset viewer.