Ignore:
Timestamp:
Dec 13, 2002, 8:27:16 PM (20 years ago)
Message:
• moved nuke from explosions to weapons.
• used a cool Bresenham algorithm to draw the nuke circles.
• nuke collides with aliens.
Location:
Files:
6 edited

Legend:

Unmodified
Removed

 r12 int i; for( i = 0; i < SHOTS; i++ ) for( i = 0; i < WEAPONS; i++ ) { if( wp->y[i] >= 0 ) int i, j; for( i = 0; i < SHOTS; i++ ) for( i = 0; i < WEAPONS; i++ ) { if( wp->y[i] >= 0 ) { int ok = 0; int r; for( j = 0; j < ALIENS; j++ ) switch( wp->type[i] ) { if( wp->x[i] >= al->x[j] && wp->x[i] <= al->x[j] + 4 && wp->y[i] >= al->y[j] && wp->y[i] <= al->y[j] + 2 ) case 2: /* Big nuke */ r = (34 - wp->n[i]) * (34 - wp->n[i]) / 10; for( j = 0; j < ALIENS; j++ ) { al->life[j]--; if( al->life[j] == 0 ) if( al->x[j] < 0 ) { continue; } if( (al->x[j] - wp->x[i]) * (al->x[j] - wp->x[i]) + 4 * (al->y[j] - wp->y[i]) * (al->y[j] - wp->y[i]) <= r * r ) { /* Kill alien, not nuke */ add_explosion( g, ex, al->x[j], al->y[j], 0, 0, 1 ); al->x[j] = -1; al->y[j] = -1; add_explosion( g, ex, wp->x[i], wp->y[i], 0, 0, 1 ); } ok = 1; } else if( wp->x[i] >= al->x[j] && wp->x[i] <= al->x[j] + 4 && wp->y[i]+1 >= al->y[j] && wp->y[i]+1 <= al->y[j] + 2 ) break; case 1: default: for( j = 0; j < ALIENS; j++ ) { al->life[j]--; if( al->life[j] == 0 ) if( wp->x[i] >= al->x[j] && wp->x[i] <= al->x[j] + 4 && wp->y[i] >= al->y[j] && wp->y[i] <= al->y[j] + 2 ) { al->x[j] = -1; al->y[j] = -1; add_explosion( g, ex, wp->x[i], wp->y[i]+1, 0, 0, 1 ); al->life[j]--; if( al->life[j] == 0 ) { al->x[j] = -1; al->y[j] = -1; add_explosion( g, ex, wp->x[i], wp->y[i], 0, 0, 1 ); } ok = 1; } ok = 1; else if( wp->x[i] >= al->x[j] && wp->x[i] <= al->x[j] + 4 && wp->y[i]+1 >= al->y[j] && wp->y[i]+1 <= al->y[j] + 2 ) { al->life[j]--; if( al->life[j] == 0 ) { al->x[j] = -1; al->y[j] = -1; add_explosion( g, ex, wp->x[i], wp->y[i]+1, 0, 0, 1 ); } ok = 1; } } } if( ok ) { wp->y[i] = -1; if( ok ) { wp->y[i] = -1; } break; } }

 r12 #define STARS 50 #define SHOTS 50 #define WEAPONS 50 #define ROCKS 10 #define ALIENS 10 #   define GFX_WRITE(x) addch(x) #endif #define GFX_WRITETO(x,y,c) do{ GFX_GOTO(x,y); GFX_WRITE(c); }while(0) #define GET_RAND(p,q) ((p)+(int)((1.0*((q)-(p)))*rand()/(RAND_MAX+1.0))) typedef struct { int x[SHOTS]; int y[SHOTS]; int v[SHOTS]; int x[WEAPONS]; int y[WEAPONS]; int v[WEAPONS]; int n[WEAPONS]; int type[WEAPONS]; } weapons; int x, y; int dir; int weapon; int weapon, nuke; } player; void draw_weapons( game *g, weapons *wp ); void update_weapons( game *g, weapons *wp ); void add_weapon( game *g, weapons *wp, int x, int y ); void add_weapon( game *g, weapons *wp, int x, int y, int type ); void init_starfield( game *g, starfield *s );