Changeset 16
 Timestamp:
 Dec 13, 2002 8:27:16 PM (12 years ago)
 Location:
 ttyvaders/trunk
 Files:

 6 edited
Legend:
 Unmodified
 Added
 Removed

ttyvaders/trunk/collide.c
r12 r16 8 8 int i; 9 9 10 for( i = 0; i < SHOTS; i++ )10 for( i = 0; i < WEAPONS; i++ ) 11 11 { 12 12 if( wp>y[i] >= 0 ) … … 60 60 int i, j; 61 61 62 for( i = 0; i < SHOTS; i++ )62 for( i = 0; i < WEAPONS; i++ ) 63 63 { 64 64 if( wp>y[i] >= 0 ) 65 65 { 66 66 int ok = 0; 67 int r; 67 68 68 for( j = 0; j < ALIENS; j++)69 switch( wp>type[i] ) 69 70 { 70 if( wp>x[i] >= al>x[j] 71 && wp>x[i] <= al>x[j] + 4 72 && wp>y[i] >= al>y[j] 73 && wp>y[i] <= al>y[j] + 2 ) 71 case 2: 72 /* Big nuke */ 73 r = (34  wp>n[i]) * (34  wp>n[i]) / 10; 74 75 for( j = 0; j < ALIENS; j++ ) 74 76 { 75 al>life[j]; 76 if( al>life[j] == 0 ) 77 if( al>x[j] < 0 ) 77 78 { 79 continue; 80 } 81 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]) 84 <= r * r ) 85 { 86 /* Kill alien, not nuke */ 87 add_explosion( g, ex, al>x[j], al>y[j], 0, 0, 1 ); 78 88 al>x[j] = 1; 79 89 al>y[j] = 1; 80 add_explosion( g, ex, wp>x[i], wp>y[i], 0, 0, 1 );81 90 } 82 ok = 1;83 91 } 84 else if( wp>x[i] >= al>x[j] 85 && wp>x[i] <= al>x[j] + 4 86 && wp>y[i]+1 >= al>y[j] 87 && wp>y[i]+1 <= al>y[j] + 2 ) 92 break; 93 94 case 1: 95 default: 96 for( j = 0; j < ALIENS; j++ ) 88 97 { 89 al>life[j]; 90 if( al>life[j] == 0 ) 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 ) 91 102 { 92 al>x[j] = 1; 93 al>y[j] = 1; 94 add_explosion( g, ex, wp>x[i], wp>y[i]+1, 0, 0, 1 ); 103 al>life[j]; 104 if( al>life[j] == 0 ) 105 { 106 al>x[j] = 1; 107 al>y[j] = 1; 108 add_explosion( g, ex, wp>x[i], wp>y[i], 0, 0, 1 ); 109 } 110 ok = 1; 95 111 } 96 ok = 1; 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 ) 116 { 117 al>life[j]; 118 if( al>life[j] == 0 ) 119 { 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 ); 123 } 124 ok = 1; 125 } 97 126 } 98 }99 127 100 if( ok ) 101 { 102 wp>y[i] = 1; 128 if( ok ) 129 { 130 wp>y[i] = 1; 131 } 132 break; 103 133 } 104 134 } 
ttyvaders/trunk/common.h
r12 r16 1 1 2 2 #define STARS 50 3 #define SHOTS 503 #define WEAPONS 50 4 4 #define ROCKS 10 5 5 #define ALIENS 10 … … 17 17 # define GFX_WRITE(x) addch(x) 18 18 #endif 19 20 #define GFX_WRITETO(x,y,c) do{ GFX_GOTO(x,y); GFX_WRITE(c); }while(0) 19 21 20 22 #define GET_RAND(p,q) ((p)+(int)((1.0*((q)(p)))*rand()/(RAND_MAX+1.0))) … … 55 57 typedef struct 56 58 { 57 int x[SHOTS]; 58 int y[SHOTS]; 59 int v[SHOTS]; 59 int x[WEAPONS]; 60 int y[WEAPONS]; 61 int v[WEAPONS]; 62 int n[WEAPONS]; 63 int type[WEAPONS]; 60 64 61 65 } weapons; … … 65 69 int x, y; 66 70 int dir; 67 int weapon ;71 int weapon, nuke; 68 72 69 73 } player; … … 113 117 void draw_weapons( game *g, weapons *wp ); 114 118 void update_weapons( game *g, weapons *wp ); 115 void add_weapon( game *g, weapons *wp, int x, int y );119 void add_weapon( game *g, weapons *wp, int x, int y, int type ); 116 120 117 121 void init_starfield( game *g, starfield *s ); 
ttyvaders/trunk/explosions.c
r12 r16 1 1 2 2 #include <stdlib.h> 3 #include <math.h>4 3 5 4 #include "common.h" … … 7 6 static void draw_small_explosion( int x, int y, int frame ); 8 7 static void draw_big_explosion( int x, int y, int frame ); 9 static void draw_huge_explosion( int x, int y, int frame );10 8 11 9 void init_explosions( game *g, explosions *ex ) … … 86 84 switch( ex>type[i] ) 87 85 { 88 case 2:89 draw_huge_explosion( ex>x[i], ex>y[i], ex>n[i] );90 break;91 86 case 1: 92 87 draw_big_explosion( ex>x[i], ex>y[i], ex>n[i] ); … … 309 304 } 310 305 311 static void draw_circle( int x, int y, float r );312 313 static void draw_huge_explosion( int x, int y, int frame )314 {315 float r = 1.5 * (30  frame);316 317 GFX_COLOR( BLUE );318 draw_circle( x, y, r );319 320 r += 0.7;321 322 GFX_COLOR( CYAN );323 draw_circle( x, y, r );324 325 r += 0.7;326 327 GFX_COLOR( WHITE );328 draw_circle( x, y, r );329 }330 331 static void draw_circle( int x, int y, float r )332 {333 #if 1334 float c;335 336 for( c = 0 ; c <= 90 ; c += 1 )337 {338 float dx = 0.5 + r * 2.0 * sin( c * M_PI / 180.0 );339 float dy = 0.5 + r * cos( c * M_PI / 180.0 );340 341 GFX_GOTO( x + dx, y + dy );342 GFX_WRITE( '#' );343 GFX_GOTO( x  dx, y + dy );344 GFX_WRITE( '#' );345 GFX_GOTO( x + dx, y  dy );346 GFX_WRITE( '#' );347 GFX_GOTO( x  dx, y  dy );348 GFX_WRITE( '#' );349 }350 #endif351 352 #if 0353 int dx,dy,a2,b2, S, T;354 float a = r*8, b = r*2;355 356 a2 = a*a;357 b2 = b*b;358 dx = 0;359 dy = b;360 S = a2*(12*b) + 2*b2;361 T = b2  2*a2*(2*b1);362 GFX_GOTO( x + dx, y + dy );363 GFX_WRITE( '#' );364 GFX_GOTO( x  dx, y + dy );365 GFX_WRITE( '#' );366 GFX_GOTO( x + dx, y  dy );367 GFX_WRITE( '#' );368 GFX_GOTO( x  dx, y  dy );369 GFX_WRITE( '#' );370 371 do372 {373 if (S<0)374 {375 S += 2*b2*(2*x+3);376 T += 4*b2*(x+1);377 dx++;378 }379 else if (T<0)380 {381 S += 2*b2*(2*x+3)  4*a2*(dy1);382 T += 4*b2*(x+1)  2*a2*(2*dy3);383 dx++;384 dy;385 }386 else387 {388 S = 4*a2*(dy1);389 T = 2*a2*(2*dy3);390 dy;391 }392 GFX_GOTO( x + dx, y + dy );393 GFX_WRITE( '#' );394 GFX_GOTO( x  dx, y + dy );395 GFX_WRITE( '#' );396 GFX_GOTO( x + dx, y  dy );397 GFX_WRITE( '#' );398 GFX_GOTO( x  dx, y  dy );399 GFX_WRITE( '#' );400 }401 while (dy>0);402 #endif403 404 }405 
ttyvaders/trunk/main.c
r12 r16 99 99 break; 100 100 case 'j': 101 //if( p>y < g>h  2 ) p>y += 1;101 if( p>y < g>h  2 ) p>y += 1; 102 102 break; 103 103 case 'k': 104 //if( p>y > 1 ) p>y = 1;104 if( p>y > 1 ) p>y = 1; 105 105 break; 106 106 case 'l': … … 108 108 break; 109 109 case '\r': 110 add_explosion( g, ex, p>x + 2, p>y, 0, 0, 2 ); 110 if( p>nuke == 0 ) 111 { 112 p>nuke = 40; 113 add_weapon( g, wp, p>x + 2, p>y, 2 ); 114 } 111 115 break; 112 116 case ' ': … … 114 118 { 115 119 p>weapon = 4; 116 add_weapon( g, wp, p>x, p>y );117 add_weapon( g, wp, p>x + 5, p>y );120 add_weapon( g, wp, p>x, p>y, 1 ); 121 add_weapon( g, wp, p>x + 5, p>y, 1 ); 118 122 } 119 123 break; 
ttyvaders/trunk/player.c
r12 r16 13 13 p>dir = 0; 14 14 p>weapon = 0; 15 p>nuke = 0; 15 16 16 17 return p; … … 52 53 } 53 54 55 if( p>nuke ) 56 { 57 p>nuke; 58 } 59 54 60 if( p>dir < 0 ) 55 61 { 
ttyvaders/trunk/weapons.c
r12 r16 4 4 #include "common.h" 5 5 6 static void draw_nuke( int x, int y, int frame ); 7 static void draw_circle( int x, int y, int r ); 8 6 9 void init_weapons( game *g, weapons *wp ) 7 10 { 8 11 int i; 9 12 10 for( i = 0; i < SHOTS; i++ )13 for( i = 0; i < WEAPONS; i++ ) 11 14 { 12 15 wp>x[i] = 1; 13 16 wp>y[i] = 1; 14 17 wp>v[i] = 0; 18 wp>n[i] = 0; 19 wp>type[i] = 0; 15 20 } 16 21 } … … 20 25 int i; 21 26 22 for( i = 0; i < SHOTS; i++ )27 for( i = 0; i < WEAPONS; i++ ) 23 28 { 24 29 if( wp>x[i] >= 0 ) 25 30 { 26 GFX_COLOR( WHITE ); 27 GFX_GOTO( wp>x[i], wp>y[i] ); 28 GFX_WRITE( '' ); 29 GFX_COLOR( CYAN ); 30 GFX_GOTO( wp>x[i], wp>y[i] + 1 ); 31 GFX_WRITE( '' ); 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 } 32 46 } 33 47 } … … 38 52 int i; 39 53 40 for( i = 0; i < SHOTS; i++ )54 for( i = 0; i < WEAPONS; i++ ) 41 55 { 42 56 if( wp>y[i] < 0 ) … … 47 61 else 48 62 { 49 wp>y[i] += wp>v[i]; 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 } 50 77 51 78 /* Check collisions */ … … 54 81 } 55 82 56 void add_weapon( game *g, weapons *wp, int x, int y )83 void add_weapon( game *g, weapons *wp, int x, int y, int type ) 57 84 { 58 85 int i; 59 86 60 for( i = 0; i < SHOTS; i++ )87 for( i = 0; i < WEAPONS; i++ ) 61 88 { 62 89 if( wp>y[i] < 0 ) … … 64 91 wp>x[i] = x; 65 92 wp>y[i] = y; 93 wp>type[i] = type; 66 94 wp>v[i] = 2; 95 wp>n[i] = 30; 67 96 break; 68 97 } … … 70 99 } 71 100 101 static void draw_nuke( int x, int y, int frame ) 102 { 103 int r = (34  frame) * (34  frame) / 10; 104 105 /* 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 ) 116 { 117 int test, dx, dy; 118 119 /* Optimized Bresenham. Kick ass. */ 120 for( test = 0, dx = 0, dy = r ; dx <= dy ; dx++ ) 121 { 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, '#' ); 131 132 test += test > 0 ? dx  dy : dx; 133 } 134 } 135
Note: See TracChangeset
for help on using the changeset viewer.