- Timestamp:
- Nov 9, 2003, 2:16:19 PM (16 years ago)
- Location:
- ttyvaders/trunk/src
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
ttyvaders/trunk/src/aliens.c
r80 r88 25 25 #include "common.h" 26 26 27 static void draw_alien_foo( game *g, int x, int y, int frame);28 static void draw_alien_bar( game *g, int x, int y, int frame);29 static void draw_alien_baz( game *g, int x, int y, int frame);30 31 void init_aliens( game *g, aliens *al)32 { 33 int i; 34 35 for( i = 0; i < ALIENS; i++)27 static void draw_alien_foo(game *, int, int, int); 28 static void draw_alien_bar(game *, int, int, int); 29 static void draw_alien_baz(game *, int, int, int); 30 31 void init_aliens(game *g, aliens *al) 32 { 33 int i; 34 35 for(i = 0; i < ALIENS; i++) 36 36 { 37 37 al->type[i] = ALIEN_NONE; … … 39 39 } 40 40 41 void draw_aliens( game *g, aliens *al)42 { 43 int i; 44 45 for( i = 0; i < ALIENS; i++)46 { 47 switch( al->type[i])41 void draw_aliens(game *g, aliens *al) 42 { 43 int i; 44 45 for(i = 0; i < ALIENS; i++) 46 { 47 switch(al->type[i]) 48 48 { 49 49 case ALIEN_FOO: 50 draw_alien_foo( g, al->x[i], al->y[i], al->img[i] % 8);50 draw_alien_foo(g, al->x[i], al->y[i], al->img[i] % 8); 51 51 break; 52 52 case ALIEN_BAR: 53 draw_alien_bar( g, al->x[i], al->y[i], al->img[i] % 2);53 draw_alien_bar(g, al->x[i], al->y[i], al->img[i] % 2); 54 54 break; 55 55 case ALIEN_BAZ: 56 draw_alien_baz( g, al->x[i], al->y[i], al->img[i] % 6);56 draw_alien_baz(g, al->x[i], al->y[i], al->img[i] % 6); 57 57 break; 58 58 case ALIEN_NONE: … … 62 62 } 63 63 64 void update_aliens( game *g, aliens *al)65 { 66 int i; 67 68 for( i = 0; i < ALIENS; i++)64 void update_aliens(game *g, aliens *al) 65 { 66 int i; 67 68 for(i = 0; i < ALIENS; i++) 69 69 { 70 70 /* If alien died, make it explode */ 71 if( al->type[i] != ALIEN_NONE && al->life[i] < 0)72 { 73 add_explosion( g, g->ex, al->x[i], al->y[i], 0, 0, EXPLOSION_MEDIUM);71 if(al->type[i] != ALIEN_NONE && al->life[i] < 0) 72 { 73 add_explosion(g, g->ex, al->x[i], al->y[i], 0, 0, EXPLOSION_MEDIUM); 74 74 al->type[i] = ALIEN_NONE; 75 add_bonus( g, g->bo, al->x[i], al->y[i], GET_RAND(0,5) ? BONUS_GREEN : BONUS_LIFE);75 add_bonus(g, g->bo, al->x[i], al->y[i], GET_RAND(0,5) ? BONUS_GREEN : BONUS_LIFE); 76 76 } 77 77 78 78 /* Update coordinates */ 79 switch( al->type[i])79 switch(al->type[i]) 80 80 { 81 81 case ALIEN_FOO: … … 87 87 88 88 /* Check bounds */ 89 if( 90 if( 89 if(al->y[i] < 0 ) al->y[i] = 0; 90 if(al->y[i] > g->w - 1 ) al->y[i] = g->w - 1; 91 91 break; 92 92 case ALIEN_NONE: … … 96 96 } 97 97 98 void add_alien( game *g, aliens *al, int x, int y, int type)99 { 100 int i; 101 102 for( i = 0; i < ALIENS; i++)103 { 104 if( al->type[i] == ALIEN_NONE)98 void add_alien(game *g, aliens *al, int x, int y, int type) 99 { 100 int i; 101 102 for(i = 0; i < ALIENS; i++) 103 { 104 if(al->type[i] == ALIEN_NONE) 105 105 { 106 106 al->type[i] = type; … … 109 109 al->img[i] = 0; 110 110 111 switch( al->type[i])111 switch(al->type[i]) 112 112 { 113 113 case ALIEN_FOO: … … 129 129 } 130 130 131 static void draw_alien_bar( game *g, int x, int y, int frame)132 { 133 switch( frame)131 static void draw_alien_bar(game *g, int x, int y, int frame) 132 { 133 switch(frame) 134 134 { 135 135 case 0: 136 ee_color( EE_MAGENTA);137 ee_goto( x, y);138 ee_putstr( ",---.");139 ee_goto( x, y+1);140 ee_putchar( '\\');141 ee_color( EE_WHITE);142 ee_putstr( "o O");143 ee_color( EE_MAGENTA);144 ee_putchar( '/');145 ee_goto( x, y+2);146 ee_putstr( "^^^^^");136 ee_color(EE_MAGENTA); 137 ee_goto(x, y); 138 ee_putstr(",---."); 139 ee_goto(x, y+1); 140 ee_putchar('\\'); 141 ee_color(EE_WHITE); 142 ee_putstr("o O"); 143 ee_color(EE_MAGENTA); 144 ee_putchar('/'); 145 ee_goto(x, y+2); 146 ee_putstr("^^^^^"); 147 147 break; 148 148 case 1: 149 ee_color( EE_MAGENTA);150 ee_goto( x, y);151 ee_putstr( ",---.");152 ee_goto( x, y+1);153 ee_putchar( '\\');154 ee_color( EE_WHITE);155 ee_putstr( "O o");156 ee_color( EE_MAGENTA);157 ee_putchar( '/');158 ee_goto( x, y+2);159 ee_putstr( "^^^^^");160 break; 161 } 162 } 163 164 static void draw_alien_baz( game *g, int x, int y, int frame)165 { 166 ee_color( EE_GREEN);167 ee_goto( x, y-1);168 ee_putstr( "__");169 170 ee_goto( x-1, y);171 ee_putchar( '/');172 ee_goto( x+2, y);173 ee_putchar( '\\');174 175 switch( frame)149 ee_color(EE_MAGENTA); 150 ee_goto(x, y); 151 ee_putstr(",---."); 152 ee_goto(x, y+1); 153 ee_putchar('\\'); 154 ee_color(EE_WHITE); 155 ee_putstr("O o"); 156 ee_color(EE_MAGENTA); 157 ee_putchar('/'); 158 ee_goto(x, y+2); 159 ee_putstr("^^^^^"); 160 break; 161 } 162 } 163 164 static void draw_alien_baz(game *g, int x, int y, int frame) 165 { 166 ee_color(EE_GREEN); 167 ee_goto(x, y-1); 168 ee_putstr("__"); 169 170 ee_goto(x-1, y); 171 ee_putchar('/'); 172 ee_goto(x+2, y); 173 ee_putchar('\\'); 174 175 switch(frame) 176 176 { 177 177 case 3: 178 ee_goto( x-2, y+1);179 ee_putstr( "//'`\\\\");178 ee_goto(x-2, y+1); 179 ee_putstr("//'`\\\\"); 180 180 break; 181 181 case 4: 182 182 case 2: 183 ee_goto( x-2, y+1);184 ee_putstr( "/(~~)\\");183 ee_goto(x-2, y+1); 184 ee_putstr("/(~~)\\"); 185 185 break; 186 186 case 5: 187 187 case 1: 188 ee_goto( x-2, y+1);189 ee_putstr( "((^^))");188 ee_goto(x-2, y+1); 189 ee_putstr("((^^))"); 190 190 break; 191 191 case 0: 192 ee_goto( x-1, y+1);193 ee_putstr( "\\\\//");194 break; 195 } 196 197 ee_color( EE_WHITE);198 ee_goto( x, y);199 ee_putstr( "oo");200 } 201 202 static void draw_alien_foo( game *g, int x, int y, int frame)203 { 204 ee_color( EE_YELLOW);205 206 switch( frame)192 ee_goto(x-1, y+1); 193 ee_putstr("\\\\//"); 194 break; 195 } 196 197 ee_color(EE_WHITE); 198 ee_goto(x, y); 199 ee_putstr("oo"); 200 } 201 202 static void draw_alien_foo(game *g, int x, int y, int frame) 203 { 204 ee_color(EE_YELLOW); 205 206 switch(frame) 207 207 { 208 208 case 0: 209 ee_goto( x, y);210 ee_putchar( '.');211 ee_goto( x+6, y);212 ee_putchar( ',');213 ee_goto( x+1, y+1);214 ee_putstr( "\\ X /");209 ee_goto(x, y); 210 ee_putchar('.'); 211 ee_goto(x+6, y); 212 ee_putchar(','); 213 ee_goto(x+1, y+1); 214 ee_putstr("\\ X /"); 215 215 break; 216 216 case 7: 217 217 case 1: 218 ee_goto( x-1, y);219 ee_putchar( '.');220 ee_goto( x+7, y);221 ee_putchar( ',');222 ee_goto( x, y+1);223 ee_putstr( "`- X -'");218 ee_goto(x-1, y); 219 ee_putchar('.'); 220 ee_goto(x+7, y); 221 ee_putchar(','); 222 ee_goto(x, y+1); 223 ee_putstr("`- X -'"); 224 224 break; 225 225 case 6: 226 226 case 2: 227 ee_goto( x-1, y+1);228 ee_putstr( "`-- X --'");227 ee_goto(x-1, y+1); 228 ee_putstr("`-- X --'"); 229 229 break; 230 230 case 5: 231 231 case 3: 232 ee_goto( x, y+1);233 ee_putstr( ",- X -.");234 ee_goto( x-1, y+2);235 ee_putchar( '\'');236 ee_goto( x+7, y+2);237 ee_putchar( '`');232 ee_goto(x, y+1); 233 ee_putstr(",- X -."); 234 ee_goto(x-1, y+2); 235 ee_putchar('\''); 236 ee_goto(x+7, y+2); 237 ee_putchar('`'); 238 238 break; 239 239 case 4: 240 ee_goto( x+1, y+1);241 ee_putstr( ", X .");242 ee_goto( x, y+2);243 ee_putchar( '/');244 ee_goto( x+6, y+2);245 ee_putchar( '\\');246 break; 247 } 248 249 ee_goto( x+2, y+2);250 ee_putstr( "`V'");251 252 ee_color( EE_WHITE);253 ee_goto( x+2, y+1);254 ee_putchar( 'o');255 ee_goto( x+4, y+1);256 ee_putchar( 'o');257 } 258 259 240 ee_goto(x+1, y+1); 241 ee_putstr(", X ."); 242 ee_goto(x, y+2); 243 ee_putchar('/'); 244 ee_goto(x+6, y+2); 245 ee_putchar('\\'); 246 break; 247 } 248 249 ee_goto(x+2, y+2); 250 ee_putstr("`V'"); 251 252 ee_color(EE_WHITE); 253 ee_goto(x+2, y+1); 254 ee_putchar('o'); 255 ee_goto(x+4, y+1); 256 ee_putchar('o'); 257 } 258 259 -
ttyvaders/trunk/src/bonus.c
r80 r88 25 25 #include "common.h" 26 26 27 void init_bonus( game *g, bonus *bo)27 void init_bonus(game *g, bonus *bo) 28 28 { 29 29 int i; 30 30 31 for( i = 0; i < BONUS; i++)31 for(i = 0; i < BONUS; i++) 32 32 { 33 33 bo->type[i] = BONUS_NONE; … … 35 35 } 36 36 37 void draw_bonus( game *g, bonus *bo)37 void draw_bonus(game *g, bonus *bo) 38 38 { 39 39 int i; 40 40 41 for( i = 0; i < BONUS; i++)41 for(i = 0; i < BONUS; i++) 42 42 { 43 switch( bo->type[i])43 switch(bo->type[i]) 44 44 { 45 45 case BONUS_GREEN: 46 ee_color( (bo->n[i]/2 % 3) ? EE_GREEN : EE_WHITE);47 ee_goto( bo->x[i]+1, bo->y[i]-1);48 ee_putchar( '_');49 ee_goto( bo->x[i], bo->y[i]);50 ee_putstr( "/ \\");51 ee_goto( bo->x[i], bo->y[i]+1);52 ee_putstr( "\\_/");53 ee_color( EE_WHITE);54 ee_goto( bo->x[i]+1, bo->y[i]);55 ee_putchar( 'g');46 ee_color((bo->n[i]/2 % 3) ? EE_GREEN : EE_WHITE); 47 ee_goto(bo->x[i]+1, bo->y[i]-1); 48 ee_putchar('_'); 49 ee_goto(bo->x[i], bo->y[i]); 50 ee_putstr("/ \\"); 51 ee_goto(bo->x[i], bo->y[i]+1); 52 ee_putstr("\\_/"); 53 ee_color(EE_WHITE); 54 ee_goto(bo->x[i]+1, bo->y[i]); 55 ee_putchar('g'); 56 56 break; 57 57 case BONUS_LIFE: 58 ee_color( (bo->n[i] % 3) ? EE_RED : EE_WHITE);59 ee_goto( bo->x[i]+1, bo->y[i]-1);60 ee_putchar( '_');61 ee_goto( bo->x[i]+3, bo->y[i]-1);62 ee_putchar( '_');63 ee_goto( bo->x[i], bo->y[i]);64 ee_putstr( "( ' )");65 ee_goto( bo->x[i]+1, bo->y[i]+1);66 ee_putstr( "`v'");67 ee_color( EE_WHITE);68 ee_goto( bo->x[i]+3, bo->y[i]);69 ee_putchar( '^');58 ee_color((bo->n[i] % 3) ? EE_RED : EE_WHITE); 59 ee_goto(bo->x[i]+1, bo->y[i]-1); 60 ee_putchar('_'); 61 ee_goto(bo->x[i]+3, bo->y[i]-1); 62 ee_putchar('_'); 63 ee_goto(bo->x[i], bo->y[i]); 64 ee_putstr("( ' )"); 65 ee_goto(bo->x[i]+1, bo->y[i]+1); 66 ee_putstr("`v'"); 67 ee_color(EE_WHITE); 68 ee_goto(bo->x[i]+3, bo->y[i]); 69 ee_putchar('^'); 70 70 break; 71 71 case BONUS_NONE: … … 75 75 } 76 76 77 void update_bonus( game *g, bonus *bo)77 void update_bonus(game *g, bonus *bo) 78 78 { 79 79 int i; 80 80 81 for( i = 0; i < BONUS; i++)81 for(i = 0; i < BONUS; i++) 82 82 { 83 switch( bo->type[i])83 switch(bo->type[i]) 84 84 { 85 85 case BONUS_GREEN: 86 86 bo->n[i]++; 87 87 bo->y[i]++; 88 if( bo->y[i] > g->h)88 if(bo->y[i] > g->h) 89 89 { 90 90 bo->type[i] = BONUS_NONE; … … 94 94 bo->n[i]++; 95 95 bo->y[i]++; 96 if( bo->y[i] > g->h)96 if(bo->y[i] > g->h) 97 97 { 98 98 bo->type[i] = BONUS_NONE; … … 105 105 } 106 106 107 void add_bonus( game *g, bonus *bo, int x, int y, int type)107 void add_bonus(game *g, bonus *bo, int x, int y, int type) 108 108 { 109 109 int i; 110 110 111 for( i = 0; i < BONUS; i++)111 for(i = 0; i < BONUS; i++) 112 112 { 113 if( bo->type[i] == BONUS_NONE)113 if(bo->type[i] == BONUS_NONE) 114 114 { 115 115 bo->type[i] = type; -
ttyvaders/trunk/src/box.c
r80 r88 25 25 #include "common.h" 26 26 27 box * create_box( game *g, int x, int y, int w, int h)27 box * create_box(game *g, int x, int y, int w, int h) 28 28 { 29 box *b = malloc( sizeof( box ));29 box *b = malloc(sizeof( box )); 30 30 31 31 b->x = x; … … 38 38 } 39 39 40 void draw_box( game *g, box *b)40 void draw_box(game *g, box *b) 41 41 { 42 42 int i, j, frame; 43 43 44 ee_color( EE_YELLOW);44 ee_color(EE_YELLOW); 45 45 46 46 /* Draw the thin horizontal line */ 47 if( b->frame < 8)47 if(b->frame < 8) 48 48 { 49 for( 49 for(i = b->x - b->w * b->frame / 16 ; 50 50 i < b->x + b->w * b->frame / 16 ; 51 i++ 51 i++) 52 52 { 53 ee_goto( i, b->y);54 ee_putchar( 'X');53 ee_goto(i, b->y); 54 ee_putchar('X'); 55 55 } 56 56 … … 61 61 frame = b->frame < 12 ? b->frame : 12; 62 62 63 for( 63 for(i = b->x - b->w / 2 ; 64 64 i < b->x + b->w / 2 ; 65 i++ 65 i++) 66 66 { 67 ee_goto( i, b->y - b->h * (frame - 8) / 8);68 ee_putchar( 'X');69 ee_goto( i, b->y + b->h * (frame - 8) / 8);70 ee_putchar( 'X');67 ee_goto(i, b->y - b->h * (frame - 8) / 8); 68 ee_putchar('X'); 69 ee_goto(i, b->y + b->h * (frame - 8) / 8); 70 ee_putchar('X'); 71 71 } 72 72 73 for( 73 for(j = b->y - b->h * (frame - 8) / 8 ; 74 74 j < b->y + b->h * (frame - 8) / 8 ; 75 j++ 75 j++) 76 76 { 77 ee_goto( b->x - b->w / 2, j);78 ee_putchar( 'X');79 ee_goto( b->x + b->w / 2 - 1, j);80 ee_putchar( 'X');77 ee_goto(b->x - b->w / 2, j); 78 ee_putchar('X'); 79 ee_goto(b->x + b->w / 2 - 1, j); 80 ee_putchar('X'); 81 81 } 82 82 83 ee_color( EE_BLACK);83 ee_color(EE_BLACK); 84 84 85 for( 85 for(j = b->y - b->h * (frame - 8) / 8 + 1 ; 86 86 j < b->y + b->h * (frame - 8) / 8 ; 87 j++ 87 j++) 88 88 { 89 for( 89 for(i = b->x - b->w / 2 + 1 ; 90 90 i < b->x + b->w / 2 - 1 ; 91 i++ 91 i++) 92 92 { 93 ee_goto( i, j);94 ee_putchar( 'X');93 ee_goto(i, j); 94 ee_putchar('X'); 95 95 } 96 96 } 97 97 98 if( b->frame < 12)98 if(b->frame < 12) 99 99 { 100 100 return; … … 102 102 103 103 /* Draw the text inside the frame */ 104 ee_color( EE_YELLOW);104 ee_color(EE_YELLOW); 105 105 106 106 /* FIXME: use a font */ 107 ee_goto( b->x - b->w / 2 + 12, b->y - b->h / 2 + 2);108 ee_putstr( "XXXX. .XXXX X X .XXXX .XXXX XXXX.");109 ee_goto( b->x - b->w / 2 + 12, b->y - b->h / 2 + 3);110 ee_putstr( "X `X X' X X X X' X' X `X");111 ee_goto( b->x - b->w / 2 + 12, b->y - b->h / 2 + 4);112 ee_putstr( "XXXX' XXXXX X X `XXX XXXX X X");113 ee_goto( b->x - b->w / 2 + 12, b->y - b->h / 2 + 5);114 ee_putstr( "X' X' `X X. ,X `X X' X ,X");115 ee_goto( b->x - b->w / 2 + 12, b->y - b->h / 2 + 6);116 ee_putstr( "X X X `XXXX XXXX' `XXXX XXXX'");107 ee_goto(b->x - b->w / 2 + 12, b->y - b->h / 2 + 2); 108 ee_putstr("XXXX. .XXXX X X .XXXX .XXXX XXXX."); 109 ee_goto(b->x - b->w / 2 + 12, b->y - b->h / 2 + 3); 110 ee_putstr("X `X X' X X X X' X' X `X"); 111 ee_goto(b->x - b->w / 2 + 12, b->y - b->h / 2 + 4); 112 ee_putstr("XXXX' XXXXX X X `XXX XXXX X X"); 113 ee_goto(b->x - b->w / 2 + 12, b->y - b->h / 2 + 5); 114 ee_putstr("X' X' `X X. ,X `X X' X ,X"); 115 ee_goto(b->x - b->w / 2 + 12, b->y - b->h / 2 + 6); 116 ee_putstr("X X X `XXXX XXXX' `XXXX XXXX'"); 117 117 } 118 118 119 void free_box( box *b)119 void free_box(box *b) 120 120 { 121 free( b);121 free(b); 122 122 } 123 123 -
ttyvaders/trunk/src/ceo.c
r80 r88 28 28 #include "common.h" 29 29 30 void ceo_alert( game *g)30 void ceo_alert(game *g) 31 31 { 32 32 int end = 0; 33 33 34 while( !end)34 while(!end) 35 35 { 36 36 ee_clear(); 37 37 38 if( ee_get_key() == '\t')38 if(ee_get_key() == '\t') 39 39 { 40 40 end = 1; 41 41 } 42 42 43 fprintf( stderr, "foo\n");43 fprintf(stderr, "foo\n"); 44 44 45 45 ee_refresh(); 46 46 47 usleep( 40000);47 usleep(40000); 48 48 } 49 49 } -
ttyvaders/trunk/src/collide.c
r72 r88 4 4 * All Rights Reserved 5 5 * 6 * $Id : collide.c,v 1.11 2003/01/06 12:22:58 sam Exp$6 * $Id$ 7 7 * 8 8 * This program is free software; you can redistribute it and/or modify … … 25 25 #include "common.h" 26 26 27 void collide_weapons_tunnel( game *g, weapons *wp, tunnel *t, explosions *ex)27 void collide_weapons_tunnel(game *g, weapons *wp, tunnel *t, explosions *ex) 28 28 { 29 29 int i, j, x, y; 30 30 31 for( i = 0; i < WEAPONS; i++)31 for(i = 0; i < WEAPONS; i++) 32 32 { 33 33 x = wp->x[i] >> 4; 34 34 y = wp->y[i] >> 4; 35 35 36 switch( wp->type[i])36 switch(wp->type[i]) 37 37 { 38 38 case WEAPON_LIGHTNING: … … 42 42 case WEAPON_BOMB: 43 43 case WEAPON_FRAGBOMB: 44 if( y < 0 || y >= g->h)44 if(y < 0 || y >= g->h) 45 45 { 46 46 break; 47 47 } 48 48 49 if( 50 || x >= t->right[y] 49 if(x <= t->left[y] 50 || x >= t->right[y]) 51 51 { 52 52 int damage = wp->type[i] == WEAPON_SEEKER ? 1 : 2; 53 53 54 add_explosion( g, ex, x, y, 0, 1, wp->type[i] == WEAPON_SEEKER ? EXPLOSION_SMALL : EXPLOSION_MEDIUM);55 56 if( x <= t->left[y])57 { 58 if( y-2 >= 0) t->left[y-2] -= damage - 1;59 if( y-1 >= 0) t->left[y-1] -= damage;54 add_explosion(g, ex, x, y, 0, 1, wp->type[i] == WEAPON_SEEKER ? EXPLOSION_SMALL : EXPLOSION_MEDIUM); 55 56 if(x <= t->left[y]) 57 { 58 if(y-2 >= 0) t->left[y-2] -= damage - 1; 59 if(y-1 >= 0) t->left[y-1] -= damage; 60 60 t->left[y] -= damage + 1; 61 if( y+1 < g->h) t->left[y+1] -= damage;62 if( y+2 < g->h) t->left[y+2] -= damage - 1;61 if(y+1 < g->h) t->left[y+1] -= damage; 62 if(y+2 < g->h) t->left[y+2] -= damage - 1; 63 63 } 64 64 else 65 65 { 66 if( y-2 >= 0) t->right[y-2] += damage - 1;67 if( y-1 >= 0) t->right[y-1] += damage;66 if(y-2 >= 0) t->right[y-2] += damage - 1; 67 if(y-1 >= 0) t->right[y-1] += damage; 68 68 t->right[y] += damage + 1; 69 if( y+1 < g->h) t->right[y+1] += damage;70 if( y+2 < g->h) t->right[y+2] += damage - 1;71 } 72 73 if( wp->type[i] == WEAPON_FRAGBOMB)69 if(y+1 < g->h) t->right[y+1] += damage; 70 if(y+2 < g->h) t->right[y+2] += damage - 1; 71 } 72 73 if(wp->type[i] == WEAPON_FRAGBOMB) 74 74 { 75 75 wp->n[i] = -1; … … 82 82 break; 83 83 case WEAPON_LASER: 84 for( j = GET_MIN( 0, wp->vy[i] >> 4 );85 j < GET_MAX( 0, wp->vy[i] >> 4 );86 j++ 87 { 88 if( y+j >= g->h || y+j < 0)89 { 90 continue; 91 } 92 93 if( x <= t->left[y+j] || x >= t->right[y+j])94 { 95 add_explosion( g, ex, x, y+j, 0, 1, EXPLOSION_SMALL);84 for(j = GET_MIN(0, wp->vy[i] >> 4); 85 j < GET_MAX(0, wp->vy[i] >> 4); 86 j++) 87 { 88 if(y+j >= g->h || y+j < 0) 89 { 90 continue; 91 } 92 93 if(x <= t->left[y+j] || x >= t->right[y+j]) 94 { 95 add_explosion(g, ex, x, y+j, 0, 1, EXPLOSION_SMALL); 96 96 wp->type[i] = WEAPON_NONE; 97 97 98 if( x <= t->left[y+j])98 if(x <= t->left[y+j]) 99 99 { 100 if( y+j-1 >= 0) t->left[y+j-1]--;100 if(y+j-1 >= 0) t->left[y+j-1]--; 101 101 t->left[y+j] -= 2; 102 if( y+j+1 < g->h) t->left[y+j+1]--;102 if(y+j+1 < g->h) t->left[y+j+1]--; 103 103 } 104 104 else 105 105 { 106 if( y+j-1 >= 0) t->right[y+j-1]++;106 if(y+j-1 >= 0) t->right[y+j-1]++; 107 107 t->right[y+j] += 2; 108 if( y+j+1 < g->h) t->right[y+j+1]++;108 if(y+j+1 < g->h) t->right[y+j+1]++; 109 109 } 110 110 break; … … 113 113 break; 114 114 case WEAPON_BEAM: 115 if( wp->n[i] > 19)115 if(wp->n[i] > 19) 116 116 { 117 117 break; … … 119 119 120 120 j = (29 - wp->n[i]) * (29 - wp->n[i]) / 8; 121 j = GET_MIN( y, j);122 123 for( ; j > 0 ; j--)124 { 125 if( x - 2 <= t->left[y-j])126 { 127 add_explosion( g, ex, GET_MIN(t->left[y-j], x+3), y-j, 0, 1, EXPLOSION_SMALL);121 j = GET_MIN(y, j); 122 123 for(; j > 0; j--) 124 { 125 if(x - 2 <= t->left[y-j]) 126 { 127 add_explosion(g, ex, GET_MIN(t->left[y-j], x+3), y-j, 0, 1, EXPLOSION_SMALL); 128 128 t->left[y-j] -= GET_RAND(0,3); 129 129 } 130 else if( x + 3 >= t->right[y-j])131 { 132 add_explosion( g, ex, GET_MAX(t->right[y-j], x-2), y-j, 0, 1, EXPLOSION_SMALL);130 else if(x + 3 >= t->right[y-j]) 131 { 132 add_explosion(g, ex, GET_MAX(t->right[y-j], x-2), y-j, 0, 1, EXPLOSION_SMALL); 133 133 t->right[y-j] += GET_RAND(0,3); 134 134 } … … 143 143 } 144 144 145 void collide_weapons_aliens( game *g, weapons *wp, aliens *al, explosions *ex)145 void collide_weapons_aliens(game *g, weapons *wp, aliens *al, explosions *ex) 146 146 { 147 147 int i, j, k, x, y; 148 148 149 for( i = 0; i < WEAPONS; i++)149 for(i = 0; i < WEAPONS; i++) 150 150 { 151 151 int ok = 0; … … 155 155 y = wp->y[i] >> 4; 156 156 157 switch( wp->type[i])157 switch(wp->type[i]) 158 158 { 159 159 case WEAPON_LIGHTNING: … … 164 164 r = (29 - wp->n[i]) * (29 - wp->n[i]) / 8; 165 165 166 for( j = 0; j < ALIENS; j++)167 { 168 if( al->type[j] == ALIEN_NONE || al->life[j] < 0)169 { 170 continue; 171 } 172 173 if( 166 for(j = 0; j < ALIENS; j++) 167 { 168 if(al->type[j] == ALIEN_NONE || al->life[j] < 0) 169 { 170 continue; 171 } 172 173 if(wp->n[i] == 0 /* Nuke destroys _everything_ */ || 174 174 (al->x[j] - x) * (al->x[j] - x) 175 175 + 4 * (al->y[j] - y) * (al->y[j] - y) 176 <= r * r 176 <= r * r) 177 177 { 178 178 /* Kill alien, not nuke */ … … 183 183 184 184 case WEAPON_BEAM: 185 if( wp->n[i] > 19)185 if(wp->n[i] > 19) 186 186 { 187 187 break; … … 190 190 r = (29 - wp->n[i]) * (29 - wp->n[i]) / 8; 191 191 192 for( j = 0; j < ALIENS; j++)193 { 194 if( al->type[j] == ALIEN_NONE || al->life[j] < 0)195 { 196 continue; 197 } 198 199 if( 200 && y >= al->y[j] + 2 && y-5-r <= al->y[j] 192 for(j = 0; j < ALIENS; j++) 193 { 194 if(al->type[j] == ALIEN_NONE || al->life[j] < 0) 195 { 196 continue; 197 } 198 199 if(x >= al->x[j] && x <= al->x[j] + 4 200 && y >= al->y[j] + 2 && y-5-r <= al->y[j]) 201 201 { 202 202 al->life[j] -= 4; … … 206 206 207 207 case WEAPON_LASER: 208 for( j = 0; j < ALIENS; j++)209 { 210 if( al->type[j] == ALIEN_NONE || al->life[j] < 0)211 { 212 continue; 213 } 214 215 for( k = GET_MIN( 0, wp->vy[i] >> 4 );216 k < GET_MAX( 0, wp->vy[i] >> 4 );217 k++ 218 { 219 if( 220 && y+k >= al->y[j] && y+k <= al->y[j] + 2 208 for(j = 0; j < ALIENS; j++) 209 { 210 if(al->type[j] == ALIEN_NONE || al->life[j] < 0) 211 { 212 continue; 213 } 214 215 for(k = GET_MIN(0, wp->vy[i] >> 4); 216 k < GET_MAX(0, wp->vy[i] >> 4); 217 k++) 218 { 219 if(x >= al->x[j] && x <= al->x[j] + 4 220 && y+k >= al->y[j] && y+k <= al->y[j] + 2) 221 221 { 222 222 al->life[j]--; … … 227 227 } 228 228 229 if( ok)230 { 231 add_explosion( g, ex, x, y+1, 0, 0, EXPLOSION_SMALL);229 if(ok) 230 { 231 add_explosion(g, ex, x, y+1, 0, 0, EXPLOSION_SMALL); 232 232 wp->type[i] = WEAPON_NONE; 233 233 } … … 237 237 case WEAPON_BOMB: 238 238 case WEAPON_FRAGBOMB: 239 for( j = 0; j < ALIENS; j++)240 { 241 if( al->type[j] == ALIEN_NONE || al->life[j] < 0)242 { 243 continue; 244 } 245 246 if( 247 && y >= al->y[j] && y <= al->y[j] + 2 239 for(j = 0; j < ALIENS; j++) 240 { 241 if(al->type[j] == ALIEN_NONE || al->life[j] < 0) 242 { 243 continue; 244 } 245 246 if(x >= al->x[j] && x <= al->x[j] + 4 247 && y >= al->y[j] && y <= al->y[j] + 2) 248 248 { 249 249 al->life[j] -= wp->type[i] == WEAPON_SEEKER ? 1 : 5; … … 252 252 } 253 253 254 if( ok)255 { 256 add_explosion( g, ex, x, y+1, 0, 0, wp->type[i] == WEAPON_SEEKER ? EXPLOSION_SMALL : EXPLOSION_MEDIUM);257 258 if( wp->type[i] == WEAPON_FRAGBOMB)254 if(ok) 255 { 256 add_explosion(g, ex, x, y+1, 0, 0, wp->type[i] == WEAPON_SEEKER ? EXPLOSION_SMALL : EXPLOSION_MEDIUM); 257 258 if(wp->type[i] == WEAPON_FRAGBOMB) 259 259 { 260 260 wp->n[i] = -1; … … 270 270 } 271 271 272 void collide_player_tunnel( game *g, player *p, tunnel *t, explosions *ex)272 void collide_player_tunnel(game *g, player *p, tunnel *t, explosions *ex) 273 273 { 274 if( p->dead)274 if(p->dead) 275 275 { 276 276 return; 277 277 } 278 278 279 if( p->x <= t->left[p->y])279 if(p->x <= t->left[p->y]) 280 280 { 281 281 p->x += 3; 282 282 p->vx = 2; 283 add_explosion( g, ex, p->x+1, p->y-1, 0, 0, EXPLOSION_SMALL);283 add_explosion(g, ex, p->x+1, p->y-1, 0, 0, EXPLOSION_SMALL); 284 284 p->life -= 180; 285 285 } 286 else if( p->x + 5 >= t->right[p->y])286 else if(p->x + 5 >= t->right[p->y]) 287 287 { 288 288 p->x -= 3; 289 289 p->vx = -2; 290 add_explosion( g, ex, p->x+4, p->y-1, 0, 0, EXPLOSION_SMALL);290 add_explosion(g, ex, p->x+4, p->y-1, 0, 0, EXPLOSION_SMALL); 291 291 p->life -= 180; 292 292 } -
ttyvaders/trunk/src/common.h
r80 r88 147 147 * From aliens.c 148 148 */ 149 void init_aliens( game *g, aliens *al);150 void draw_aliens( game *g, aliens *al);151 void update_aliens( game *g, aliens *al);152 void add_alien( game *g, aliens *al, int x, int y, int type);149 void init_aliens(game *, aliens *); 150 void draw_aliens(game *, aliens *); 151 void update_aliens(game *, aliens *); 152 void add_alien(game *, aliens *, int, int, int); 153 153 154 154 /* 155 155 * From bonus.c 156 156 */ 157 void init_bonus( game *g, bonus *bo);158 void draw_bonus( game *g, bonus *bo);159 void update_bonus( game *g, bonus *bo);160 void add_bonus( game *g, bonus *bo, int x, int y, int type);157 void init_bonus(game *, bonus *); 158 void draw_bonus(game *, bonus *); 159 void update_bonus(game *, bonus *); 160 void add_bonus(game *, bonus *, int, int, int); 161 161 162 162 /* 163 163 * From box.c 164 164 */ 165 box * create_box( game *g, int x, int y, int w, int h);166 void draw_box( game *g, box *b);167 void free_box( box *b);165 box * create_box(game *, int, int, int, int); 166 void draw_box(game *, box *); 167 void free_box(box *); 168 168 169 169 /* 170 170 * From ceo.c 171 171 */ 172 void ceo_alert( game *g);172 void ceo_alert(game *); 173 173 174 174 /* 175 175 * From collide.c 176 176 */ 177 void collide_weapons_tunnel( game *g, weapons *wp, tunnel *t, explosions *ex);178 void collide_weapons_aliens( game *g, weapons *wp, aliens *al, explosions *ex);179 void collide_player_tunnel( game *g, player *p, tunnel *t, explosions *ex);177 void collide_weapons_tunnel(game *, weapons *, tunnel *, explosions *); 178 void collide_weapons_aliens(game *, weapons *, aliens *, explosions *); 179 void collide_player_tunnel(game *, player *, tunnel *, explosions *); 180 180 181 181 /* 182 182 * From explosions.c 183 183 */ 184 void init_explosions( game *g, explosions *ex);185 void add_explosion( game *g, explosions *ex, int x, int y, int vx, int vy, int type);186 void draw_explosions( game *g, explosions *ex);187 void update_explosions( game *g, explosions *ex);184 void init_explosions(game *, explosions *); 185 void add_explosion(game *, explosions *, int, int, int, int, int); 186 void draw_explosions(game *, explosions *); 187 void update_explosions(game *, explosions *); 188 188 189 189 /* 190 190 * From math.c 191 191 */ 192 int r00t( int a);192 int r00t(int); 193 193 194 194 /* 195 195 * From overlay.c 196 196 */ 197 void draw_status( game *g);197 void draw_status(game *); 198 198 199 199 /* 200 200 * From player.c 201 201 */ 202 player * create_player( game *g);203 void free_player( player *p);204 void draw_player( game *g, player *p);205 void update_player( game *g, player *p);202 player * create_player(game *); 203 void free_player(player *); 204 void draw_player(game *, player *); 205 void update_player(game *, player *); 206 206 207 207 /* 208 208 * From starfield.c 209 209 */ 210 starfield * create_starfield( game *g);211 void draw_starfield( game *g, starfield *s);212 void update_starfield( game *g, starfield *s);213 void free_starfield( game *g, starfield *s);210 starfield * create_starfield(game *); 211 void draw_starfield(game *, starfield *); 212 void update_starfield(game *, starfield *); 213 void free_starfield(game *, starfield *); 214 214 215 215 /* 216 216 * From tunnel.c 217 217 */ 218 tunnel * create_tunnel( game *g, int w, int h);219 void free_tunnel( tunnel *t);220 void draw_tunnel( game *g, tunnel *t);221 void update_tunnel( game *g, tunnel *t);218 tunnel * create_tunnel(game *, int, int); 219 void free_tunnel(tunnel *); 220 void draw_tunnel(game *, tunnel *); 221 void update_tunnel(game *, tunnel *); 222 222 223 223 /* 224 224 * From weapons.c 225 225 */ 226 void init_weapons( game *g, weapons *wp);227 void draw_weapons( game *g, weapons *wp);228 void update_weapons( game *g, weapons *wp);229 void add_weapon( game *g, weapons *wp, int x, int y, int vx, int vy, int type);230 226 void init_weapons(game *, weapons *); 227 void draw_weapons(game *, weapons *); 228 void update_weapons(game *, weapons *); 229 void add_weapon(game *, weapons *, int, int, int, int, int); 230 -
ttyvaders/trunk/src/explosions.c
r80 r88 25 25 #include "common.h" 26 26 27 static void draw_small_explosion( int x, int y, int frame);28 static void draw_medium_explosion( int x, int y, int frame);29 30 void init_explosions( game *g, explosions *ex)31 { 32 int i; 33 34 for( i = 0; i < EXPLOSIONS; i++)27 static void draw_small_explosion(int x, int y, int frame); 28 static void draw_medium_explosion(int x, int y, int frame); 29 30 void init_explosions(game *g, explosions *ex) 31 { 32 int i; 33 34 for(i = 0; i < EXPLOSIONS; i++) 35 35 { 36 36 ex->type[i] = EXPLOSION_NONE; … … 38 38 } 39 39 40 void add_explosion( game *g, explosions *ex, int x, int y, int vx, int vy, int type)41 { 42 int i; 43 44 for( i = 0; i < EXPLOSIONS; i++)45 { 46 if( ex->type[i] == EXPLOSION_NONE)40 void add_explosion(game *g, explosions *ex, int x, int y, int vx, int vy, int type) 41 { 42 int i; 43 44 for(i = 0; i < EXPLOSIONS; i++) 45 { 46 if(ex->type[i] == EXPLOSION_NONE) 47 47 { 48 48 ex->type[i] = type; … … 51 51 ex->vx[i] = vx; 52 52 ex->vy[i] = vy; 53 switch( type)53 switch(type) 54 54 { 55 55 case EXPLOSION_MEDIUM: … … 65 65 } 66 66 67 void draw_explosions( game *g, explosions *ex)68 { 69 int i; 70 71 for( i = 0; i < EXPLOSIONS; i++)67 void draw_explosions(game *g, explosions *ex) 68 { 69 int i; 70 71 for(i = 0; i < EXPLOSIONS; i++) 72 72 { 73 73 #if 0 74 ee_color( GREEN);75 ee_goto( ex->x[i] + 3, ex->y[i]);76 switch( GET_RAND(0,3))74 ee_color(GREEN); 75 ee_goto(ex->x[i] + 3, ex->y[i]); 76 switch(GET_RAND(0,3)) 77 77 { 78 78 case 0: 79 ee_putchar( 'p');80 ee_putchar( 'i');81 ee_putchar( 'f');79 ee_putchar('p'); 80 ee_putchar('i'); 81 ee_putchar('f'); 82 82 break; 83 83 case 1: 84 ee_putchar( 'p');85 ee_putchar( 'a');86 ee_putchar( 'f');84 ee_putchar('p'); 85 ee_putchar('a'); 86 ee_putchar('f'); 87 87 break; 88 88 case 2: 89 ee_putchar( 'p');90 ee_putchar( 'o');91 ee_putchar( 'u');92 ee_putchar( 'f');93 break; 94 } 95 ee_putchar( '!');89 ee_putchar('p'); 90 ee_putchar('o'); 91 ee_putchar('u'); 92 ee_putchar('f'); 93 break; 94 } 95 ee_putchar('!'); 96 96 #endif 97 97 98 switch( ex->type[i])98 switch(ex->type[i]) 99 99 { 100 100 case EXPLOSION_MEDIUM: 101 draw_medium_explosion( ex->x[i], ex->y[i], ex->n[i]);101 draw_medium_explosion(ex->x[i], ex->y[i], ex->n[i]); 102 102 break; 103 103 case EXPLOSION_SMALL: 104 draw_small_explosion( ex->x[i], ex->y[i], ex->n[i]);104 draw_small_explosion(ex->x[i], ex->y[i], ex->n[i]); 105 105 break; 106 106 case EXPLOSION_NONE: … … 110 110 } 111 111 112 void update_explosions( game *g, explosions *ex)113 { 114 int i; 115 116 for( i = 0; i < EXPLOSIONS; i++)117 { 118 switch( ex->type[i])112 void update_explosions(game *g, explosions *ex) 113 { 114 int i; 115 116 for(i = 0; i < EXPLOSIONS; i++) 117 { 118 switch(ex->type[i]) 119 119 { 120 120 case EXPLOSION_MEDIUM: … … 123 123 ex->y[i] += ex->vy[i]; 124 124 ex->n[i]--; 125 if( ex->n[i] < 0)125 if(ex->n[i] < 0) 126 126 { 127 127 ex->type[i] = EXPLOSION_NONE; … … 134 134 } 135 135 136 static void draw_small_explosion( int x, int y, int frame)137 { 138 switch( frame)136 static void draw_small_explosion(int x, int y, int frame) 137 { 138 switch(frame) 139 139 { 140 140 case 6: 141 ee_color( EE_YELLOW);142 ee_goto( x, y);143 ee_putchar( '+');141 ee_color(EE_YELLOW); 142 ee_goto(x, y); 143 ee_putchar('+'); 144 144 break; 145 145 case 5: 146 ee_color( EE_YELLOW);147 ee_goto( x, y);148 ee_putchar( 'o');146 ee_color(EE_YELLOW); 147 ee_goto(x, y); 148 ee_putchar('o'); 149 149 break; 150 150 case 4: 151 ee_color( EE_YELLOW);152 ee_goto( x, y-1);153 ee_putchar( '_');154 ee_goto( x-1, y);155 ee_putstr( ")_(");151 ee_color(EE_YELLOW); 152 ee_goto(x, y-1); 153 ee_putchar('_'); 154 ee_goto(x-1, y); 155 ee_putstr(")_("); 156 156 break; 157 157 case 3: 158 ee_color( EE_YELLOW);159 ee_goto( x-1, y-1);160 ee_putstr( "._,");161 ee_goto( x-1, y);162 ee_putstr( ")_(");163 ee_goto( x-1, y+1);164 ee_putstr( "\' `");158 ee_color(EE_YELLOW); 159 ee_goto(x-1, y-1); 160 ee_putstr("._,"); 161 ee_goto(x-1, y); 162 ee_putstr(")_("); 163 ee_goto(x-1, y+1); 164 ee_putstr("\' `"); 165 165 break; 166 166 case 2: 167 ee_color( EE_YELLOW);168 ee_goto( x-1, y-1);169 ee_putstr( ".v,");170 ee_goto( x-1, y);171 ee_putstr( "> <");172 ee_goto( x-1, y+1);173 ee_putstr( "\'^`");167 ee_color(EE_YELLOW); 168 ee_goto(x-1, y-1); 169 ee_putstr(".v,"); 170 ee_goto(x-1, y); 171 ee_putstr("> <"); 172 ee_goto(x-1, y+1); 173 ee_putstr("\'^`"); 174 174 break; 175 175 case 1: 176 ee_color( EE_WHITE);177 ee_goto( x-1, y-1);178 ee_putstr( ". ,");179 ee_goto( x-1, y);180 ee_putstr( " ");181 ee_goto( x-1, y+1);182 ee_putstr( "\' `");183 break; 184 } 185 } 186 187 static void draw_medium_explosion( int x, int y, int frame)188 { 189 ee_color( EE_YELLOW);190 191 switch( frame)176 ee_color(EE_WHITE); 177 ee_goto(x-1, y-1); 178 ee_putstr(". ,"); 179 ee_goto(x-1, y); 180 ee_putstr(" "); 181 ee_goto(x-1, y+1); 182 ee_putstr("\' `"); 183 break; 184 } 185 } 186 187 static void draw_medium_explosion(int x, int y, int frame) 188 { 189 ee_color(EE_YELLOW); 190 191 switch(frame) 192 192 { 193 193 case 10: 194 ee_goto( x, y);195 ee_putchar( '+');194 ee_goto(x, y); 195 ee_putchar('+'); 196 196 break; 197 197 case 9: 198 ee_goto( x, y);199 ee_putchar( 'o');198 ee_goto(x, y); 199 ee_putchar('o'); 200 200 break; 201 201 case 8: 202 ee_goto( x, y-1);203 ee_putchar( '_');204 ee_goto( x-1, y);205 ee_putstr( ")_(");202 ee_goto(x, y-1); 203 ee_putchar('_'); 204 ee_goto(x-1, y); 205 ee_putstr(")_("); 206 206 break; 207 207 case 7: 208 ee_goto( x-1, y-1);209 ee_putstr( "._,");210 ee_goto( x-1, y);211 ee_putstr( ")_(");212 ee_goto( x-1, y+1);213 ee_putstr( "\' `");208 ee_goto(x-1, y-1); 209 ee_putstr("._,"); 210 ee_goto(x-1, y); 211 ee_putstr(")_("); 212 ee_goto(x-1, y+1); 213 ee_putstr("\' `"); 214 214 break; 215 215 case 6: 216 ee_goto( x-1, y-1);217 ee_putstr( ".v,");218 ee_goto( x-1, y);219 ee_putstr( "> <");220 ee_goto( x-1, y+1);221 ee_putstr( "\'^`");216 ee_goto(x-1, y-1); 217 ee_putstr(".v,"); 218 ee_goto(x-1, y); 219 ee_putstr("> <"); 220 ee_goto(x-1, y+1); 221 ee_putstr("\'^`"); 222 222 break; 223 223 case 5: 224 ee_color( EE_RED);224 ee_color(EE_RED); 225 225 case 4: 226 ee_goto( x-2, y-1);227 ee_putstr( "_\\~/_");228 ee_goto( x-2, y);229 ee_putstr( "> <");230 ee_goto( x-2, y+1);231 ee_putstr( "~/_\\~");226 ee_goto(x-2, y-1); 227 ee_putstr("_\\~/_"); 228 ee_goto(x-2, y); 229 ee_putstr("> <"); 230 ee_goto(x-2, y+1); 231 ee_putstr("~/_\\~"); 232 232 break; 233 233 case 3: 234 ee_color( EE_RED);234 ee_color(EE_RED); 235 235 case 2: 236 ee_goto( x-2, y-1);237 ee_putstr( "_\\ /_");238 ee_goto( x-2, y);239 ee_putstr( "_ _");240 ee_goto( x-2, y+1);241 ee_putstr( " / \\ ");236 ee_goto(x-2, y-1); 237 ee_putstr("_\\ /_"); 238 ee_goto(x-2, y); 239 ee_putstr("_ _"); 240 ee_goto(x-2, y+1); 241 ee_putstr(" / \\ "); 242 242 break; 243 243 case 1: 244 ee_color( EE_WHITE);245 ee_goto( x-2, y-1);246 ee_putstr( ". \' ,");247 ee_goto( x-2, y);248 ee_putstr( " ");249 ee_goto( x-2, y+1);250 ee_putstr( "\' . `");251 break; 252 } 253 } 254 244 ee_color(EE_WHITE); 245 ee_goto(x-2, y-1); 246 ee_putstr(". \' ,"); 247 ee_goto(x-2, y); 248 ee_putstr(" "); 249 ee_goto(x-2, y+1); 250 ee_putstr("\' . `"); 251 break; 252 } 253 } 254 -
ttyvaders/trunk/src/main.c
r80 r88 38 38 srand(time(NULL)); 39 39 40 if( ee_init())40 if(ee_init()) 41 41 { 42 42 return 1; … … 65 65 box *pausebox = NULL; 66 66 67 g->sf = create_starfield( g);67 g->sf = create_starfield(g); 68 68 g->wp = malloc(sizeof(weapons)); 69 69 g->ex = malloc(sizeof(explosions)); 70 70 g->bo = malloc(sizeof(bonus)); 71 g->t = create_tunnel( g, g->w, g->h);72 g->p = create_player( g);71 g->t = create_tunnel(g, g->w, g->h); 72 g->p = create_player(g); 73 73 g->al = malloc(sizeof(aliens)); 74 74 75 init_bonus( g, g->bo);76 init_weapons( g, g->wp);77 init_explosions( g, g->ex);78 init_aliens( g, g->al);75 init_bonus(g, g->bo); 76 init_weapons(g, g->wp); 77 init_explosions(g, g->ex); 78 init_aliens(g, g->al); 79 79 80 80 /* Temporary stuff */ 81 81 g->t->w = 25; 82 82 83 while( !quit)83 while(!quit) 84 84 { 85 85 char key; 86 86 87 while( ( key = ee_get_key() ))87 while((key = ee_get_key())) 88 88 { 89 switch( key)89 switch(key) 90 90 { 91 91 case 'q': … … 94 94 case 'p': 95 95 poz = !poz; 96 if( poz)97 { 98 pausebox = create_box( 99 g->w - 16, 8 96 if(poz) 97 { 98 pausebox = create_box(g, g->w / 2, g->h / 2, 99 g->w - 16, 8); 100 100 } 101 101 else 102 102 { 103 free_box( pausebox);103 free_box(pausebox); 104 104 } 105 105 break; 106 106 case '\t': 107 ceo_alert( g);107 ceo_alert(g); 108 108 poz = 1; 109 109 break; … … 112 112 break; 113 113 default: 114 if( g->p->dead)115 { 116 break; 117 } 118 119 switch( key)114 if(g->p->dead) 115 { 116 break; 117 } 118 119 switch(key) 120 120 { 121 121 case 'h': … … 123 123 break; 124 124 case 'j': 125 if( g->p->y < g->h - 2) g->p->y += 1;125 if(g->p->y < g->h - 2) g->p->y += 1; 126 126 break; 127 127 case 'k': 128 if( g->p->y > 1) g->p->y -= 1;128 if(g->p->y > 1) g->p->y -= 1; 129 129 break; 130 130 case 'l': … … 132 132 break; 133 133 case 'n': 134 if( g->p->special >= COST_NUKE)134 if(g->p->special >= COST_NUKE) 135 135 { 136 136 g->p->special -= COST_NUKE; 137 add_weapon( g, g->wp, (g->p->x + 2) << 4, g->p->y << 4, 0, 0, WEAPON_NUKE);137 add_weapon(g, g->wp, (g->p->x + 2) << 4, g->p->y << 4, 0, 0, WEAPON_NUKE); 138 138 } 139 139 break; 140 140 case 'f': 141 if( g->p->special >= COST_FRAGBOMB)141 if(g->p->special >= COST_FRAGBOMB) 142 142 { 143 143 g->p->special -= COST_FRAGBOMB; 144 add_weapon( g, g->wp, (g->p->x + 2) << 4, g->p->y << 4, 0, -16, WEAPON_FRAGBOMB);144 add_weapon(g, g->wp, (g->p->x + 2) << 4, g->p->y << 4, 0, -16, WEAPON_FRAGBOMB); 145 145 } 146 146 break; 147 147 case 'b': 148 if( g->p->special >= COST_BEAM)148 if(g->p->special >= COST_BEAM) 149 149 { 150 150 g->p->special -= COST_BEAM; 151 add_weapon( g, g->wp, (g->p->x + 2) << 4, g->p->y << 4, 0, 0, WEAPON_BEAM);151 add_weapon(g, g->wp, (g->p->x + 2) << 4, g->p->y << 4, 0, 0, WEAPON_BEAM); 152 152 } 153 153 break; 154 154 case ' ': 155 if( g->p->weapon == 0)155 if(g->p->weapon == 0) 156 156 { 157 157 g->p->weapon = 4; 158 add_weapon( g, g->wp, g->p->x << 4, g->p->y << 4, 0, -32, WEAPON_LASER);159 add_weapon( g, g->wp, (g->p->x + 5) << 4, g->p->y << 4, 0, -32, WEAPON_LASER);158 add_weapon(g, g->wp, g->p->x << 4, g->p->y << 4, 0, -32, WEAPON_LASER); 159 add_weapon(g, g->wp, (g->p->x + 5) << 4, g->p->y << 4, 0, -32, WEAPON_LASER); 160 160 /* Extra schtuph */ 161 add_weapon( g, g->wp, g->p->x << 4, g->p->y << 4, -24, -16, WEAPON_SEEKER);162 add_weapon( g, g->wp, (g->p->x + 5) << 4, g->p->y << 4, 24, -16, WEAPON_SEEKER);161 add_weapon(g, g->wp, g->p->x << 4, g->p->y << 4, -24, -16, WEAPON_SEEKER); 162 add_weapon(g, g->wp, (g->p->x + 5) << 4, g->p->y << 4, 24, -16, WEAPON_SEEKER); 163 163 /* More schtuph */ 164 add_weapon( g, g->wp, (g->p->x + 1) << 4, (g->p->y - 1) << 4, 0, -32, WEAPON_LASER);165 add_weapon( g, g->wp, (g->p->x + 4) << 4, (g->p->y - 1) << 4, 0, -32, WEAPON_LASER);164 add_weapon(g, g->wp, (g->p->x + 1) << 4, (g->p->y - 1) << 4, 0, -32, WEAPON_LASER); 165 add_weapon(g, g->wp, (g->p->x + 4) << 4, (g->p->y - 1) << 4, 0, -32, WEAPON_LASER); 166 166 /* Even more schtuph */ 167 add_weapon( g, g->wp, (g->p->x + 2) << 4, (g->p->y - 1) << 4, 0, -32, WEAPON_LASER);168 add_weapon( g, g->wp, (g->p->x + 3) << 4, (g->p->y - 1) << 4, 0, -32, WEAPON_LASER);167 add_weapon(g, g->wp, (g->p->x + 2) << 4, (g->p->y - 1) << 4, 0, -32, WEAPON_LASER); 168 add_weapon(g, g->wp, (g->p->x + 3) << 4, (g->p->y - 1) << 4, 0, -32, WEAPON_LASER); 169 169 /* Extra schtuph */ 170 add_weapon( g, g->wp, g->p->x << 4, g->p->y << 4, -32, 0, WEAPON_SEEKER);171 add_weapon( g, g->wp, (g->p->x + 5) << 4, g->p->y << 4, 32, 0, WEAPON_SEEKER);170 add_weapon(g, g->wp, g->p->x << 4, g->p->y << 4, -32, 0, WEAPON_SEEKER); 171 add_weapon(g, g->wp, (g->p->x + 5) << 4, g->p->y << 4, 32, 0, WEAPON_SEEKER); 172 172 /* MORE SCHTUPH! */ 173 add_weapon( g, g->wp, (g->p->x + 2) << 4, g->p->y << 4, 0, -16, WEAPON_BOMB);173 add_weapon(g, g->wp, (g->p->x + 2) << 4, g->p->y << 4, 0, -16, WEAPON_BOMB); 174 174 } 175 175 break; … … 178 178 } 179 179 180 if( !poz || skip)180 if(!poz || skip) 181 181 { 182 182 skip = 0; 183 183 184 184 /* XXX: to be removed */ 185 if( GET_RAND(0,10) == 0)185 if(GET_RAND(0,10) == 0) 186 186 { 187 187 int list[3] = { ALIEN_FOO, ALIEN_BAR, ALIEN_BAZ }; 188 188 189 add_alien( g, g->al, 0, rand() % g->h / 2, list[GET_RAND(0,3)]);189 add_alien(g, g->al, 0, rand() % g->h / 2, list[GET_RAND(0,3)]); 190 190 } 191 191 192 192 /* Update game rules */ 193 if( g->t->right[1] - g->t->left[1] == g->t->w)193 if(g->t->right[1] - g->t->left[1] == g->t->w) 194 194 { 195 195 g->t->w = 85 - g->t->w; … … 197 197 198 198 /* Scroll and update positions */ 199 collide_player_tunnel( g, g->p, g->t, g->ex);200 update_player( g, g->p);201 collide_player_tunnel( g, g->p, g->t, g->ex);202 203 update_starfield( g, g->sf);204 update_bonus( g, g->bo);205 update_aliens( g, g->al);206 207 collide_weapons_tunnel( g, g->wp, g->t, g->ex);208 collide_weapons_aliens( g, g->wp, g->al, g->ex);209 update_weapons( g, g->wp);210 collide_weapons_tunnel( g, g->wp, g->t, g->ex);211 collide_weapons_aliens( g, g->wp, g->al, g->ex);212 213 update_explosions( g, g->ex);214 update_tunnel( g, g->t);199 collide_player_tunnel(g, g->p, g->t, g->ex); 200 update_player(g, g->p); 201 collide_player_tunnel(g, g->p, g->t, g->ex); 202 203 update_starfield(g, g->sf); 204 update_bonus(g, g->bo); 205 update_aliens(g, g->al); 206 207 collide_weapons_tunnel(g, g->wp, g->t, g->ex); 208 collide_weapons_aliens(g, g->wp, g->al, g->ex); 209 update_weapons(g, g->wp); 210 collide_weapons_tunnel(g, g->wp, g->t, g->ex); 211 collide_weapons_aliens(g, g->wp, g->al, g->ex); 212 213 update_explosions(g, g->ex); 214 update_tunnel(g, g->t); 215 215 } 216 216 … … 219 219 220 220 /* Print starfield, tunnel, aliens, player and explosions */ 221 draw_starfield( g, g->sf);222 draw_aliens( g, g->al);223 draw_tunnel( g, g->t);224 draw_bonus( g, g->bo);225 draw_explosions( g, g->ex);226 draw_weapons( g, g->wp);227 draw_player( g, g->p);228 draw_status( g);221 draw_starfield(g, g->sf); 222 draw_aliens(g, g->al); 223 draw_tunnel(g, g->t); 224 draw_bonus(g, g->bo); 225 draw_explosions(g, g->ex); 226 draw_weapons(g, g->wp); 227 draw_player(g, g->p); 228 draw_status(g); 229 229 230 230 /* Print pause box if needed */ 231 if( poz)231 if(poz) 232 232 { 233 233 pausebox->frame++; 234 draw_box( g, pausebox);234 draw_box(g, pausebox); 235 235 } 236 236 … … 241 241 } 242 242 243 if( pausebox)243 if(pausebox) 244 244 { 245 free_box( pausebox);245 free_box(pausebox); 246 246 } 247 247 248 free_starfield( g, g->sf);249 free_tunnel( g->t);250 free_player( g->p);248 free_starfield(g, g->sf); 249 free_tunnel(g->t); 250 free_player(g->p); 251 251 } 252 252 -
ttyvaders/trunk/src/math.c
r72 r88 4 4 * All Rights Reserved 5 5 * 6 * $Id : math.c,v 1.2 2002/12/22 23:01:35 sam Exp$6 * $Id$ 7 7 * 8 8 * This program is free software; you can redistribute it and/or modify … … 23 23 #include "common.h" 24 24 25 int r00t( int a)25 int r00t(int a) 26 26 { 27 27 int x = a > 100000 ? 1000 : a > 1000 ? 100 : a > 10 ? 10 : 1; 28 28 29 if( a <= 0)29 if(a <= 0) 30 30 { 31 31 return 0; -
ttyvaders/trunk/src/overlay.c
r80 r88 25 25 #include "common.h" 26 26 27 void draw_status( game *g)27 void draw_status(game *g) 28 28 { 29 29 static char dots30[] = "------------------------------"; … … 31 31 32 32 /* Draw life jauge */ 33 ee_color( EE_GRAY);34 ee_goto( 4, 1);35 ee_putstr( dots30);33 ee_color(EE_GRAY); 34 ee_goto(4, 1); 35 ee_putstr(dots30); 36 36 37 if( g->p->life > MAX_LIFE * 7 / 10)37 if(g->p->life > MAX_LIFE * 7 / 10) 38 38 { 39 ee_color( EE_GREEN);39 ee_color(EE_GREEN); 40 40 } 41 else if( g->p->life > MAX_LIFE * 3 / 10)41 else if(g->p->life > MAX_LIFE * 3 / 10) 42 42 { 43 ee_color( EE_YELLOW);43 ee_color(EE_YELLOW); 44 44 } 45 45 else 46 46 { 47 ee_color( EE_RED);47 ee_color(EE_RED); 48 48 } 49 49 50 ee_goto( 4, 1);51 ee_putstr( dashes30 + ( MAX_LIFE - g->p->life ) * 30 / MAX_LIFE);50 ee_goto(4, 1); 51 ee_putstr(dashes30 + (MAX_LIFE - g->p->life) * 30 / MAX_LIFE); 52 52 53 ee_color( EE_WHITE);54 ee_goto( 1, 1);55 ee_putstr( "L |");56 ee_goto( 34, 1);57 ee_putstr( "|");53 ee_color(EE_WHITE); 54 ee_goto(1, 1); 55 ee_putstr("L |"); 56 ee_goto(34, 1); 57 ee_putstr("|"); 58 58 59 59 /* Draw weapon jauge */ 60 ee_color( EE_GRAY);61 ee_goto( 42, 1);62 ee_putstr( dots30 + 10);60 ee_color(EE_GRAY); 61 ee_goto(42, 1); 62 ee_putstr(dots30 + 10); 63 63 64 if( g->p->special > MAX_SPECIAL * 9 / 10)64 if(g->p->special > MAX_SPECIAL * 9 / 10) 65 65 { 66 ee_color( EE_WHITE);66 ee_color(EE_WHITE); 67 67 } 68 else if( g->p->special > MAX_SPECIAL * 3 / 10)68 else if(g->p->special > MAX_SPECIAL * 3 / 10) 69 69 { 70 ee_color( EE_CYAN);70 ee_color(EE_CYAN); 71 71 } 72 72 else 73 73 { 74 ee_color( EE_BLUE);74 ee_color(EE_BLUE); 75 75 } 76 76 77 ee_goto( 42, 1);78 ee_putstr( dashes30 + 10 + ( MAX_SPECIAL - g->p->special ) * 20 / MAX_SPECIAL);77 ee_goto(42, 1); 78 ee_putstr(dashes30 + 10 + (MAX_SPECIAL - g->p->special) * 20 / MAX_SPECIAL); 79 79 80 ee_color( EE_WHITE);81 ee_goto( 39, 1);82 ee_putstr( "S |");83 ee_goto( 62, 1);84 ee_putstr( "|");80 ee_color(EE_WHITE); 81 ee_goto(39, 1); 82 ee_putstr("S |"); 83 ee_goto(62, 1); 84 ee_putstr("|"); 85 85 } 86 86 -
ttyvaders/trunk/src/player.c
r80 r88 26 26 27 27 /* Init tunnel */ 28 player * create_player( game *g)28 player * create_player(game *g) 29 29 { 30 30 player *p = malloc(sizeof(player)); … … 42 42 } 43 43 44 void free_player( player *p)44 void free_player(player *p) 45 45 { 46 free( p);46 free(p); 47 47 } 48 48 49 void draw_player( game *g, player *p)49 void draw_player(game *g, player *p) 50 50 { 51 if( p->dead)51 if(p->dead) 52 52 { 53 53 return; 54 54 } 55 55 56 ee_goto( p->x + 2, p->y - 2);57 ee_color( EE_GREEN);58 ee_putstr( "/\\");59 ee_goto( p->x + 1, p->y - 1);60 ee_putchar( '(');61 ee_color( EE_YELLOW);62 ee_putstr( "()");63 ee_color( EE_GREEN);64 ee_putchar( ')');65 ee_goto( p->x, p->y);66 ee_color( EE_GREEN);67 ee_putstr( "I<__>I");56 ee_goto(p->x + 2, p->y - 2); 57 ee_color(EE_GREEN); 58 ee_putstr("/\\"); 59 ee_goto(p->x + 1, p->y - 1); 60 ee_putchar('('); 61 ee_color(EE_YELLOW); 62 ee_putstr("()"); 63 ee_color(EE_GREEN); 64 ee_putchar(')'); 65 ee_goto(p->x, p->y); 66 ee_color(EE_GREEN); 67 ee_putstr("I<__>I"); 68 68 } 69 69 70 void update_player( game *g, player *p)70 void update_player(game *g, player *p) 71 71 { 72 if( p->dead)72 if(p->dead) 73 73 { 74 74 return; 75 75 } 76 76 77 if( p->life <= 0)77 if(p->life <= 0) 78 78 { 79 add_explosion( g, g->ex, p->x, p->y, 0, 0, EXPLOSION_SMALL);79 add_explosion(g, g->ex, p->x, p->y, 0, 0, EXPLOSION_SMALL); 80 80 p->dead = 1; 81 81 return; … … 83 83 84 84 /* Update weapon stats */ 85 if( p->weapon)85 if(p->weapon) 86 86 { 87 87 p->weapon--; 88 88 } 89 89 90 if( p->special < MAX_SPECIAL)90 if(p->special < MAX_SPECIAL) 91 91 { 92 92 p->special++; … … 94 94 95 95 /* Update life */ 96 if( p->life < MAX_LIFE)96 if(p->life < MAX_LIFE) 97 97 { 98 98 p->life++; … … 102 102 p->x += p->vx; 103 103 104 if( p->vx < 0)104 if(p->vx < 0) 105 105 { 106 106 p->vx++; 107 107 } 108 else if( p->vx > 0)108 else if(p->vx > 0) 109 109 { 110 110 p->vx--; 111 111 } 112 112 113 if( p->x < 1)113 if(p->x < 1) 114 114 { 115 115 p->x = 1; 116 116 } 117 else if( p->x > g->w - 7)117 else if(p->x > g->w - 7) 118 118 { 119 119 p->x = g->w - 7; -
ttyvaders/trunk/src/starfield.c
r80 r88 25 25 #include "common.h" 26 26 27 starfield * create_starfield( game *g)27 starfield * create_starfield(game *g) 28 28 { 29 29 int i; 30 30 starfield *s; 31 31 32 s = malloc( STARS * sizeof(starfield));32 s = malloc(STARS * sizeof(starfield)); 33 33 34 for( i = 0; i < STARS; i++)34 for(i = 0; i < STARS; i++) 35 35 { 36 s[i].x = GET_RAND( 0, g->w);37 s[i].y = GET_RAND( 0, g->h);38 s[i].z = GET_RAND( 1, 4);39 s[i].c = GET_RAND( 6, 8);40 s[i].ch = GET_RAND( 0, 2) ? '.' : '\'';36 s[i].x = GET_RAND(0, g->w); 37 s[i].y = GET_RAND(0, g->h); 38 s[i].z = GET_RAND(1, 4); 39 s[i].c = GET_RAND(6, 8); 40 s[i].ch = GET_RAND(0, 2) ? '.' : '\''; 41 41 } 42 42 … … 44 44 } 45 45 46 void draw_starfield( game *g, starfield *s)46 void draw_starfield(game *g, starfield *s) 47 47 { 48 48 int i; 49 49 50 for( i = 0; i < STARS; i++)50 for(i = 0; i < STARS; i++) 51 51 { 52 if( s[i].x >= 0)52 if(s[i].x >= 0) 53 53 { 54 ee_color( s[i].c);55 ee_goto( s[i].x, s[i].y);56 ee_putchar( s[i].ch);54 ee_color(s[i].c); 55 ee_goto(s[i].x, s[i].y); 56 ee_putchar(s[i].ch); 57 57 } 58 58 } 59 59 } 60 60 61 void update_starfield( game *g, starfield *s)61 void update_starfield(game *g, starfield *s) 62 62 { 63 63 int i; 64 64 65 for( i = 0; i < STARS; i++)65 for(i = 0; i < STARS; i++) 66 66 { 67 if( s[i].x < 0)67 if(s[i].x < 0) 68 68 { 69 s[i].x = GET_RAND( 0, g->w);69 s[i].x = GET_RAND(0, g->w); 70 70 s[i].y = 0; 71 s[i].z = GET_RAND( 1, 3);72 s[i].c = GET_RAND( 6, 8);73 s[i].ch = GET_RAND( 0, 2) ? '.' : '\'';71 s[i].z = GET_RAND(1, 3); 72 s[i].c = GET_RAND(6, 8); 73 s[i].ch = GET_RAND(0, 2) ? '.' : '\''; 74 74 } 75 else if( s[i].y < g->h-1)75 else if(s[i].y < g->h-1) 76 76 { 77 77 s[i].y += s[i].z; … … 84 84 } 85 85 86 void free_starfield( game *g, starfield *s)86 void free_starfield(game *g, starfield *s) 87 87 { 88 free( s);88 free(s); 89 89 } 90 90 -
ttyvaders/trunk/src/tunnel.c
r80 r88 28 28 29 29 /* Init tunnel */ 30 tunnel * create_tunnel( game *g, int w, int h)30 tunnel * create_tunnel(game *g, int w, int h) 31 31 { 32 32 int i; … … 38 38 t->h = h; 39 39 40 if( t->w >= g->w)41 { 42 for( i = 0; i < g->h; i++)40 if(t->w >= g->w) 41 { 42 for(i = 0; i < g->h; i++) 43 43 { 44 44 t->left[i] = -10; … … 51 51 t->right[0] = (g->w + w) / 2; 52 52 /* Yeah, sub-efficient, but less code to do :-) */ 53 for( i = 0; i < g->h; i++)54 { 55 update_tunnel( g, t);53 for(i = 0; i < g->h; i++) 54 { 55 update_tunnel(g, t); 56 56 } 57 57 } … … 60 60 } 61 61 62 void free_tunnel( tunnel *t)63 { 64 free( t->left);65 free( t->right);66 free( t);67 } 68 69 void draw_tunnel( game *g, tunnel *t)62 void free_tunnel(tunnel *t) 63 { 64 free(t->left); 65 free(t->right); 66 free(t); 67 } 68 69 void draw_tunnel(game *g, tunnel *t) 70 70 { 71 71 int i, j; 72 72 char c; 73 73 74 ee_color( EE_GREEN);74 ee_color(EE_GREEN); 75 75 76 76 /* Left border */ 77 for( i = 0; i < g->h ; i++)78 { 79 if( t->left[i] <= -10)77 for(i = 0; i < g->h ; i++) 78 { 79 if(t->left[i] <= -10) 80 80 { 81 81 continue; 82 82 } 83 83 84 if( i + 1 == g->h || t->left[i] > t->left[i+1])85 { 86 c = ( i == 0 || t->left[i] > t->left[i-1]) ? '>' : '/';84 if(i + 1 == g->h || t->left[i] > t->left[i+1]) 85 { 86 c = (i == 0 || t->left[i] > t->left[i-1]) ? '>' : '/'; 87 87 } 88 88 else 89 89 { 90 c = ( i == 0 || t->left[i] > t->left[i-1]) ? '\\' : '<';91 } 92 93 ee_goto( t->left[i] + 1, i);94 ee_putchar( c);95 96 if( i + 1 < g->h)97 { 98 for( j = 1; j < t->left[i+1] - t->left[i]; j++)90 c = (i == 0 || t->left[i] > t->left[i-1]) ? '\\' : '<'; 91 } 92 93 ee_goto(t->left[i] + 1, i); 94 ee_putchar(c); 95 96 if(i + 1 < g->h) 97 { 98 for(j = 1; j < t->left[i+1] - t->left[i]; j++) 99 99 { 100 ee_goto( t->left[i] + j + 1, i);101 ee_putchar( '_');100 ee_goto(t->left[i] + j + 1, i); 101 ee_putchar('_'); 102 102 } 103 103 } … … 105 105 106 106 /* Right border */ 107 for( i = 0; i < g->h ; i++)108 { 109 if( t->right[i] >= g->w + 10)107 for(i = 0; i < g->h ; i++) 108 { 109 if(t->right[i] >= g->w + 10) 110 110 { 111 111 continue; 112 112 } 113 113 114 if( i + 1 == g->h || t->right[i] > t->right[i+1])115 { 116 c = ( i == 0 || t->right[i] > t->right[i-1]) ? '>' : '/';114 if(i + 1 == g->h || t->right[i] > t->right[i+1]) 115 { 116 c = (i == 0 || t->right[i] > t->right[i-1]) ? '>' : '/'; 117 117 } 118 118 else 119 119 { 120 c = ( i == 0 || t->right[i] > t->right[i-1]) ? '\\' : '<';121 } 122 123 if( i + 1 < g->h)124 { 125 for( j = 1; j < t->right[i] - t->right[i+1]; j++)120 c = (i == 0 || t->right[i] > t->right[i-1]) ? '\\' : '<'; 121 } 122 123 if(i + 1 < g->h) 124 { 125 for(j = 1; j < t->right[i] - t->right[i+1]; j++) 126 126 { 127 ee_goto( t->right[i+1] + j - 1, i);128 ee_putchar( '_');127 ee_goto(t->right[i+1] + j - 1, i); 128 ee_putchar('_'); 129 129 } 130 130 } 131 131 132 ee_goto( t->right[i] - 1, i);133 ee_putchar( c);134 } 135 136 ee_color( EE_RED);132 ee_goto(t->right[i] - 1, i); 133 ee_putchar(c); 134 } 135 136 ee_color(EE_RED); 137 137 138 138 /* Left concrete */ 139 for( i = 0; i < g->h ; i++)140 { 141 for( j = 0 ; j <= t->left[i]; j++)142 { 143 ee_goto( j, i);144 ee_putchar( '#');139 for(i = 0; i < g->h ; i++) 140 { 141 for(j = 0 ; j <= t->left[i]; j++) 142 { 143 ee_goto(j, i); 144 ee_putchar('#'); 145 145 } 146 146 } 147 147 148 148 /* Right concrete */ 149 for( i = 0; i < g->h ; i++)150 { 151 for( j = t->right[i] ; j < g->w ; j++)152 { 153 ee_goto( j, i);154 ee_putchar( '#');155 } 156 } 157 } 158 159 void update_tunnel( game *g, tunnel *t)149 for(i = 0; i < g->h ; i++) 150 { 151 for(j = t->right[i] ; j < g->w ; j++) 152 { 153 ee_goto(j, i); 154 ee_putchar('#'); 155 } 156 } 157 } 158 159 void update_tunnel(game *g, tunnel *t) 160 160 { 161 161 static int const delta[] = { -3, -2, -1, 1, 2, 3 }; … … 163 163 164 164 /* Slide tunnel one block vertically */ 165 for( i = t->h - 1; i--;)165 for(i = t->h - 1; i--;) 166 166 { 167 167 t->left[i+1] = t->left[i]; … … 174 174 175 175 /* Check in which direction we need to alter tunnel */ 176 if( t->right[1] - t->left[1] < t->w)176 if(t->right[1] - t->left[1] < t->w) 177 177 { 178 178 /* Not wide enough, make sure i <= j */ 179 if( i > j)179 if(i > j) 180 180 { 181 181 k = j; j = i; i = k; 182 182 } 183 183 } 184 else if( t->right[1] - t->left[1] - 2 > t->w)184 else if(t->right[1] - t->left[1] - 2 > t->w) 185 185 { 186 186 /* Too wide, make sure i >= j */ 187 if( i < j)187 if(i < j) 188 188 { 189 189 k = j; j = i; i = k; … … 196 196 197 197 /* If width doesn't exceed game size, update coords */ 198 if( t->w <= g->w || t->right[1] - t->left[1] < t->w)198 if(t->w <= g->w || t->right[1] - t->left[1] < t->w) 199 199 { 200 200 t->left[0] = t->left[1] + i; … … 207 207 } 208 208 209 if( t->w > g->w)210 { 211 if( t->left[0] < 0 && t->right[0] < g->w - 2)209 if(t->w > g->w) 210 { 211 if(t->left[0] < 0 && t->right[0] < g->w - 2) 212 212 { 213 213 t->left[0] = t->left[1] + 1; 214 214 } 215 215 216 if( t->left[0] > 1 && t->right[0] > g->w - 1)216 if(t->left[0] > 1 && t->right[0] > g->w - 1) 217 217 { 218 218 t->right[0] = t->right[1] - 1; … … 221 221 else 222 222 { 223 if( t->left[0] < 0)223 if(t->left[0] < 0) 224 224 { 225 225 t->left[0] = t->left[1] + 1; 226 226 } 227 227 228 if( t->right[0] > g->w - 1)228 if(t->right[0] > g->w - 1) 229 229 { 230 230 t->right[0] = t->right[1] - 1; -
ttyvaders/trunk/src/weapons.c
r80 r88 25 25 #include "common.h" 26 26 27 static void draw_bomb( int x, int y, int vx, int vy);28 static void draw_nuke( int x, int y, int frame);29 static void draw_beam( int x, int y, int frame);30 static void draw_circle( int x, int y, int r, char c);31 static void draw_fragbomb( int x, int y, int frame);32 33 void init_weapons( game *g, weapons *wp)27 static void draw_bomb(int x, int y, int vx, int vy); 28 static void draw_nuke(int x, int y, int frame); 29 static void draw_beam(int x, int y, int frame); 30 static void draw_circle(int x, int y, int r, char c); 31 static void draw_fragbomb(int x, int y, int frame); 32 33 void init_weapons(game *g, weapons *wp) 34 34 { 35 35 int i; 36 36 37 for( i = 0; i < WEAPONS; i++)37 for(i = 0; i < WEAPONS; i++) 38 38 { 39 39 wp->type[i] = WEAPON_NONE; … … 41 41 } 42 42 43 void draw_weapons( game *g, weapons *wp)43 void draw_weapons(game *g, weapons *wp) 44 44 { 45 45 int i; 46 46 47 for( i = 0; i < WEAPONS; i++)48 { 49 switch( wp->type[i])47 for(i = 0; i < WEAPONS; i++) 48 { 49 switch(wp->type[i]) 50 50 { 51 51 case WEAPON_LASER: 52 ee_color( EE_WHITE);53 ee_goto( wp->x[i] >> 4, wp->y[i] >> 4);54 ee_putchar( '|');55 ee_color( EE_CYAN);56 ee_goto( wp->x[i] >> 4, (wp->y[i] >> 4) + 1);57 ee_putchar( '|');52 ee_color(EE_WHITE); 53 ee_goto(wp->x[i] >> 4, wp->y[i] >> 4); 54 ee_putchar('|'); 55 ee_color(EE_CYAN); 56 ee_goto(wp->x[i] >> 4, (wp->y[i] >> 4) + 1); 57 ee_putchar('|'); 58 58 break; 59 59 case WEAPON_SEEKER: 60 ee_color( EE_CYAN);61 ee_goto( wp->x3[i] >> 4, wp->y3[i] >> 4);62 ee_putchar( '.');63 ee_goto( wp->x2[i] >> 4, wp->y2[i] >> 4);64 ee_putchar( 'o');65 ee_color( EE_WHITE);66 ee_goto( wp->x[i] >> 4, wp->y[i] >> 4);67 ee_putchar( '@');60 ee_color(EE_CYAN); 61 ee_goto(wp->x3[i] >> 4, wp->y3[i] >> 4); 62 ee_putchar('.'); 63 ee_goto(wp->x2[i] >> 4, wp->y2[i] >> 4); 64 ee_putchar('o'); 65 ee_color(EE_WHITE); 66 ee_goto(wp->x[i] >> 4, wp->y[i] >> 4); 67 ee_putchar('@'); 68 68 break; 69 69 case WEAPON_BOMB: 70 ee_color( EE_GRAY);71 ee_goto( (wp->x[i] - wp->vx[i]) >> 4, (wp->y[i] - wp->vy[i]) >> 4);72 ee_putchar( '.');73 ee_goto( (wp->x3[i] - wp->vx[i]) >> 4, (wp->y3[i] - wp->vy[i]) >> 4);74 ee_putchar( '.');75 ee_goto( (wp->x2[i] - wp->vx[i]) >> 4, (wp->y2[i] - wp->vy[i]) >> 4);76 ee_putchar( '.');77 ee_goto( wp->x3[i] >> 4, wp->y3[i] >> 4);78 ee_putchar( '.');79 ee_goto( wp->x2[i] >> 4, wp->y2[i] >> 4);80 ee_putchar( '.');81 draw_bomb( wp->x[i] >> 4, wp->y[i] >> 4, wp->vx[i], wp->vy[i]);70 ee_color(EE_GRAY); 71 ee_goto((wp->x[i] - wp->vx[i]) >> 4, (wp->y[i] - wp->vy[i]) >> 4); 72 ee_putchar('.'); 73 ee_goto((wp->x3[i] - wp->vx[i]) >> 4, (wp->y3[i] - wp->vy[i]) >> 4); 74 ee_putchar('.'); 75 ee_goto((wp->x2[i] - wp->vx[i]) >> 4, (wp->y2[i] - wp->vy[i]) >> 4); 76 ee_putchar('.'); 77 ee_goto(wp->x3[i] >> 4, wp->y3[i] >> 4); 78 ee_putchar('.'); 79 ee_goto(wp->x2[i] >> 4, wp->y2[i] >> 4); 80 ee_putchar('.'); 81 draw_bomb(wp->x[i] >> 4, wp->y[i] >> 4, wp->vx[i], wp->vy[i]); 82 82 break; 83 83 case WEAPON_FRAGBOMB: 84 draw_fragbomb( wp->x[i] >> 4, wp->y[i] >> 4, wp->n[i]);84 draw_fragbomb(wp->x[i] >> 4, wp->y[i] >> 4, wp->n[i]); 85 85 break; 86 86 case WEAPON_BEAM: 87 draw_beam( wp->x[i] >> 4, wp->y[i] >> 4, wp->n[i]);87 draw_beam(wp->x[i] >> 4, wp->y[i] >> 4, wp->n[i]); 88 88 break; 89 89 case WEAPON_NUKE: 90 draw_nuke( wp->x[i] >> 4, wp->y[i] >> 4, wp->n[i]);90 draw_nuke(wp->x[i] >> 4, wp->y[i] >> 4, wp->n[i]); 91 91 break; 92 92 case WEAPON_LIGHTNING: … … 97 97 } 98 98 99 void update_weapons( game *g, weapons *wp)99 void update_weapons(game *g, weapons *wp) 100 100 { 101 101 int i, j, dist, xmin, ymin, dx, dy, xnew, ynew; 102 102 103 for( i = 0; i < WEAPONS; i++)104 { 105 switch( wp->type[i])103 for(i = 0; i < WEAPONS; i++) 104 { 105 switch(wp->type[i]) 106 106 { 107 107 case WEAPON_LASER: 108 108 wp->x[i] += wp->vx[i]; 109 109 wp->y[i] += wp->vy[i]; 110 if( wp->y[i] < 0)110 if(wp->y[i] < 0) 111 111 { 112 112 wp->type[i] = WEAPON_NONE; … … 125 125 wp->y[i] += wp->vy[i]; 126 126 127 if( wp->y[i] < 0)127 if(wp->y[i] < 0) 128 128 { 129 129 wp->type[i] = WEAPON_NONE; … … 131 131 } 132 132 133 if( wp->n[i] < 0)133 if(wp->n[i] < 0) 134 134 { 135 135 /* Stop updating direction */ … … 149 149 150 150 /* Find the nearest alien */ 151 for( j = 0; j < ALIENS; j++)152 { 153 if( g->al->type[j] != ALIEN_NONE)151 for(j = 0; j < ALIENS; j++) 152 { 153 if(g->al->type[j] != ALIEN_NONE) 154 154 { 155 155 int alx = g->al->x[j] << 4; … … 157 157 int new = (xnew - alx) * (xnew - alx) 158 158 + 4 * (ynew - aly) * (ynew - aly); 159 if( new <= dist)159 if(new <= dist) 160 160 { 161 161 dist = new; … … 171 171 172 172 /* Normalize direction */ 173 if( dx | dy)174 { 175 int norm = r00t( dx * dx + 4 * dy * dy);173 if(dx | dy) 174 { 175 int norm = r00t(dx * dx + 4 * dy * dy); 176 176 dx = dx * 32 / norm; 177 177 dy = dy * 32 / norm; … … 183 183 184 184 /* Normalize speed */ 185 if( dx | dy)186 { 187 int norm = r00t( dx * dx + 4 * dy * dy);185 if(dx | dy) 186 { 187 int norm = r00t(dx * dx + 4 * dy * dy); 188 188 wp->vx[i] = dx * 32 / norm; 189 189 wp->vy[i] = dy * 32 / norm; … … 194 194 case WEAPON_FRAGBOMB: 195 195 /* If n was set to -1, the fragbomb just exploded */ 196 if( wp->n[i] == -1)196 if(wp->n[i] == -1) 197 197 { 198 198 int coords[] = … … 204 204 }; 205 205 206 for( j = 0 ; j < sizeof(coords) / sizeof(int) ; j += 2)206 for(j = 0 ; j < sizeof(coords) / sizeof(int) ; j += 2) 207 207 { 208 add_weapon( g, g->wp, wp->x[i] + coords[j], wp->y[i] + coords[j+1] / 2, coords[j], coords[j+1], WEAPON_SEEKER);209 add_weapon( g, g->wp, wp->x[i] + coords[j] / 2, wp->y[i] + coords[j+1], coords[j], coords[j+1], WEAPON_SEEKER);208 add_weapon(g, g->wp, wp->x[i] + coords[j], wp->y[i] + coords[j+1] / 2, coords[j], coords[j+1], WEAPON_SEEKER); 209 add_weapon(g, g->wp, wp->x[i] + coords[j] / 2, wp->y[i] + coords[j+1], coords[j], coords[j+1], WEAPON_SEEKER); 210 210 } 211 211 … … 216 216 wp->y[i] += wp->vy[i]; 217 217 wp->n[i]++; 218 if( wp->y[i] < 0)218 if(wp->y[i] < 0) 219 219 { 220 220 wp->type[i] = WEAPON_NONE; … … 226 226 wp->y[i] = g->p->y << 4; 227 227 wp->n[i]--; 228 if( wp->n[i] < 0)228 if(wp->n[i] < 0) 229 229 { 230 230 wp->type[i] = WEAPON_NONE; … … 233 233 case WEAPON_NUKE: 234 234 wp->n[i]--; 235 if( wp->n[i] < 0)235 if(wp->n[i] < 0) 236 236 { 237 237 wp->type[i] = WEAPON_NONE; … … 245 245 } 246 246 247 void add_weapon( game *g, weapons *wp, int x, int y, int vx, int vy, int type)247 void add_weapon(game *g, weapons *wp, int x, int y, int vx, int vy, int type) 248 248 { 249 249 int i; 250 250 251 for( i = 0; i < WEAPONS; i++)252 { 253 if( wp->type[i] == WEAPON_NONE)251 for(i = 0; i < WEAPONS; i++) 252 { 253 if(wp->type[i] == WEAPON_NONE) 254 254 { 255 255 wp->x[i] = x; … … 259 259 wp->type[i] = type; 260 260 wp->n[i] = 0; 261 switch( type)261 switch(type) 262 262 { 263 263 case WEAPON_LASER: … … 287 287 } 288 288 289 static void draw_bomb( int x, int y, int vx, int vy)289 static void draw_bomb(int x, int y, int vx, int vy) 290 290 { 291 291 vy *= 2; 292 ee_color( EE_CYAN);293 294 if( vx > vy)295 { 296 if( vx > -vy) /* right quarter */292 ee_color(EE_CYAN); 293 294 if(vx > vy) 295 { 296 if(vx > -vy) /* right quarter */ 297 297 { 298 if( vy > vx/4)298 if(vy > vx/4) 299 299 { 300 300 /* -1pi/6 */ 301 ee_goto( x-4, y-1);302 ee_putstr( "/`-.");303 ee_goto( x-4, y);304 ee_putstr( "`-._\\");305 ee_color( EE_WHITE);306 ee_goto( x-1, y);307 ee_putstr( "_\\");308 ee_goto( x, y+1);309 ee_putchar( '`');310 } 311 else if( vy < -vx/4)301 ee_goto(x-4, y-1); 302 ee_putstr("/`-."); 303 ee_goto(x-4, y); 304 ee_putstr("`-._\\"); 305 ee_color(EE_WHITE); 306 ee_goto(x-1, y); 307 ee_putstr("_\\"); 308 ee_goto(x, y+1); 309 ee_putchar('`'); 310 } 311 else if(vy < -vx/4) 312 312 { 313 313 /* 1pi/6 */ 314 ee_goto( x-4, y);315 ee_putstr( ",-' ");316 ee_goto( x-4, y+1);317 ee_putstr( "\\,-'");318 ee_color( EE_WHITE);319 ee_goto( x-1, y-1);320 ee_putstr( "_,");321 ee_goto( x, y);322 ee_putchar( '/');314 ee_goto(x-4, y); 315 ee_putstr(",-' "); 316 ee_goto(x-4, y+1); 317 ee_putstr("\\,-'"); 318 ee_color(EE_WHITE); 319 ee_goto(x-1, y-1); 320 ee_putstr("_,"); 321 ee_goto(x, y); 322 ee_putchar('/'); 323 323 } 324 324 else 325 325 { 326 326 /* 0pi/6 */ 327 ee_goto( x-4, y-1);328 ee_putstr( "____");329 ee_goto( x-5, y);330 ee_putstr( "|____");331 ee_color( EE_WHITE);332 ee_goto( x, y);333 ee_putchar( '>');327 ee_goto(x-4, y-1); 328 ee_putstr("____"); 329 ee_goto(x-5, y); 330 ee_putstr("|____"); 331 ee_color(EE_WHITE); 332 ee_goto(x, y); 333 ee_putchar('>'); 334 334 } 335 335 } 336 336 else /* top quarter */ 337 337 { 338 if( vx > -vy/4)338 if(vx > -vy/4) 339 339 { 340 340 /* 2pi/6 */ 341 ee_goto( x-2, y);342 ee_putstr( "/ ");343 ee_goto( x-3, y+1);344 ee_putstr( "/ /");345 ee_goto( x-3, y+2);346 ee_putstr( "`'");347 ee_color( EE_WHITE);348 ee_goto( x-1, y-1);349 ee_putstr( "_,");350 ee_goto( x, y);351 ee_putchar( '|');352 } 353 else if( vx < vy/4)341 ee_goto(x-2, y); 342 ee_putstr("/ "); 343 ee_goto(x-3, y+1); 344 ee_putstr("/ /"); 345 ee_goto(x-3, y+2); 346 ee_putstr("`'"); 347 ee_color(EE_WHITE); 348 ee_goto(x-1, y-1); 349 ee_putstr("_,"); 350 ee_goto(x, y); 351 ee_putchar('|'); 352 } 353 else if(vx < vy/4) 354 354 { 355 355 /* 4pi/6 */ 356 ee_goto( x+1, y);357 ee_putstr( " \\");358 ee_goto( x+1, y+1);359 ee_putstr( "\\ \\");360 ee_goto( x+2, y+2);361 ee_putstr( "`'");362 ee_color( EE_WHITE);363 ee_goto( x, y-1);364 ee_putstr( "._");365 ee_goto( x, y);366 ee_putchar( '|');356 ee_goto(x+1, y); 357 ee_putstr(" \\"); 358 ee_goto(x+1, y+1); 359 ee_putstr("\\ \\"); 360 ee_goto(x+2, y+2); 361 ee_putstr("`'"); 362 ee_color(EE_WHITE); 363 ee_goto(x, y-1); 364 ee_putstr("._"); 365 ee_goto(x, y); 366 ee_putchar('|'); 367 367 } 368 368 else 369 369 { 370 370 /* 3pi/6 */ 371 ee_goto( x-1, y+1);372 ee_putstr( "| |");373 ee_goto( x-1, y+2);374 ee_putstr( "|_|");375 ee_color( EE_WHITE);376 ee_goto( x-1, y);377 ee_putstr( ",^.");371 ee_goto(x-1, y+1); 372 ee_putstr("| |"); 373 ee_goto(x-1, y+2); 374 ee_putstr("|_|"); 375 ee_color(EE_WHITE); 376 ee_goto(x-1, y); 377 ee_putstr(",^."); 378 378 } 379 379 } … … 381 381 else 382 382 { 383 if( vx > -vy) /* bottom quarter */383 if(vx > -vy) /* bottom quarter */ 384 384 { 385 if( vx > vy/4)385 if(vx > vy/4) 386 386 { 387 387 /* -2pi/6 */ 388 ee_goto( x-2, y-2);389 ee_putstr( ",.");390 ee_goto( x-2, y-1);391 ee_putstr( "\\ \\");392 ee_goto( x-1, y);393 ee_putchar( '\\');394 ee_color( EE_WHITE);395 ee_goto( x, y);396 ee_putstr( "_|");397 } 398 else if( vx < -vy/4)388 ee_goto(x-2, y-2); 389 ee_putstr(",."); 390 ee_goto(x-2, y-1); 391 ee_putstr("\\ \\"); 392 ee_goto(x-1, y); 393 ee_putchar('\\'); 394 ee_color(EE_WHITE); 395 ee_goto(x, y); 396 ee_putstr("_|"); 397 } 398 else if(vx < -vy/4) 399 399 { 400 400 /* -4pi/6 */ 401 ee_goto( x+1, y-2);402 ee_putstr( ",.");403 ee_goto( x, y-1);404 ee_putstr( "/ /");405 ee_goto( x+1, y);406 ee_putchar( '/');407 ee_color( EE_WHITE);408 ee_goto( x-1, y);409 ee_putstr( "|_/");401 ee_goto(x+1, y-2); 402 ee_putstr(",."); 403 ee_goto(x, y-1); 404 ee_putstr("/ /"); 405 ee_goto(x+1, y); 406 ee_putchar('/'); 407 ee_color(EE_WHITE); 408 ee_goto(x-1, y); 409 ee_putstr("|_/"); 410 410 } 411 411 else 412 412 { 413 413 /* -3pi/6 */ 414 ee_goto( x, y-3);415 ee_putchar( '_');416 ee_goto( x-1, y-2);417 ee_putstr( "| |");418 ee_goto( x-1, y-1);419 ee_putstr( "| |");420 ee_color( EE_WHITE);421 ee_goto( x-1, y);422 ee_putstr( "`v'");414 ee_goto(x, y-3); 415 ee_putchar('_'); 416 ee_goto(x-1, y-2); 417 ee_putstr("| |"); 418 ee_goto(x-1, y-1); 419 ee_putstr("| |"); 420 ee_color(EE_WHITE); 421 ee_goto(x-1, y); 422 ee_putstr("`v'"); 423 423 } 424 424 } 425 425 else /* left quarter */ 426 426 { 427 if( vy > -vx/4)427 if(vy > -vx/4) 428 428 { 429 429 /* -5pi/6 */ 430 ee_goto( x+1, y-1);431 ee_putstr( ",-'\\");432 ee_goto( x+2, y);433 ee_putstr( ",-'");434 ee_goto( x, y+1);435 ee_putchar( '\'');436 ee_color( EE_WHITE);437 ee_goto( x, y);438 ee_putstr( "/_");439 } 440 else if( vy < vx/4)430 ee_goto(x+1, y-1); 431 ee_putstr(",-'\\"); 432 ee_goto(x+2, y); 433 ee_putstr(",-'"); 434 ee_goto(x, y+1); 435 ee_putchar('\''); 436 ee_color(EE_WHITE); 437 ee_goto(x, y); 438 ee_putstr("/_"); 439 } 440 else if(vy < vx/4) 441 441 { 442 442 /* 5pi/6 */ 443 ee_goto( x+1, y);444 ee_putstr( " `-.");445 ee_goto( x+1, y+1);446 ee_putstr( "`-./");447 ee_color( EE_WHITE);448 ee_goto( x, y-1);449 ee_putstr( "._");450 ee_goto( x, y);451 ee_putchar( '\\');443 ee_goto(x+1, y); 444 ee_putstr(" `-."); 445 ee_goto(x+1, y+1); 446 ee_putstr("`-./"); 447 ee_color(EE_WHITE); 448 ee_goto(x, y-1); 449 ee_putstr("._"); 450 ee_goto(x, y); 451 ee_putchar('\\'); 452 452 } 453 453 else 454 454 { 455 455 /* 6pi/6 */ 456 ee_goto( x+1, y-1);457 ee_putstr( "____");458 ee_goto( x+1, y);459 ee_putstr( "____|");460 ee_color( EE_WHITE);461 ee_goto( x, y);462 ee_putchar( '<');456 ee_goto(x+1, y-1); 457 ee_putstr("____"); 458 ee_goto(x+1, y); 459 ee_putstr("____|"); 460 ee_color(EE_WHITE); 461 ee_goto(x, y); 462 ee_putchar('<'); 463 463 } 464 464 } … … 466 466 } 467 467 468 static void draw_fragbomb( int x, int y, int frame)469 { 470 ee_color( EE_WHITE);471 472 ee_color( frame & 1 ? EE_CYAN : EE_WHITE);473 ee_goto( x-2, y);474 ee_putstr( "( )");475 ee_goto( x-1, y+1);476 ee_putstr( "`--'");477 478 ee_color( frame & 1 ? EE_WHITE : EE_CYAN);479 ee_goto( x-1, y-1);480 ee_putstr( ",--.");481 ee_goto( x, y);482 ee_putstr( "',");483 484 switch( frame % 4)468 static void draw_fragbomb(int x, int y, int frame) 469 { 470 ee_color(EE_WHITE); 471 472 ee_color(frame & 1 ? EE_CYAN : EE_WHITE); 473 ee_goto(x-2, y); 474 ee_putstr("( )"); 475 ee_goto(x-1, y+1); 476 ee_putstr("`--'"); 477 478 ee_color(frame & 1 ? EE_WHITE : EE_CYAN); 479 ee_goto(x-1, y-1); 480 ee_putstr(",--."); 481 ee_goto(x, y); 482 ee_putstr("',"); 483 484 switch(frame % 4) 485 485 { 486 486 case 0: 487 ee_color( EE_CYAN);488 ee_goto( x, y + 2);489 ee_putchar( 'O');490 ee_goto( x + 2, y + 2);491 ee_putchar( 'o');492 ee_goto( x + 1, y + 3);493 ee_putchar( 'o');494 ee_color( EE_GRAY);495 ee_goto( x - 1, y + 3);496 ee_putchar( ':');497 ee_goto( x + 2, y + 4);498 ee_putchar( ':');499 ee_goto( x, y + 4);500 ee_putchar( '.');501 ee_goto( x + 1, y + 5);502 ee_putchar( '.');487 ee_color(EE_CYAN); 488 ee_goto(x, y + 2); 489 ee_putchar('O'); 490 ee_goto(x + 2, y + 2); 491 ee_putchar('o'); 492 ee_goto(x + 1, y + 3); 493 ee_putchar('o'); 494 ee_color(EE_GRAY); 495 ee_goto(x - 1, y + 3); 496 ee_putchar(':'); 497 ee_goto(x + 2, y + 4); 498 ee_putchar(':'); 499 ee_goto(x, y + 4); 500 ee_putchar('.'); 501 ee_goto(x + 1, y + 5); 502 ee_putchar('.'); 503 503 break; 504 504 case 1: 505 ee_color( EE_CYAN);506 //ee_goto( x, y + 1);507 //ee_putchar( 'O');508 ee_goto( x + 1, y + 2);509 ee_putchar( 'O');510 ee_goto( x, y + 3);511 ee_putchar( 'o');512 ee_color( EE_GRAY);513 ee_goto( x + 2, y + 3);514 ee_putchar( ':');515 ee_goto( x + 1, y + 4);516 ee_putchar( ':');517 ee_goto( x - 1, y + 4);518 ee_putchar( '.');519 ee_goto( x + 2, y + 5);520 ee_putchar( '.');505 ee_color(EE_CYAN); 506 //ee_goto(x, y + 1); 507 //ee_putchar('O'); 508 ee_goto(x + 1, y + 2); 509 ee_putchar('O'); 510 ee_goto(x, y + 3); 511 ee_putchar('o'); 512 ee_color(EE_GRAY); 513 ee_goto(x + 2, y + 3); 514 ee_putchar(':'); 515 ee_goto(x + 1, y + 4); 516 ee_putchar(':'); 517 ee_goto(x - 1, y + 4); 518 ee_putchar('.'); 519 ee_goto(x + 2, y + 5); 520 ee_putchar('.'); 521 521 break; 522 522 case 2: 523 ee_color( EE_CYAN);524 //ee_goto( x - 1, y + 1);525 //ee_putchar( 'O');526 ee_goto( x + 2, y + 2);527 ee_putchar( 'O');528 ee_goto( x, y + 2);529 ee_putchar( 'o');530 ee_goto( x + 1, y + 3);531 ee_putchar( 'o');532 ee_color( EE_GRAY);533 ee_goto( x, y + 4);534 ee_putchar( ':');535 ee_goto( x + 2, y + 4);536 ee_putchar( '.');537 ee_goto( x + 1, y + 5);538 ee_putchar( '.');523 ee_color(EE_CYAN); 524 //ee_goto(x - 1, y + 1); 525 //ee_putchar('O'); 526 ee_goto(x + 2, y + 2); 527 ee_putchar('O'); 528 ee_goto(x, y + 2); 529 ee_putchar('o'); 530 ee_goto(x + 1, y + 3); 531 ee_putchar('o'); 532 ee_color(EE_GRAY); 533 ee_goto(x, y + 4); 534 ee_putchar(':'); 535 ee_goto(x + 2, y + 4); 536 ee_putchar('.'); 537 ee_goto(x + 1, y + 5); 538 ee_putchar('.'); 539 539 break; 540 540 case 3: 541 ee_color( EE_CYAN);542 //ee_goto( x + 2, y + 1);543 //ee_putchar( 'O');544 ee_goto( x + 1, y + 2);545 ee_putchar( 'O');546 ee_goto( x - 1, y + 2);547 ee_putchar( 'o');548 ee_goto( x + 2, y + 3);549 ee_putchar( 'o');550 ee_color( EE_GRAY);551 ee_goto( x, y + 3);552 ee_putchar( ':');553 ee_goto( x + 1, y + 4);554 ee_putchar( ':');555 ee_goto( x, y + 5);556 ee_putchar( '.');541 ee_color(EE_CYAN); 542 //ee_goto(x + 2, y + 1); 543 //ee_putchar('O'); 544 ee_goto(x + 1, y + 2); 545 ee_putchar('O'); 546 ee_goto(x - 1, y + 2); 547 ee_putchar('o'); 548 ee_goto(x + 2, y + 3); 549 ee_putchar('o'); 550 ee_color(EE_GRAY); 551 ee_goto(x, y + 3); 552 ee_putchar(':'); 553 ee_goto(x + 1, y + 4); 554 ee_putchar(':'); 555 ee_goto(x, y + 5); 556 ee_putchar('.'); 557 557 break; 558 558 } 559 559 } 560 560 561 static void draw_beam( int x, int y, int frame)561 static void draw_beam(int x, int y, int frame) 562 562 { 563 563 int r = (29 - frame) * (29 - frame) / 8; 564 564 int i; 565 565 566 switch( frame)566 switch(frame) 567 567 { 568 568 case 24: 569 ee_color( EE_WHITE);570 ee_goto( x, y-3);571 ee_putstr( "__");572 ee_goto( x-1, y-2);573 ee_putchar( '\'');574 ee_goto( x+2, y-2);575 ee_putchar( '`');569 ee_color(EE_WHITE); 570 ee_goto(x, y-3); 571 ee_putstr("__"); 572 ee_goto(x-1, y-2); 573 ee_putchar('\''); 574 ee_goto(x+2, y-2); 575 ee_putchar('`'); 576 576 break; 577 577 case 23: 578 ee_color( EE_CYAN);579 ee_goto( x, y-3);580 ee_putstr( "__");581 ee_color( EE_WHITE);582 ee_goto( x-2, y-2);583 ee_putstr( "-'");584 ee_goto( x+2, y-2);585 ee_putstr( "`-");578 ee_color(EE_CYAN); 579 ee_goto(x, y-3); 580 ee_putstr("__"); 581 ee_color(EE_WHITE); 582 ee_goto(x-2, y-2); 583 ee_putstr("-'"); 584 ee_goto(x+2, y-2); 585 ee_putstr("`-"); 586 586 break; 587 587 case 22: 588 ee_color( EE_CYAN);589 ee_goto( x, y-3);590 ee_putstr( "__");591 ee_goto( x-1, y-2);592 ee_putchar( '\'');593 ee_goto( x+2, y-2);594 ee_putchar( '`');595 ee_color( EE_WHITE);596 ee_goto( x-3, y-2);597 ee_putstr( ",-");598 ee_goto( x+3, y-2);599 ee_putstr( "-.");588 ee_color(EE_CYAN); 589 ee_goto(x, y-3); 590 ee_putstr("__"); 591 ee_goto(x-1, y-2); 592 ee_putchar('\''); 593 ee_goto(x+2, y-2); 594 ee_putchar('`'); 595 ee_color(EE_WHITE); 596 ee_goto(x-3, y-2); 597 ee_putstr(",-"); 598 ee_goto(x+3, y-2); 599 ee_putstr("-."); 600 600 break; 601 601 case 21: 602 ee_color( EE_CYAN);603 ee_goto( x-1, y-3);604 ee_putstr( "____");605 ee_goto( x-2, y-2);606 ee_putchar( '\'');607 ee_goto( x+3, y-2);608 ee_putchar( '`');609 ee_color( EE_WHITE);610 ee_goto( x-4, y-2);611 ee_putstr( ",-");612 ee_goto( x+4, y-2);613 ee_putstr( "-.");602 ee_color(EE_CYAN); 603 ee_goto(x-1, y-3); 604 ee_putstr("____"); 605 ee_goto(x-2, y-2); 606 ee_putchar('\''); 607 ee_goto(x+3, y-2); 608 ee_putchar('`'); 609 ee_color(EE_WHITE); 610 ee_goto(x-4, y-2); 611 ee_putstr(",-"); 612 ee_goto(x+4, y-2); 613 ee_putstr("-."); 614 614 break; 615 615 case 20: 616 ee_color( EE_WHITE);617 ee_goto( x, y-3);618 ee_putstr( "%%");619 ee_goto( x-4, y-2);620 ee_putchar( ',');621 ee_goto( x+5, y-2);622 ee_putchar( '.');623 ee_color( EE_CYAN);624 ee_goto( x-1, y-3);625 ee_putchar( ':');626 ee_goto( x+2, y-3);627 ee_putchar( ':');628 ee_goto( x-3, y-2);629 ee_putstr( "-'");630 ee_goto( x+3, y-2);631 ee_putstr( "`-");616 ee_color(EE_WHITE); 617 ee_goto(x, y-3); 618 ee_putstr("%%"); 619 ee_goto(x-4, y-2); 620 ee_putchar(','); 621 ee_goto(x+5, y-2); 622 ee_putchar('.'); 623 ee_color(EE_CYAN); 624 ee_goto(x-1, y-3); 625 ee_putchar(':'); 626 ee_goto(x+2, y-3); 627 ee_putchar(':'); 628 ee_goto(x-3, y-2); 629 ee_putstr("-'"); 630 ee_goto(x+3, y-2); 631 ee_putstr("`-"); 632 632 break; 633 633 case 19: 634 ee_color( EE_WHITE);635 ee_goto( x, y-4);636 ee_putstr( "%%");637 ee_goto( x, y-3);638 ee_putstr( "##");639 ee_color( EE_CYAN);640 ee_goto( x-1, y-4);641 ee_putchar( ':');642 ee_goto( x+2, y-4);643 ee_putchar( ':');644 ee_goto( x-1, y-3);645 ee_putchar( '%');646 ee_goto( x+2, y-3);647 ee_putchar( '%');648 ee_goto( x-4, y-2);649 ee_putstr( ",-'");650 ee_goto( x+3, y-2);651 ee_putstr( "`-.");652 ee_color( EE_BLUE);653 ee_goto( x-2, y-3);654 ee_putchar( ':');655 ee_goto( x+3, y-3);656 ee_putchar( ':');634 ee_color(EE_WHITE); 635 ee_goto(x, y-4); 636 ee_putstr("%%"); 637 ee_goto(x, y-3); 638 ee_putstr("##"); 639 ee_color(EE_CYAN); 640 ee_goto(x-1, y-4); 641 ee_putchar(':'); 642 ee_goto(x+2, y-4); 643 ee_putchar(':'); 644 ee_goto(x-1, y-3); 645 ee_putchar('%'); 646 ee_goto(x+2, y-3); 647 ee_putchar('%'); 648 ee_goto(x-4, y-2); 649 ee_putstr(",-'"); 650 ee_goto(x+3, y-2); 651 ee_putstr("`-."); 652 ee_color(EE_BLUE); 653 ee_goto(x-2, y-3); 654 ee_putchar(':'); 655 ee_goto(x+3, y-3); 656 ee_putchar(':'); 657 657 break; 658 658 case 18: 659 659 default: 660 660 r = (18 - frame) * (18 - frame); 661 ee_color( EE_WHITE);662 ee_goto( x-1, y-5-r);663 ee_putstr( ":%%:");664 ee_goto( x-1, y-4-r);665 ee_putstr( "%##%");666 ee_color( EE_CYAN);667 ee_goto( x-2, y-4-r);668 ee_putchar( ':');669 ee_goto( x+3, y-4-r);670 ee_putchar( ':');671 ee_goto( x-2, y-2);672 ee_putchar( '\'');673 ee_goto( x+3, y-2);674 ee_putchar( '`');675 ee_color( EE_BLUE);676 ee_goto( x-3, y-2);677 ee_putchar( ':');678 ee_goto( x+4, y-2);679 ee_putchar( ':');680 for( i = 0; i <= r; i++)681 { 682 ee_color( EE_WHITE);683 ee_goto( x-1, y-3-i);684 ee_putstr( (i+frame) % 5 ? "####" : "%%%%");685 ee_color( EE_CYAN);686 ee_goto( x-2, y-3-i);687 ee_putchar( '%');688 ee_goto( x+3, y-3-i);689 ee_putchar( '%');690 ee_color( EE_BLUE);691 ee_goto( x-3, y-3-i);692 ee_putchar( ':');693 ee_goto( x+4, y-3-i);694 ee_putchar( ':');661 ee_color(EE_WHITE); 662 ee_goto(x-1, y-5-r); 663 ee_putstr(":%%:"); 664 ee_goto(x-1, y-4-r); 665 ee_putstr("%##%"); 666 ee_color(EE_CYAN); 667 ee_goto(x-2, y-4-r); 668 ee_putchar(':'); 669 ee_goto(x+3, y-4-r); 670 ee_putchar(':'); 671 ee_goto(x-2, y-2); 672 ee_putchar('\''); 673 ee_goto(x+3, y-2); 674 ee_putchar('`'); 675 ee_color(EE_BLUE); 676 ee_goto(x-3, y-2); 677 ee_putchar(':'); 678 ee_goto(x+4, y-2); 679 ee_putchar(':'); 680 for(i = 0; i <= r; i++) 681 { 682 ee_color(EE_WHITE); 683 ee_goto(x-1, y-3-i); 684 ee_putstr((i+frame) % 5 ? "####" : "%%%%"); 685 ee_color(EE_CYAN); 686 ee_goto(x-2, y-3-i); 687 ee_putchar('%'); 688 ee_goto(x+3, y-3-i); 689 ee_putchar('%'); 690 ee_color(EE_BLUE); 691 ee_goto(x-3, y-3-i); 692 ee_putchar(':'); 693 ee_goto(x+4, y-3-i); 694 ee_putchar(':'); 695 695 } 696 696 break; … … 698 698 } 699 699 700 static void draw_nuke( int x, int y, int frame)700 static void draw_nuke(int x, int y, int frame) 701 701 { 702 702 int r = (29 - frame) * (29 - frame) / 8; 703 703 704 704 /* Lots of duplicate pixels, but we don't care */ 705 ee_color( EE_BLUE);706 draw_circle( x, y, r++, ':');707 ee_color( EE_CYAN);708 draw_circle( x, y, r++, '%');709 ee_color( EE_WHITE);710 draw_circle( x, y, r++, '#');711 draw_circle( x, y, r++, '#');712 } 713 714 static void draw_circle( int x, int y, int r, char c)705 ee_color(EE_BLUE); 706 draw_circle(x, y, r++, ':'); 707 ee_color(EE_CYAN); 708 draw_circle(x, y, r++, '%'); 709 ee_color(EE_WHITE); 710 draw_circle(x, y, r++, '#'); 711 draw_circle(x, y, r++, '#'); 712 } 713 714 static void draw_circle(int x, int y, int r, char c) 715 715 { 716 716 int test, dx, dy; 717 717 718 718 /* Optimized Bresenham. Kick ass. */ 719 for( test = 0, dx = 0, dy = r ; dx <= dy ; dx++)720 { 721 ee_putcharTO( x + dx, y + dy / 2, c);722 ee_putcharTO( x - dx, y + dy / 2, c);723 ee_putcharTO( x + dx, y - dy / 2, c);724 ee_putcharTO( x - dx, y - dy / 2, c);725 726 ee_putcharTO( x + dy, y + dx / 2, c);727 ee_putcharTO( x - dy, y + dx / 2, c);728 ee_putcharTO( x + dy, y - dx / 2, c);729 ee_putcharTO( x - dy, y - dx / 2, c);719 for(test = 0, dx = 0, dy = r ; dx <= dy ; dx++) 720 { 721 ee_putcharTO(x + dx, y + dy / 2, c); 722 ee_putcharTO(x - dx, y + dy / 2, c); 723 ee_putcharTO(x + dx, y - dy / 2, c); 724 ee_putcharTO(x - dx, y - dy / 2, c); 725 726 ee_putcharTO(x + dy, y + dx / 2, c); 727 ee_putcharTO(x - dy, y + dx / 2, c); 728 ee_putcharTO(x + dy, y - dx / 2, c); 729 ee_putcharTO(x - dy, y - dx / 2, c); 730 730 731 731 test += test > 0 ? dx - dy-- : dx;
Note: See TracChangeset
for help on using the changeset viewer.