Changeset 19
- Timestamp:
- Dec 15, 2002, 4:41:32 AM (20 years ago)
- Location:
- libcaca/trunk
- Files:
-
- 1 added
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/Makefile
r17 r19 77 77 PACKAGE_BUGREPORT = 78 78 PACKAGE_NAME = ttyvaders 79 PACKAGE_STRING = ttyvaders 0.0 -cvs79 PACKAGE_STRING = ttyvaders 0.0cvs 80 80 PACKAGE_TARNAME = ttyvaders 81 PACKAGE_VERSION = 0.0 -cvs81 PACKAGE_VERSION = 0.0cvs 82 82 PATH_SEPARATOR = : 83 83 SET_MAKE = … … 86 86 USE_NCURSES_FALSE = 87 87 USE_NCURSES_TRUE = # 88 VERSION = 0.0 -cvs88 VERSION = 0.0cvs 89 89 ac_ct_CC = gcc 90 90 ac_ct_STRIP = -
libcaca/trunk/configure.ac
r17 r19 1 1 dnl Autoconf settings for ttyvaders 2 2 3 AC_INIT(ttyvaders,0.0 -cvs)3 AC_INIT(ttyvaders,0.0cvs) 4 4 5 5 AC_PREREQ(2.50) … … 7 7 AC_CANONICAL_SYSTEM 8 8 9 AM_INIT_AUTOMAKE(ttyvaders,0.0 -cvs)9 AM_INIT_AUTOMAKE(ttyvaders,0.0cvs) 10 10 AM_CONFIG_HEADER(config.h) 11 11 -
libcaca/trunk/debian/changelog
r17 r19 1 ttyvaders (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 1 Source: ttyvaders 2 Section: games 3 Priority: optional 4 Maintainer: Samuel Hocevar <sam@zoy.org> 5 Build-Depends: debhelper (>=2.2.0), slang1-dev 6 Standards-Version: 3.5.6 7 8 Package: ttyvaders 9 Section: games 10 Architecture: any 11 Depends: ${shlibs:Depends} 12 Description: 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 4 export DH_COMPAT=3 5 export DEB_HOST_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE) 6 export DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE) 7 8 # FOR AUTOCONF 2.52 AND NEWER ONLY 9 ifeq ($(DEB_BUILD_GNU_TYPE), $(DEB_HOST_GNU_TYPE)) 10 confflags += --build $(DEB_HOST_GNU_TYPE) 11 else 12 confflags += --build $(DEB_BUILD_GNU_TYPE) --host $(DEB_HOST_GNU_TYPE) 13 endif 14 15 confflags += --mandir=\$${prefix}/share/man --infodir=\$${prefix}/share/info 16 17 configure: configure-stamp 18 configure-stamp: 19 dh_testdir 20 ./configure $(confflags) --prefix=/usr 21 touch configure-stamp 22 23 build: configure-stamp build-stamp 24 build-stamp: 25 dh_testdir 26 $(MAKE) 27 touch build-stamp 28 29 clean: 30 dh_testdir 31 dh_testroot 32 rm -f build-stamp configure-stamp 33 -$(MAKE) distclean 34 dh_clean 35 36 install: 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. 44 binary-indep: build install 45 # We have nothing to do by default. 46 47 # Build architecture-dependent files here. 48 binary-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 76 binary: binary-indep binary-arch 77 .PHONY: build clean binary-indep binary-arch binary install configure -
libcaca/trunk/doc/shapes.txt
r17 r19 3 3 -------- 4 4 5 /\ 6 (()) 7 I<__>I 5 /\ /~\ 6 (()) ]O[ 7 I<__>I I\#/I 8 8 9 9 … … 14 14 \O o/ \o O/ 15 15 ^^^^^ ^^^^^ 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 29 Bonus 30 ----- 31 _ _ _ 32 /|\ / \ /.\ 33 \|/ \_/ \_/ 34 35 ,--. ,--. ,--. 36 \VV/ \~~/ \ / 37 \/ \/ \/ 38 _ _ _ _ 39 ( `' ) ( ' ) 40 \ / `v' 41 \/ 42 ___ 43 / g \ 44 \___/ 16 45 17 46 Shots 18 47 ----- 19 48 20 | / _, ___ \ 21 | / ' \ 49 .o@ . o @ . o @ 50 51 .o() . o () . o () 52 53 | / _, ___ ._ \ 54 | / ' ` \ 22 55 23 56 -
libcaca/trunk/src/Makefile.am
r17 r19 3 3 ############################################################################### 4 4 5 AM_C PPFLAGS = -g -O6 -fno-strength-reduce -fomit-frame-pointer5 AM_CFLAGS = -g -O6 -fno-strength-reduce -fomit-frame-pointer 6 6 7 7 # Code qui fait des warnings == code de porc == deux baffes dans ta gueule 8 AM_C PPFLAGS += -Wall -Wpointer-arith -Wcast-align -Wcast-qual -Wstrict-prototypes -Wshadow -Waggregate-return -Wmissing-prototypes -Wnested-externs8 AM_CFLAGS += -Wall -Wpointer-arith -Wcast-align -Wcast-qual -Wstrict-prototypes -Wshadow -Waggregate-return -Wmissing-prototypes -Wnested-externs 9 9 10 10 if USE_NCURSES … … 20 20 ttyvaders_SOURCES = \ 21 21 aliens.c \ 22 bonus.c \ 22 23 common.h \ 23 24 explosions.c \ -
libcaca/trunk/src/aliens.c
r17 r19 4 4 #include "common.h" 5 5 6 static void draw_alien( game *g, int x, int y, int type ); 6 static void draw_alien_poolp( game *g, int x, int y, int frame ); 7 static void draw_alien_bool( game *g, int x, int y, int frame ); 8 static void draw_alien_brah( game *g, int x, int y, int frame ); 7 9 8 10 void init_aliens( game *g, aliens *al ) … … 12 14 for( i = 0; i < ALIENS; i++ ) 13 15 { 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; 18 17 } 19 18 } … … 25 24 for( i = 0; i < ALIENS; i++ ) 26 25 { 27 if( al->y[i] >= 0)26 switch( al->type[i] ) 28 27 { 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; 30 39 } 31 40 } … … 38 47 for( i = 0; i < ALIENS; i++ ) 39 48 { 40 if( al->y[i] < 0)49 switch( al->type[i] ) 41 50 { 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; 43 64 } 44 else 65 } 66 } 67 68 void 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 ) 45 75 { 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; 65 77 al->x[i] = x; 66 78 al->y[i] = y; 67 79 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 69 96 break; 70 97 } … … 72 99 } 73 100 74 static void draw_alien ( game *g, int x, int y, int type )75 { 76 switch( type )101 static void draw_alien_poolp( game *g, int x, int y, int frame ) 102 { 103 switch( frame ) 77 104 { 78 105 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( "^^^^^" ); 100 117 break; 101 118 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 134 static 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; 132 158 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 171 static 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: 153 186 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 6 6 void collide_weapons_tunnel( game *g, weapons *wp, tunnel *t, explosions *ex ) 7 7 { 8 int i ;8 int i, x, y; 9 9 10 10 for( i = 0; i < WEAPONS; i++ ) 11 11 { 12 if( wp->y[i] >= 0 ) 12 x = wp->x[i] >> 4; 13 y = wp->y[i] >> 4; 14 15 switch( wp->type[i] ) 13 16 { 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; 54 86 } 55 87 } … … 58 90 void collide_weapons_aliens( game *g, weapons *wp, aliens *al, explosions *ex ) 59 91 { 60 int i, j ;92 int i, j, x, y; 61 93 62 94 for( i = 0; i < WEAPONS; i++ ) 63 95 { 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] ) 65 103 { 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: 72 107 /* Big nuke */ 73 r = ( 34 - wp->n[i]) * (34 - wp->n[i]) / 10;108 r = (29 - wp->n[i]) * (29 - wp->n[i]) / 8; 74 109 75 110 for( j = 0; j < ALIENS; j++ ) 76 111 { 77 if( al-> x[j] < 0)112 if( al->type[j] == ALIEN_NONE ) 78 113 { 79 114 continue; 80 115 } 81 116 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) 84 120 <= r * r ) 85 121 { 86 122 /* 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: 96 130 for( j = 0; j < ALIENS; j++ ) 97 131 { 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 ) 102 139 { 103 140 al->life[j]--; 104 if( al->life[j] == 0 )141 if( al->life[j] <= 0 ) 105 142 { 106 al-> x[j] = -1;107 a l->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 ); 109 146 } 110 147 ok = 1; 111 148 } 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 ) 116 151 { 117 152 al->life[j]--; 118 if( al->life[j] == 0 )153 if( al->life[j] <= 0 ) 119 154 { 120 al-> x[j] = -1;121 a l->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 ); 123 158 } 124 159 ok = 1; … … 128 163 if( ok ) 129 164 { 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; 134 196 } 135 197 } … … 140 202 if( p->x <= t->left[p->y] ) 141 203 { 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 ); 144 206 } 145 207 else if( p->x + 5 >= t->right[p->y] ) 146 208 { 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 ); 149 211 } 150 212 } -
libcaca/trunk/src/common.h
r17 r19 2 2 #define STARS 50 3 3 #define WEAPONS 50 4 #define ROCKS 105 #define ALIENS 104 #define BONUS 30 5 #define ALIENS 30 6 6 #define EXPLOSIONS 20 7 7 8 8 #ifdef USE_SLANG 9 9 # 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) 13 14 #else 14 15 # 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) 18 20 #endif 19 21 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) 21 23 22 24 #define GET_RAND(p,q) ((p)+(int)((1.0*((q)-(p)))*rand()/(RAND_MAX+1.0))) 23 24 typedef struct25 {26 int w, h;27 28 } game;29 25 30 26 typedef struct … … 46 42 typedef struct 47 43 { 44 enum { EXPLOSION_NONE, EXPLOSION_SMALL, EXPLOSION_MEDIUM } type[EXPLOSIONS]; 48 45 int x[EXPLOSIONS]; 49 46 int y[EXPLOSIONS]; 50 47 int vx[EXPLOSIONS]; 51 48 int vy[EXPLOSIONS]; 52 int type[EXPLOSIONS];53 49 int n[EXPLOSIONS]; 54 50 … … 57 53 typedef struct 58 54 { 55 enum { WEAPON_NONE, WEAPON_LASER, WEAPON_SEEKER, WEAPON_NUKE } type[WEAPONS]; 59 56 int x[WEAPONS]; 60 57 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]; 62 64 int n[WEAPONS]; 63 int type[WEAPONS];64 65 65 66 } weapons; 67 68 typedef 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; 66 76 67 77 typedef struct … … 75 85 typedef struct 76 86 { 87 enum { ALIEN_NONE, ALIEN_POOLP, ALIEN_BOOL, ALIEN_BRAH } type[ALIENS]; 77 88 int x[ALIENS]; 78 89 int y[ALIENS]; … … 81 92 82 93 } aliens; 94 95 typedef 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; 83 108 84 109 #define BLACK 1 … … 100 125 void draw_aliens( game *g, aliens *al ); 101 126 void update_aliens( game *g, aliens *al ); 102 void add_alien( game *g, aliens *al, int x, int y );127 void add_alien( game *g, aliens *al, int x, int y, int type ); 103 128 104 129 int init_graphics( void ); … … 117 142 void draw_weapons( game *g, weapons *wp ); 118 143 void update_weapons( game *g, weapons *wp ); 119 void add_weapon( game *g, weapons *wp, int x, int y, int type ); 144 void add_weapon( game *g, weapons *wp, int x, int y, int vx, int vy, int type ); 145 146 void init_bonus( game *g, bonus *bo ); 147 void draw_bonus( game *g, bonus *bo ); 148 void update_bonus( game *g, bonus *bo ); 149 void add_bonus( game *g, bonus *bo, int x, int y, int type ); 120 150 121 151 void init_starfield( game *g, starfield *s ); -
libcaca/trunk/src/explosions.c
r17 r19 5 5 6 6 static void draw_small_explosion( int x, int y, int frame ); 7 static void draw_ big_explosion( int x, int y, int frame );7 static void draw_medium_explosion( int x, int y, int frame ); 8 8 9 9 void init_explosions( game *g, explosions *ex ) … … 13 13 for( i = 0; i < EXPLOSIONS; i++ ) 14 14 { 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; 21 16 } 22 17 } … … 28 23 for( i = 0; i < EXPLOSIONS; i++ ) 29 24 { 30 if( ex->n[i] <= 0 ) 31 { 25 if( ex->type[i] == EXPLOSION_NONE ) 26 { 27 ex->type[i] = type; 32 28 ex->x[i] = x; 33 29 ex->y[i] = y; … … 36 32 switch( type ) 37 33 { 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; 41 40 } 42 ex->type[i] = type;43 41 break; 44 42 } … … 52 50 for( i = 0; i < EXPLOSIONS; i++ ) 53 51 { 54 if( ex->n[i] <= 0 )55 {56 continue;57 }58 59 52 #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] ); 62 55 switch( GET_RAND(0,3) ) 63 56 { 64 57 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' ); 68 61 break; 69 62 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' ); 73 66 break; 74 67 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( '!' ); 82 75 #endif 83 76 84 77 switch( ex->type[i] ) 85 78 { 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: 91 83 draw_small_explosion( ex->x[i], ex->y[i], ex->n[i] ); 92 84 break; 93 } 94 85 case EXPLOSION_NONE: 86 break; 87 } 95 88 } 96 89 } … … 102 95 for( i = 0; i < EXPLOSIONS; i++ ) 103 96 { 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; 109 111 } 110 112 } … … 115 117 switch( frame ) 116 118 { 117 default:118 119 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( '+' ); 122 123 break; 123 124 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' ); 127 128 break; 128 129 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( ")_(" ); 136 135 break; 137 136 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( "\' `" ); 151 144 break; 152 145 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( "\'^`" ); 166 153 break; 167 154 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 166 static void draw_medium_explosion( int x, int y, int frame ) 167 { 168 gfx_color( YELLOW ); 188 169 189 170 switch( frame ) 190 171 { 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;200 172 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( '+' ); 207 175 break; 208 176 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' ); 221 179 break; 222 180 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( "\' `" ); 235 193 break; 236 194 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; 239 202 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( "~/_\\~" ); 258 211 break; 259 212 case 3: 260 GFX_COLOR( RED ); 261 case 4: 213 gfx_color( RED ); 262 214 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( " / \\ " ); 281 221 break; 282 222 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 109 109 void refresh_graphics( void ) 110 110 { 111 GFX_GOTO( 0, 0 );111 gfx_goto( 0, 0 ); 112 112 #ifdef USE_SLANG 113 113 SLsmg_refresh(); -
libcaca/trunk/src/main.c
r17 r19 33 33 game *g = malloc(sizeof(game)); 34 34 35 //srand(time(NULL));35 //srand(time(NULL)); 36 36 37 37 if( init_graphics() ) … … 58 58 int poz = 0; 59 59 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 ); 72 74 73 75 /* Temporary stuff */ 74 76 for( i = 0; i < 5; i++ ) 75 77 { 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 ); 77 79 } 78 t->w = 25; 80 81 g->t->w = 25; 79 82 80 83 while( !quit ) … … 96 99 break; 97 100 case 'h': 98 p->dir = -3;101 g->p->dir = -3; 99 102 break; 100 103 case 'j': 101 if( p->y < g->h - 2 )p->y += 1;104 if( g->p->y < g->h - 2 ) g->p->y += 1; 102 105 break; 103 106 case 'k': 104 if( p->y > 1 )p->y -= 1;107 if( g->p->y > 1 ) g->p->y -= 1; 105 108 break; 106 109 case 'l': 107 p->dir = 3;110 g->p->dir = 3; 108 111 break; 109 112 case '\r': 110 if( p->nuke == 0 )113 if( g->p->nuke == 0 ) 111 114 { 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 ); 114 117 } 115 118 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 } 116 126 case ' ': 117 if( p->weapon == 0 )127 if( g->p->weapon == 0 ) 118 128 { 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 ); 122 132 } 123 133 break; … … 129 139 if( GET_RAND(0,10) == 0 ) 130 140 { 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)] ); 132 144 } 133 145 … … 144 156 } 145 157 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 146 164 /* 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 ); 162 181 163 182 /* Clear screen */ … … 165 184 166 185 /* 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 ); 173 193 174 194 /* Refresh */ 175 195 refresh_graphics(); 196 197 purcompteur++; 176 198 } 177 199 178 200 #if 0 179 201 free_player( p ); 180 free_tunnel( t );202 free_tunnel( g->t ); 181 203 #endif 182 204 } -
libcaca/trunk/src/player.c
r17 r19 10 10 11 11 p->x = g->w / 2; 12 p->y = g->h - 3;12 p->y = g->h - 2; 13 13 p->dir = 0; 14 14 p->weapon = 0; … … 25 25 void draw_player( game *g, player *p ) 26 26 { 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" ); 46 39 } 47 40 -
libcaca/trunk/src/starfield.c
r17 r19 26 26 if( s->x[i] >= 0 ) 27 27 { 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] ); 31 31 } 32 32 } -
libcaca/trunk/src/tunnel.c
r17 r19 135 135 int i; 136 136 137 gfx_color( RED ); 138 137 139 for( i = 0; i < g->h ; i++ ) 138 140 { 139 char c;141 char *str; 140 142 141 143 if( wall[i] < 0 || wall[i] >= g->w ) … … 146 148 if( wall[i] > wall[i+1] ) 147 149 { 148 c = wall[i] > wall[i-1] ? '>' : '/';150 str = wall[i] > wall[i-1] ? ">##>" : "/##/"; 149 151 } 150 152 else 151 153 { 152 c = wall[i] > wall[i-1] ? '\\' : '<';154 str = wall[i] > wall[i-1] ? "\\##\\" : "<##<"; 153 155 } 154 156 155 GFX_COLOR( RED );156 157 if( wall[i] == wall[i+1] + 2 ) 157 158 { 158 GFX_GOTO( wall[i] - 1, i );159 GFX_WRITE( '_' );159 gfx_goto( wall[i] - 1, i ); 160 gfx_putchar( '_' ); 160 161 } 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( '_' ); 169 166 } 170 167 } -
libcaca/trunk/src/weapons.c
r17 r19 1 1 2 2 #include <stdlib.h> 3 #include <math.h> 3 4 4 5 #include "common.h" 5 6 6 7 static void draw_nuke( int x, int y, int frame ); 7 static void draw_circle( int x, int y, int r );8 static void draw_circle( int x, int y, int r, char c ); 8 9 9 10 void init_weapons( game *g, weapons *wp ) … … 13 14 for( i = 0; i < WEAPONS; i++ ) 14 15 { 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; 20 17 } 21 18 } … … 27 24 for( i = 0; i < WEAPONS; i++ ) 28 25 { 29 if( wp->x[i] >= 0)26 switch( wp->type[i] ) 30 27 { 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; 46 51 } 47 52 } … … 50 55 void update_weapons( game *g, weapons *wp ) 51 56 { 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 147 void add_weapon( game *g, weapons *wp, int x, int y, int vx, int vy, int type ) 148 { 52 149 int i; 53 150 54 151 for( i = 0; i < WEAPONS; i++ ) 55 152 { 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 ) 90 154 { 91 155 wp->x[i] = x; 92 156 wp->y[i] = y; 157 wp->vx[i] = vx; 158 wp->vy[i] = vy; 93 159 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 } 96 177 break; 97 178 } … … 101 182 static void draw_nuke( int x, int y, int frame ) 102 183 { 103 int r = ( 34 - frame) * (34 - frame) / 10;184 int r = (29 - frame) * (29 - frame) / 8; 104 185 105 186 /* 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 196 static void draw_circle( int x, int y, int r, char c ) 116 197 { 117 198 int test, dx, dy; … … 120 201 for( test = 0, dx = 0, dy = r ; dx <= dy ; dx++ ) 121 202 { 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 ); 131 212 132 213 test += test > 0 ? dx - dy-- : dx;
Note: See TracChangeset
for help on using the changeset viewer.