Changeset 16 for ttyvaders/trunk/weapons.c
 Timestamp:
 Dec 13, 2002, 8:27:16 PM (18 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

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.