/* Here it is, compile with something like cc bugs.c -lgl -lm or whatever works */ /* * BUGS in 3D Verison 1.5 * * by David Barberi * Bugs and Predators live, die, eat and move around inside a World. * For the Personal Iris. * Send any Comments/Fixes/Hacks/Additions to: * dbarberi AT ibiblio DOT ORG * * * (c) David Barberi 08/12/91 * Permission to Copy and Modify is granted * as long as this notice is not removed. */ #include #include #include #define MAXBUGS 500 #define MAXPREDATORS 250 #define MAXTOTAL 750 #define WORLD_SIZE_X 500 #define WORLD_SIZE_Y 500 #define WORLD_SIZE_Z 500 #define MAX_BUG_SIZE 80 #define MIN_BUG_SIZE 4 #define MAX_BUG_SPEED 15 #define MIN_BUG_SPEED 0 #define BIRTH_SIZE 25 #define BIRTH_SPEED 5 #define PRED_BIRTH_SIZE 35 #define PRED_BIRTH_SPEED 9 #define CONTENT 0 /* For pred_mode[] */ #define HUNGRY 1 #define STARVING 2 #define AURA 25 /* Area around predator for eating */ #define MAX_PRED_SIZE 80 #define MIN_PRED_SIZE 8 #define MAX_PRED_SPEED 16 #define MIN_PRED_SPEED 3 long int loop, bug; long int bug_x[MAXTOTAL], bug_y[MAXTOTAL], bug_z[MAXTOTAL]; long int bug_size[MAXTOTAL], bug_speed[MAXTOTAL]; /* bug size, speed */ long int duration[MAXTOTAL], direction[MAXTOTAL]; /* Randomosity */ long int countdown[MAXTOTAL]; long int total_bugs, clicks=0, total=0, lucky, unlucky, ispeed=3; long int god, deaths=0, births=0; long int xfront, xback, yfront, yback, zfront, zback; long int rotate_mode, xfsplat, yfsplat, zfsplat; long int xbsplat, ybsplat, zbsplat; long int total_pred, pred, happy=0, hunger=0, starve=0; long int pred_mode[MAXPREDATORS]; long int food, aura_xf, aura_xb, aura_yf, aura_yb; long int aura_zf, aura_zb; long int pred_start, pred_end; char char_clicks[50], char_deaths[50], char_births[50], char_bug[25], char_population[50]; char char_total_pred[25]; long b0[3], b1[3], b2[3], b3[3], b4[3], b5[3], b6[3], b7[3]; long v0[3]={-WORLD_SIZE_X, -WORLD_SIZE_Y, -WORLD_SIZE_Z}; long v1[3]={-WORLD_SIZE_X, -WORLD_SIZE_Y, WORLD_SIZE_X}; long v2[3]={-WORLD_SIZE_X, WORLD_SIZE_Y, WORLD_SIZE_X}; long v3[3]={-WORLD_SIZE_X, WORLD_SIZE_Y, -WORLD_SIZE_Z}; long v4[3]={WORLD_SIZE_X, -WORLD_SIZE_Y, -WORLD_SIZE_Z}; long v5[3]={WORLD_SIZE_X, -WORLD_SIZE_Y, WORLD_SIZE_X}; long v6[3]={WORLD_SIZE_X, WORLD_SIZE_Y, WORLD_SIZE_X}; long v7[3]={WORLD_SIZE_X, WORLD_SIZE_Y, -WORLD_SIZE_Z}; char copyright_notice[]=" (c) 1991 by David Barberi "; /*************** da main thing *********/ main() { initialize(); while(!getbutton(ESCKEY)) { RGBcolor(15,15,15); /* dark grey */ clear(); play_god(); /* Mutate, grow/shrink, die, reproduciton */ draw_world(); /* draw a background.. big wire square */ draw_bugs(); /* draw the bugs inside the world */ draw_predators(); writenote(); swapbuffers(); clicks++; } gexit(); exit(); } /***********************************************************/ /**** draw_world() ***/ /***********************************************************/ draw_world() { /*if(clicks<150) translate(0,0,-18); */ input(); RGBcolor(255, 97, 217); linewidth(3); bgnline(); v3i(v0); v3i(v1); v3i(v2); v3i(v3); v3i(v0); v3i(v4); v3i(v5); v3i(v6); v3i(v7); v3i(v4); v3i(v5); v3i(v1); v3i(v2); v3i(v6); v3i(v7); v3i(v3); endline(); } /*************************** input() *****************************/ /*** Get input from the Keyboard to change view, pause, etc. ***/ /*******************************************************************/ input() { if(getbutton(MKEY)) { /* Press M to create another Predator */ total_pred++; get_correct_pred_count(); get_new_direction(pred_end); get_new_location(pred_end); bug_size[pred_end] = PRED_BIRTH_SIZE; bug_speed[pred_end] = PRED_BIRTH_SPEED; pred_mode[pred_end] = HUNGRY; } if(getbutton(F1KEY)) /* Press F1 to pause */ while(!getbutton(F2KEY)); ; /* Press F2 to unpause */ if(getbutton(RKEY)) { if(rotate_mode==TRUE) rotate_mode = FALSE; else rotate_mode = TRUE; } /* R toggels rotation mode ON/OFF */ if(rotate_mode==TRUE) { rot(ispeed, 'x'); rot(ispeed, 'y'); rot(ispeed, 'z'); } if(getbutton(ONEKEY)) ispeed =1; /* Number keys */ if(getbutton(TWOKEY)) ispeed =2; /* control the speed */ if(getbutton(THREEKEY)) ispeed =3; /* of movement */ if(getbutton(FOURKEY)) ispeed =4; if(getbutton(FIVEKEY)) ispeed = 5; if(getbutton(SIXKEY)) ispeed = 6; if(getbutton(SEVENKEY)) ispeed =7; if(getbutton(EIGHTKEY)) ispeed =8; if(getbutton(NINEKEY)) ispeed=9; if(getbutton(ZEROKEY)) ispeed = 10; if (getbutton(LEFTSHIFTKEY) || getbutton(RIGHTSHIFTKEY)) { if (getbutton(XKEY)) rot(-ispeed,'x'); if (getbutton(YKEY)) rot(-ispeed,'y'); if (getbutton(ZKEY)) rot(-ispeed,'z'); } else { if (getbutton(XKEY)) rot(ispeed,'x'); if (getbutton(YKEY)) rot(ispeed,'y'); if (getbutton(ZKEY)) rot(ispeed,'z'); if (getbutton(IKEY)) translate(0,0,ispeed); if (getbutton(OKEY)) translate(0,0,-ispeed); if (getbutton(UPARROWKEY)) translate(0,ispeed,0); if (getbutton(DOWNARROWKEY)) translate(0,-ispeed,0); if (getbutton(LEFTARROWKEY)) translate(ispeed,0,0); if (getbutton(RIGHTARROWKEY)) translate(-ispeed,0,0); } } /************************ play_god() *****************************/ /*** Grow, Shrink, reproduce, die ***/ /*******************************************************************/ play_god() { if(total_bugs==0) game_over(); if((rand()%5)!=4) { god=FALSE; return(0); } god=TRUE; /*** GROW ***/ lucky = (rand()%total_bugs); bug_size[lucky] += ((rand()%6) + 3); bug_speed[lucky] -= ((rand()%4) +2); /*** SHRINK ****/ unlucky = (rand()%total_bugs); bug_size[unlucky] -= ((rand()%5) +3 ); bug_speed[unlucky] += ((rand()%4) +2); if(bug_size[unlucky]<=MIN_BUG_SIZE) die(unlucky); if(bug_size[lucky]>=MAX_BUG_SIZE) birth(lucky); if(bug_speed[unlucky]<=MIN_BUG_SPEED) bug_speed[unlucky]=MIN_BUG_SPEED; if(bug_speed[lucky]>=MAX_BUG_SPEED) bug_speed[lucky]=MAX_BUG_SPEED; } /******************************** die() *****************************/ /**********************************************************************/ die(long int bug) { deaths++; if(bug==total_bugs) { total_bugs--; get_correct_pred_count(); return(0); } bug_x[bug] = bug_x[total_bugs]; bug_y[bug] = bug_y[total_bugs]; bug_z[bug] = bug_z[total_bugs]; bug_size[bug] = bug_size[total_bugs]; bug_speed[bug] = bug_speed[total_bugs]; direction[bug] = direction[total_bugs]; duration[bug] = duration[total_bugs]; countdown[bug] = countdown[total_bugs]; total_bugs--; get_correct_pred_count(); if(total_bugs==0) game_over(); } /*********************** birth() *************************************/ /*** Asexual Reproduction ***/ /***********************************************************************/ birth(long int parent) { births++; bug_size[parent] -= (30 + (rand()%30)); bug_speed[parent] -= (15 + (rand()%5)); total_bugs++; get_correct_pred_count(); bug_x[total_bugs] = bug_x[parent]; bug_y[total_bugs] = bug_y[parent]; bug_z[total_bugs] = bug_z[parent]; bug_size[total_bugs] = (BIRTH_SIZE + (rand()%10)); bug_speed[total_bugs] = (BIRTH_SPEED + (rand()%3)); direction[total_bugs] = direction[parent]; /* get_new_direction(total_bugs); */ countdown[total_bugs] = countdown[parent]; duration[total_bugs] = duration[parent]; } /******************** game_over() ******************************/ /*****************************************************************/ game_over() { /* draw_world(); writenote(); swapbuffers(); */ while(!getbutton(ESCKEY)) { RGBcolor(15,15,15); clear(); draw_world(); writenote(); pushmatrix(); ortho2(0.0,1024.0,0.0,768.0); cmov2(90.0, 200.0); RGBcolor(255, 255, 0); charstr(" GAME OVER.. ALL BUGS HAVE DIED.. ALL HAIL THE BUGS!"); cmov2(90.0, 150.0); charstr(" type ESC to end "); popmatrix(); swapbuffers(); } gexit(); exit(); } /************************** draw_bugs() ****************************/ /*** ***/ /***********************************************************************/ draw_bugs() { for(bug=0; bug < total_bugs; bug++) { countdown[bug]++; if(countdown[bug] > duration[bug]) get_new_direction(bug); get_direction(bug); splat_check(bug); /** Draw a white outline of the bug **/ /* b0[0] = xback; b0[1] = yback; b0[2] = zback; b1[0] = xback; b1[1] = yback; b1[2] = zfront; b2[0] = xback; b2[1] = yfront; b2[2] = zfront; b3[0] = xback; b3[1] = yfront; b3[2] = zback; b4[0] = xfront; b4[1] = yback; b4[2] = zback; b5[0] = xfront; b5[1] = yback; b5[2] = zfront; b6[0] = xfront; b6[1] = yfront; b6[2] = zfront; b7[0] = xfront; b7[1] = yfront; b7[2] = zback; RGBcolor(255,255,255); linewidth(8); bgnline(); v3i(b0); v3i(b1); v3i(b2); v3i(b3); v3i(b0); v3i(b4); v3i(b5); v3i(b6); v3i(b7); v3i(b4); v3i(b5); v3i(b1); v3i(b2); v3i(b6); v3i(b7); v3i(b3); endline(); */ /** Draw each side of the box as a filled polygon **/ RGBcolor(230, 143, 23); /* orangish */ pmvi(xback, yback, zback); pdri(xback, yback, zfront); /* xback */ pdri(xback, yfront, zfront); pdri(xback, yfront, zback); pclos(); RGBcolor(45, 5, 222); /* mild dark blue */ pmvi(xback, yback, zback); pdri(xback, yback, zfront); pdri(xfront, yback, zfront); /* yback */ pdri(xfront, yback, zback); pclos(); RGBcolor(39, 255,0); /* bright green */ pmvi(xback, yback, zback); pdri(xfront, yback, zback); /* zback */ pdri(xfront, yfront, zback); pdri(xback, yfront, zback); pclos(); RGBcolor(135, 171, 254); /* light blue */ pmvi(xfront, yback, zback); pdri(xfront, yback, zfront); /* xfront */ pdri(xfront, yfront, zfront); pdri(xfront, yfront, zback); pclos(); RGBcolor(255, 0, 255); /* bright purple */ pmvi(xback, yfront, zback); pdri(xback, yfront, zfront); /* yfront */ pdri(xfront, yfront, zfront); pdri(xfront, yfront, zback); pclos(); RGBcolor(0, 255, 255); /* light Turquoise */ pmvi(xback, yback, zfront); pdri(xfront, yback, zfront); /* zfront */ pdri(xfront, yfront, zfront); pdri(xback, yfront, zfront); pclos(); } } /************************** draw_predators() ***********************/ /*** ***/ /**********************************************************************/ draw_predators() { for(pred=pred_start; pred < pred_end; pred++) eat_anything(pred); for(pred=pred_start; pred < pred_end; pred++) { /* printf("draw_pred %i ", pred); */ if(bug_size[pred] > MAX_PRED_SIZE) bug_size[pred] = MAX_PRED_SIZE; if(bug_size[pred] < MIN_PRED_SIZE) bug_size[pred] = MIN_PRED_SIZE; /* pred_die(pred); */ if(bug_speed[pred] > MAX_PRED_SPEED) bug_speed[pred] = MAX_PRED_SPEED; if(bug_speed[pred] < MIN_PRED_SPEED) bug_speed[pred] = MIN_PRED_SPEED; countdown[pred]++; if(countdown[pred] > duration[pred]) get_new_direction(pred); get_direction(pred); splat_check(pred); if(pred_mode[pred] == CONTENT) { happy++; if((rand()%9)==2) bug_speed[pred] -= (rand()%4); if(happy >= 60) { pred_mode[pred] = HUNGRY; happy=0; } } if(pred_mode[pred] == HUNGRY) { hunger++; if((rand()%3)==1) bug_speed[pred] += (rand()%4); if(hunger >= 70) { pred_mode[pred] = STARVING; hunger=0; } } if(pred_mode[pred] == STARVING) { starve++; bug_speed[pred] += (rand()%2); if(starve >= 150) pred_die(pred); } /** Draw an outline of the predator **/ if(pred_mode[pred]==CONTENT) RGBcolor(255, 109, 113); else if(pred_mode[pred]==HUNGRY) RGBcolor(255,0,130); else RGBcolor(255,0,0); b0[0] = xback; b0[1] = yback; b0[2] = zback; b1[0] = xback; b1[1] = yback; b1[2] = zfront; b2[0] = xback; b2[1] = yfront; b2[2] = zfront; b3[0] = xback; b3[1] = yfront; b3[2] = zback; b4[0] = xfront; b4[1] = yback; b4[2] = zback; b5[0] = xfront; b5[1] = yback; b5[2] = zfront; b6[0] = xfront; b6[1] = yfront; b6[2] = zfront; b7[0] = xfront; b7[1] = yfront; b7[2] = zback; linewidth(2); bgnline(); v3i(b0); v3i(b1); v3i(b2); v3i(b3); v3i(b0); v3i(b4); v3i(b5); v3i(b6); v3i(b7); v3i(b4); v3i(b5); v3i(b1); v3i(b2); v3i(b6); v3i(b7); v3i(b3); endline(); aura_xf = bug_x[pred] + bug_size[pred] + AURA; aura_xb = bug_x[pred] - bug_size[pred] - AURA; aura_yf = bug_y[pred] + bug_size[pred] + AURA; aura_yb = bug_y[pred] - bug_size[pred] - AURA; aura_zf = bug_z[pred] + bug_size[pred] + AURA; aura_zb = bug_z[pred] - bug_size[pred] - AURA; /*** draw outline of predators AURA ***/ b0[0] = aura_xb; b0[1] = aura_yb; b0[2] = aura_zb; b1[0] = aura_xb; b1[1] = aura_yb; b1[2] = aura_zf; b2[0] = aura_xb; b2[1] = aura_yf; b2[2] = aura_zf; b3[0] = aura_xb; b3[1] = aura_yf; b3[2] = aura_zb; b4[0] = aura_xf; b4[1] = aura_yb; b4[2] = aura_zb; b5[0] = aura_xf; b5[1] = aura_yb; b5[2] = aura_zf; b6[0] = aura_xf; b6[1] = aura_yf; b6[2] = aura_zf; b7[0] = aura_xf; b7[1] = aura_yf; b7[2] = aura_zb; RGBcolor(197, 255, 83); bgnline(); v3i(b0); v3i(b1); v3i(b2); v3i(b3); v3i(b0); v3i(b4); v3i(b5); v3i(b6); v3i(b7); v3i(b4); v3i(b5); v3i(b1); v3i(b2); v3i(b6); v3i(b7); v3i(b3); endline(); } } /*********************** eat_anything() ************************/ /*** Predator looks around for a bug ***/ /*** and eats it if it's close enough ***/ /****************************************************************/ eat_anything(long int pred) { /* printf(" eat_anything pred=%i clicks=%i ", pred, clicks); */ for(food=0; food < total_bugs; food++) { if( (bug_x[food] < aura_xf) && (bug_x[food] > aura_xb) && (bug_y[food] < aura_yf) && (bug_y[food] > aura_yb) && (bug_z[food] < aura_zf) && (bug_z[food] > aura_zb) ) { pred_mode[pred] = CONTENT; bug_size[pred] += ((bug_size[food]*0.4)+(rand()%3)); bug_speed[pred] -= (rand()%3); duration[pred] += ((rand()%5) +10); die(food); /* printf(" *******eating bug %i \n", food); */ return(0); /* so you only eat one bug at a time */ } } /* printf(" END \n", pred, clicks); */ } /********************** pred_die() ********************************/ /******************************************************************/ pred_die(long int pred) { if(pred==total_pred) { total_pred--; get_correct_pred_count(); return(0); } bug_x[pred] = bug_x[total_pred]; bug_y[pred] = bug_y[total_pred]; bug_z[pred] = bug_z[total_pred]; bug_size[pred] = bug_size[total_pred]; bug_speed[pred] = bug_speed[total_pred]; direction[pred] = direction[total_pred]; duration[pred] = duration[total_pred]; countdown[pred] = countdown[total_pred]; total_pred--; get_correct_pred_count(); } /*********** get_correct_pred_count() *****************************/ /******************************************************************/ get_correct_pred_count() { pred_start = (total_bugs + 1 ); pred_end = (pred_start + total_pred); } /********************** splat_check() *******************************/ /*** Teleportation, Splatting ***/ /**********************************************************************/ splat_check(long int bug) { xfront = (bug_x[bug] + bug_size[bug]); yfront = (bug_y[bug] + bug_size[bug]); zfront = (bug_z[bug] + bug_size[bug]); xback = (bug_x[bug] - bug_size[bug]); yback = (bug_y[bug] - bug_size[bug]); zback = (bug_z[bug] - bug_size[bug]); xfsplat = xfront + 30; yfsplat = yfront + 30; zfsplat = zfront + 30; xbsplat = xback - 30; ybsplat = yback - 30; zbsplat = zback -30; /* if((bug_x[bug] > WORLD_SIZE_X) || (bug_x[bug] < -WORLD_SIZE_X) || (bug_y[bug] < -WORLD_SIZE_Y) || (bug_y[bug] > WORLD_SIZE_Y) || (bug_z[bug] < -WORLD_SIZE_Z) || (bug_z[bug] > WORLD_SIZE_Z) ) get_new_direction(bug); this will cause bugs to sometimes get caught outside box and flounder */ /* Teleport the bugs to the other side of the world and make a big Splat on the wall they teleported through */ if(bug_x[bug] > WORLD_SIZE_X ) { bug_x[bug] = (-WORLD_SIZE_X); RGBcolor(248, 0, 121); pmvi(WORLD_SIZE_X, yfsplat, zfsplat); pdri(WORLD_SIZE_X, yfsplat, zbsplat); pdri(WORLD_SIZE_X, ybsplat, zbsplat); pdri(WORLD_SIZE_X, ybsplat, zfsplat); pclos(); } if(bug_x[bug] < (-WORLD_SIZE_X) ) { bug_x[bug] = WORLD_SIZE_X; RGBcolor(248, 0, 121); pmvi(-WORLD_SIZE_X, yfsplat, zfsplat); pdri(-WORLD_SIZE_X, yfsplat, zbsplat); pdri(-WORLD_SIZE_X, ybsplat, zbsplat); pdri(-WORLD_SIZE_X, ybsplat, zfsplat); pclos(); } if(bug_y[bug] < (-WORLD_SIZE_Y)) { bug_y[bug] = WORLD_SIZE_Y; RGBcolor(248, 0, 121); pmvi( xfsplat, -WORLD_SIZE_Y, zfsplat); pdri( xfsplat, -WORLD_SIZE_Y, zbsplat); pdri( xbsplat, -WORLD_SIZE_Y, zbsplat); pdri( xbsplat, -WORLD_SIZE_Y, zfsplat); pclos(); } if(bug_y[bug] > WORLD_SIZE_Y) { bug_y[bug] = (-WORLD_SIZE_Y); RGBcolor(248, 0, 121); pmvi( xfsplat, WORLD_SIZE_Y, zfsplat); pdri( xfsplat, WORLD_SIZE_Y, zbsplat); pdri( xbsplat, WORLD_SIZE_Y, zbsplat); pdri( xbsplat, WORLD_SIZE_Y, zfsplat); pclos(); } if(bug_z[bug] < (-WORLD_SIZE_Z) ) { bug_z[bug] = WORLD_SIZE_Z; RGBcolor(248, 0, 121); pmvi( xfsplat, yfsplat, -WORLD_SIZE_Z); pdri( xfsplat, ybsplat, -WORLD_SIZE_Z); pdri( xbsplat, ybsplat, -WORLD_SIZE_Z); pdri( xbsplat, yfsplat, -WORLD_SIZE_Z); pclos(); } if(bug_z[bug] > WORLD_SIZE_Z) { bug_z[bug] = (-WORLD_SIZE_Z); RGBcolor(248, 0, 121); pmvi( xfsplat, yfsplat, WORLD_SIZE_Z); pdri( xfsplat, ybsplat, WORLD_SIZE_Z); pdri( xbsplat, ybsplat, WORLD_SIZE_Z); pdri( xbsplat, yfsplat, WORLD_SIZE_Z); pclos(); } } /************************** get_direction() ***************************/ /*** move in one of 25 x,y,z directions ***/ /***********************************************************************/ get_direction(long int bug) { if(direction[bug]==0) { bug_x[bug] += bug_speed[bug]; } if(direction[bug]==1) { bug_x[bug] -= bug_speed[bug]; } if(direction[bug]==2) { bug_y[bug] += bug_speed[bug]; } if(direction[bug]==3) { bug_y[bug] -= bug_speed[bug]; } if(direction[bug]==4) { bug_z[bug] += bug_speed[bug]; } if(direction[bug]==5) { bug_z[bug] -= bug_speed[bug]; } if(direction[bug]==6) { bug_x[bug] += bug_speed[bug]; bug_y[bug] += bug_speed[bug]; } if(direction[bug]==7) { bug_x[bug] += bug_speed[bug]; bug_z[bug] += bug_speed[bug]; } if(direction[bug]==8) { bug_x[bug] += bug_speed[bug]; bug_y[bug] -= bug_speed[bug]; } if(direction[bug]==9) { bug_x[bug] += bug_speed[bug]; bug_z[bug] -= bug_speed[bug]; } if(direction[bug]==10) { bug_x[bug] -= bug_speed[bug]; bug_y[bug] += bug_speed[bug]; } if(direction[bug]==11) { bug_x[bug] -= bug_speed[bug]; bug_z[bug] += bug_speed[bug]; } if(direction[bug]==12) { bug_x[bug] -= bug_speed[bug]; bug_y[bug] -= bug_speed[bug]; } if(direction[bug]==13) { bug_x[bug] -= bug_speed[bug]; bug_z[bug] -= bug_speed[bug]; } if(direction[bug]==14) { bug_y[bug] += bug_speed[bug]; bug_z[bug] += bug_speed[bug]; } if(direction[bug]==15) { bug_y[bug] += bug_speed[bug]; bug_z[bug] -= bug_speed[bug]; } if(direction[bug]==16) { bug_y[bug] -= bug_speed[bug]; bug_z[bug] += bug_speed[bug]; } if(direction[bug]==17) { bug_y[bug] -= bug_speed[bug]; bug_z[bug] -= bug_speed[bug]; } if(direction[bug]==18) { bug_x[bug] += bug_speed[bug]; bug_y[bug] += bug_speed[bug]; bug_z[bug] += bug_speed[bug]; } if(direction[bug]==19) { bug_x[bug] += bug_speed[bug]; bug_y[bug] += bug_speed[bug]; bug_z[bug] -= bug_speed[bug]; } if(direction[bug]==20) { bug_x[bug] += bug_speed[bug]; bug_y[bug] -= bug_speed[bug]; bug_z[bug] += bug_speed[bug]; } if(direction[bug]==21) { bug_x[bug] += bug_speed[bug]; bug_y[bug] -= bug_speed[bug]; bug_z[bug] -= bug_speed[bug]; } if(direction[bug]==22) { bug_x[bug] -= bug_speed[bug]; bug_y[bug] += bug_speed[bug]; bug_z[bug] += bug_speed[bug]; } if(direction[bug]==23) { bug_x[bug] -= bug_speed[bug]; bug_y[bug] += bug_speed[bug]; bug_z[bug] -= bug_speed[bug]; } if(direction[bug]==24) { bug_x[bug] -= bug_speed[bug]; bug_y[bug] -= bug_speed[bug]; bug_z[bug] += bug_speed[bug]; } if(direction[bug]==25) { bug_x[bug] -= bug_speed[bug]; bug_y[bug] -= bug_speed[bug]; bug_z[bug] -= bug_speed[bug]; } } /******************* get_new_direction() ***************************/ /*******************************************************************/ get_new_direction(long int bug) { duration[bug]=( (rand()%30) + 30 ); direction[bug]=( rand()%26 ); countdown[bug]=0; } /******************** get_new_location() ***************************/ /*******************************************************************/ get_new_location(long int bug) { bug_x[bug] = ((rand()%(WORLD_SIZE_X *2)) - WORLD_SIZE_X); bug_y[bug] = ((rand()%(WORLD_SIZE_Y *2)) - WORLD_SIZE_Y); bug_z[bug] = ((rand()%(WORLD_SIZE_Z *2)) - WORLD_SIZE_Z); } /********************* initialize() ******************************/ /**** Create Bugs, Predators. Initialize Graphics ****/ /*******************************************************************/ initialize() { printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"); printf(" Welcome to 3D Bugs \n\n By David Barberi \n\n"); printf(" How many Bugs to start? "); scanf("%d", &total_bugs); printf("\n\n How many Predators? "); scanf("%d", &total_pred); if(total_bugs <= 0) { printf("\n\n No Bugs means No Fun \n\n"); /* exit(1); */ } if(total_bugs >= MAXBUGS) { printf("\n\n You have exceeded the Bug Limit!!!! \n\n"); exit(1); } /* Give birth to the bugs */ for(bug=0; bug<=total_bugs; bug++) { get_new_direction(bug); get_new_location(bug); bug_size[bug]= (BIRTH_SIZE + (rand()%9)); bug_speed[bug]= (BIRTH_SPEED + (rand()%4)); } /* Give birth to the Predators */ /* total_pred = (total_bugs * 0.1); */ /* if(total_pred <=0) total_pred=1; */ if(total_pred >= MAXPREDATORS) total_pred = MAXPREDATORS; /** Predators are saved in the bug..[] hierarchy **/ get_correct_pred_count(); for(pred=pred_start; pred <= pred_end; pred++) { get_new_direction(pred); get_new_location(pred); bug_size[pred] = PRED_BIRTH_SIZE; bug_speed[pred] = PRED_BIRTH_SPEED; pred_mode[pred] = HUNGRY; } /*** Initialize graphics ****/ keepaspect(1,1); prefposition(20, 990, 20, 990); winopen("Bugs"); doublebuffer(); RGBmode(); gconfig(); /* zbuffer(TRUE); mmode(MVIEWING); */ perspective(300.0, 1.0, 0.000001, 600.0); polarview(100.0, 0.0, 0.0, 0.0); translate(0.0, 0.0, -2700.0); } /****************************************************************/ /* Place stationary text on the screen */ /****************************************************************/ writenote() { sprintf(char_clicks, "%d", clicks); sprintf(char_deaths, "%d", deaths); sprintf(char_births, "%d", births); sprintf(char_population, "%d", total_bugs); sprintf(char_total_pred, "%d", total_pred); pushmatrix(); ortho2(0.0,1024.0,0.0,768.0); cmov2(10.0,30.0); RGBcolor(255,255,255); charstr(" BUGS -- By David Barberi "); charstr(" Type 'Esc' to quit"); cmov2(35.0, 60.0); charstr(" clicks ="); RGBcolor(255,255,0); charstr(char_clicks); RGBcolor(255,255,255); charstr(" # of bugs ="); RGBcolor(255,255,0); charstr(char_population); RGBcolor(255,255,255); charstr(" # of births ="); RGBcolor(255,255,0); charstr(char_births); RGBcolor(255,255,255); charstr(" # of deaths ="); RGBcolor(255,255,0); charstr(char_deaths); RGBcolor(255,255,255); charstr(" # of Predators ="); RGBcolor(255,255,0); charstr(char_total_pred); if(god==TRUE) charstr(" Playing GOD"); popmatrix(); } /*** finis ***/ What the?