/* * CSE142, Spring 2000 * Homework 4 * Idyllic landscape animation- converted to ********Spock's Pon Farr Battle Simulation Game******** Zach Adam Homework 4 Section AI This is a computer simulation game of Spock's Pon Farr mating battle with Kirk from Star Trek. The buttons 'Beam Kirk' and 'Beam Spock' can be used to beam either respective character in or out of the scene at any time. Pon Farr, however, can't be turned off because it's part of the natural Vulcan biological cycle. Once it has begun it doesn't stop until Spock is killed or kills his rival opponent in mating, which in this case as in the episode is Captain Kirk. When 'Pon Farr' is activated, Spock will go crazy waving around one of the weapons and Kirk will defend himself at this point with another of the weapons. This will continue until one of the characters is stabbed, but because this is a family game, the Enterprise beams out the loser just as this happens so he can be treated onboard the ship, and Spock is then cured until the next Pon Farr occurence. * * */ #include "gp142.h" #include #include #include /* * is included so the current time can be accessed * to initialize the random number generator. If you don't * use random numbers (and you don't have to) you can either * ignore this #include or delete it. */ /* Logical constants */ #define TRUE 1 #define FALSE 0 /* * For many of the GP142 functions, a line width of * zero means to fill the shape being drawn. The * constant FILL is used in function calls when a solid * shape is desired. */ #define FILL 0 /* * Symbolic constants. Change as needed. */ /* Menu buttons: */ /* Top-left coordinates of button palette */ #define MENU_TOP (GP142_YMAX - 5) #define MENU_LEFT (-GP142_XMAX + 5) /* Height and width of buttons in pixels */ #define BUTTON_HEIGHT 25 #define BUTTON_WIDTH 100 /* Number of buttons */ #define NUM_BUTTONS 3 /* Possible locations of mouse clicks: */ /* Mouse click in some button */ #define BUTTON_CLICK 1 /* Mouse click elsewhere */ #define OTHER_CLICK 0 /* Coordinates of objects in the drawing */ /* y-coordinate of the top of the ground in the landscape */ #define HORIZON (- 2 * (GP142_YMAX / 10)) /* Other constants pertaining to objects in the scene */ #define MOON_RADIUS 20 #define MOON_FULLNESS 2.5 #define MAX_STAR_RADIUS 4 #define MAX_BUG_SIZE 10 /***************************************************************************** FUNCTION PROTOTYPES *****************************************************************************/ /* Initialize random number generator. [Ignore or */ /* remove if your program doesn't use random numbers.] */ void initialize_random_numbers(); /* Initializes the moon parameters */ void init_moon(int *moon_x, int *moon_y); /*Move the enterprise*/ void move_ent(int *ent_x, int *ent_y) { /* Move the moon to the left. If it reaches the edge, move it */ /* to the other side and down a bit. */ (*ent_x) ++; if (*ent_x > GP142_XMAX + 150) { *ent_x = - (GP142_XMAX); } } /*make the light on the enterprise hull blink*/ void ent_light_blink(int *ent_light){ *ent_light = (rand() % 2); } /* Make the people(s) wander around */ void move_person(int *person_x, int *person_y) { *person_x = *person_x + rand() % 3 - 1; *person_y = *person_y + rand() % 3 - 1; } /*a function to make the chosen person beam in or out of the scene*/ int beam_person(int *person_x, int *person_y){ int i = 0, color = YELLOW; for(i = 0; i< 200; i = i + 1){ GP142_lineXY(color, *person_x, *person_y, *person_x, *person_y - 17, 20); GP142_ovalXY(color, *person_x - 8, *person_y + 10, *person_x + 8, *person_y + 30, FILL); GP142_lineXY(color, *person_x - 5, *person_y - 25, *person_x - 5, *person_y - 50, 7); GP142_lineXY(color, *person_x + 5, *person_y - 25, *person_x + 5, *person_y - 50, 7); GP142_lineXY(color, *person_x - 5, *person_y - 22, *person_x + 5, *person_y - 22, 10); GP142_lineXY(color, *person_x - 5, *person_y + 27, *person_x + 5, *person_y + 27, 7); GP142_lineXY(color, *person_x + 10, *person_y + 5, *person_x + 14, *person_y - 13, 4); GP142_lineXY(color, *person_x - 10, *person_y + 5, *person_x - 14, *person_y - 13, 4); } return (TRUE); } /*a function that changes the beaming status to non-done or 'FALSE', indicating that on the next cycle through, main must initiate beaming sequence. After completing the beam cycle, the value 'FALSE' is returned to the value of 'beam_person_done, indicating to stop the beam sequence */ void beam_switch(int *beam_person_done, int *person){ if(*person == TRUE){ *person = FALSE;} else *person = TRUE; *beam_person_done = FALSE; } /*This is the function that initiates the characteristics of the Pon Farr phase of the game. The random 'saber' values indicate the x and y lengths of the sabers that each character holds. The function also sets each character moving slowly toward each other in a 'duel' manner. The conditionals at the bottom allow the pon_farr mode to continue until one of the sabers crosses the x-location of the opposite opponent. At this point, the 'beam status' of the opposing character is changed to false, initiating the beaming sequence in time to save the character to battle another day, and in any case curing Spock of his Pon Farr mating drive until it is initiated again. also, Kirk is given a slighly larger x value for his battle saber to account for the fact that Spock's success is checked first in the conditional statements below and statistically he would therefore tend to win more often.*/ int Pon_Farr(int *spock_x, int *spock_y, int *Spock, int *beam_spock_done, int *kirk_x, int *kirk_y, int *Kirk, int *beam_kirk_done){ int saber_rand_1, saber_rand_2, saber_rand_3, saber_rand_4; saber_rand_1 = (rand() % 50); saber_rand_2 = (rand() % 50); saber_rand_3 = (rand() % 50); saber_rand_4 = (rand() % 50); /*indictations of Spock's Pon Farr mating condition- two red ears, a red face, and his usual black bowl-cut over top of it*/ GP142_lineXY(RED, *spock_x - 8, *spock_y + 20, *spock_x - 11, *spock_y + 24, 2); GP142_lineXY(RED, *spock_x + 8, *spock_y + 20, *spock_x + 11, *spock_y + 24, 2); GP142_ovalXY(RED, *spock_x - 8, *spock_y + 10, *spock_x + 8, *spock_y + 30, FILL); GP142_lineXY(BLACK, *spock_x - 5, *spock_y + 27, *spock_x + 5, *spock_y + 27, 7); /*saber drawings for each player referenced from his position*/ GP142_lineXY(LT_GRAY, *spock_x + 14, *spock_y - 13, *spock_x + saber_rand_1, *spock_y + saber_rand_2, 3); GP142_lineXY(LT_GRAY, *kirk_x - 14, *kirk_y - 13, *kirk_x - saber_rand_3 - 4, *kirk_y + saber_rand_4, 3); /*duel movements- spock to the left, kirk to the right*/ *spock_x = *spock_x + 2 ; *kirk_x = *kirk_x - 2; /*the success conditionals to test if the game is over and a character must be beamed*/ if((*spock_x + 14 + saber_rand_1) > (*kirk_x - 10)){ beam_switch(beam_kirk_done, Kirk); return FALSE; } if((*kirk_x - 14 - saber_rand_3) < (*spock_x + 10)){ beam_switch(beam_spock_done, Spock); return FALSE; } return TRUE; } /* Draw the background, including the moon at coordinates moon_x and moon_y, the stars */ /* the tree, the flower(s), the boat, and the bug(s) */ void draw_landscape(int moon_x, int moon_y, int star_x, int star_y, int star_radius, int star_color, int star2_x, int star2_y, int star2_radius, int star2_color, int ent_x, int ent_y, int ent_light, int spock_x, int spock_y, int Spock, int *beam_spock_done, int kirk_x, int kirk_y, int Kirk, int *beam_kirk_done, int *pon_farr); /* Make stars blink */ void blink_star(int *star_radius, int *star_color); /* Update moon coordinates moon_x, moon_y for one tick */ void move_moon(int *moon_x, int *moon_y); /* Draw buttons */ void draw_buttons(void); /* Return kind of mouse click (in a button, etc.) */ int classify_mouse_click(int mouse_x, int mouse_y); /* Process button click at location x, y. React appropriately, depending on the requested event */ void handle_button(int x, int y, int *Spock, int *beam_spock_done, int *Kirk, int *beam_kirk_done, int *pon_farr); /* Display error message if internal error is detected. */ void something_is_wrong (void); /***************************************************************************** MAIN *****************************************************************************/ /* * Main program contents: * - Major program variables that persist throughout execution * - Event loop that processes GP142 events until the user quits, * and updates variables and redraws the window as needed. */ int main(void) { /* Event handling and buttons: */ int quit; /* = "user has selected quit" */ int event; /* the most recent GP142 event */ char key_pressed; /* last keyboard character from key event */ int mouse_x, mouse_y; /* x and y coordinates of latest mouse event*/ int click_kind; /* kind of mouse click (button, etc.) */ /* Information about the moon and stars: */ int moon_x, moon_y; /* screen x and y coordinates */ int star_x, star_y; /* screen x and y coordinates */ int star_radius, star_color; /* radius and color of a star */ int star2_x, star2_y; /* screen x and y coordinates */ int star2_radius, star2_color; /* radius and color of another star */ /*information about the enterprise*/ int ent_x, ent_y, ent_light = 0; /*information about Spock*/ int Spock = FALSE; /*Initially, Spock is not in picture, i.e. FALSE*/ int spock[] = {-150, HORIZON - 100}; int beam_spock_done = TRUE; /*information about kirk*/ int Kirk = FALSE; int kirk[] = {150, HORIZON - 100}; int beam_kirk_done = TRUE; /*information concerning the condition of Spock's Pon Farr*/ int pon_farr = FALSE; /* Initialize random number generator */ initialize_random_numbers(); /* Initialize graphics package, clear the window, */ /* turn logging off, and start animation. */ GP142_open(); GP142_logging(LOG_OFF); GP142_clear(); GP142_animate(ANI_RUN); /* set initial location of the moon */ init_moon(&moon_x, &moon_y); /* set initial location of the stars */ star_x = GP142_XMAX - 200; star_y = GP142_YMAX - 90; star_radius = 3; star_color = WHITE; star2_x = -GP142_XMAX + 150; star2_y = GP142_YMAX - 80; star2_radius = 2; star2_color = YELLOW; /*set initial conditions for the enterprise*/ ent_x = GP142_XMAX - 50; ent_y = GP142_YMAX - 50; /* Draw initial landscape, buttons, and traffic */ draw_landscape(moon_x,moon_y, star_x, star_y, star_radius, star_color, star2_x, star2_y, star2_radius, star2_color, ent_x, ent_y, ent_light, spock[0], spock[1], Spock, &beam_spock_done, kirk[0], kirk[1], Kirk, &beam_kirk_done, &pon_farr); draw_buttons(); /* * Main event loop: * ---- ----- ----- * Wait for the next user action, decode it, and call an * appropriate function to handle it. Repeat until the * user selects quit. */ quit = FALSE; while (!quit) { /* get next event */ event = GP142_await_event(&mouse_x, &mouse_y, &key_pressed); /* perform appropriate action depending on kind of event */ switch (event) { case GP142_QUIT: /* Quit selected */ quit = TRUE; break; case GP142_KBD: /* Key pressed. Not used now. If the program should */ /* react to keyboard events, insert something appropriate */ /* here. Note that scanf CANNOT be used with GP142. */ break; case GP142_MOUSE: /* Mouse click. Determine if in a menu button */ /* or elsewhere and process accordingly. */ click_kind = classify_mouse_click(mouse_x, mouse_y); if (click_kind == BUTTON_CLICK) { handle_button(mouse_x, mouse_y, &Spock, &beam_spock_done, &Kirk, &beam_kirk_done, &pon_farr); } else { /* insert code here (and additional else-if statements) */ /* to react to mouse clicks elsewhere on the screen (if needed) */ } break; case GP142_PERIODIC: /* Timer interval event. Update everything that needs the change */ /* as time advances. Animation should go here! */ draw_landscape(moon_x, moon_y, star_x, star_y, star_radius, star_color, star2_x, star2_y, star2_radius, star2_color, ent_x, ent_y, ent_light, spock[0], spock[1], Spock, &beam_spock_done, kirk[0], kirk[1], Kirk, &beam_kirk_done, &pon_farr); move_moon(&moon_x, &moon_y); move_ent(&ent_x, &ent_y); blink_star(&star_radius, &star_color); blink_star(&star2_radius, &star2_color); ent_light_blink(&ent_light); /*the following conditionals move the characters Spock and Kirk after checking that either is on the screen*/ if(Spock == TRUE){ move_person(&spock[0], &spock[1]); } if(Kirk == TRUE){ move_person(&kirk[0], &kirk[1]); } /*these conditionals set the appropriate startup positions for Spock and Kirk if they are being beamed in for a following time after their initial appearences*/ if((Spock == FALSE) && (beam_spock_done == TRUE)){ spock[0] = -150; spock[1] = HORIZON - 100; } if((Kirk == FALSE) && (beam_kirk_done == TRUE)){ kirk[0] = 150; kirk[1] = HORIZON - 100; } break; default: /* unknown event */ break; } /*end switch */ /* Redraw everything */ /*if, at some point throughout the program, a call has been made to beam up/down one of the characters, it will be picked up here by either of these conditionals*/ if(beam_spock_done == FALSE){ beam_spock_done = beam_person(&spock[0], &spock[1]); } if(beam_kirk_done == FALSE){ beam_kirk_done = beam_person(&kirk[0], &kirk[1]); } if((Kirk == TRUE) && (Spock == TRUE)){ if(pon_farr == TRUE){ pon_farr = Pon_Farr(&spock[0], &spock[1], &Spock, &beam_spock_done, &kirk[0], &kirk[1], &Kirk, &beam_kirk_done); } } draw_buttons(); } /* end event loop */ /* Termination: shut down graphics window and exit */ GP142_close(); return 0; } /* end main */ /***************************************************************************** INITIALIZATION PROCEDURES *****************************************************************************/ /* Initializes the moon parameters */ void init_moon(int *moon_x, int *moon_y) { *moon_x = GP142_XMAX - 50; *moon_y = GP142_YMAX - 35; } /* Initialize other objects and their parameters here - tree, bug, etc. */ /* ... */ /***************************************************************************** BACKGROUND LANDSCAPE *****************************************************************************/ /* Draw the background, including the moon at coordinates moon_x and moon_y and stars */ void draw_landscape(int moon_x, int moon_y, int star_x, int star_y, int star_radius, int star_color, int star2_x, int star2_y, int star2_radius, int star2_color, int ent_x, int ent_y, int ent_light, int spock_x, int spock_y, int Spock, int *beam_spock_done, int kirk_x, int kirk_y, int Kirk, int *beam_kirk_done, int *pon_farr) { int text_offset = -GP142_XMAX + 15; /* horizontal offset of text */ int text_size = 12; /* size of text font */ int i = 0; /* Draw the sky */ GP142_rectangleXY(PURPLE, -GP142_XMAX, -GP142_YMAX, GP142_XMAX, GP142_YMAX, FILL); /* Draw the moon */ GP142_circleXY(WHITE, moon_x, moon_y, MOON_RADIUS); GP142_ovalXY(PURPLE, moon_x, moon_y - MOON_RADIUS, moon_x + (int)(MOON_FULLNESS * MOON_RADIUS), moon_y + MOON_RADIUS, FILL); /*Draw the enterprise*/ GP142_ovalXY(LT_GRAY, ent_x, ent_y, ent_x - 100, ent_y + 15, FILL); GP142_lineXY(LT_GRAY, ent_x - 75, ent_y + 9, ent_x - 95, ent_y - 15, 6); GP142_lineXY(LT_GRAY, ent_x - 115, ent_y + 6, ent_x - 150, ent_y + 6, 5); GP142_lineXY(LT_GRAY, ent_x - 95, ent_y - 16, ent_x - 125, ent_y - 16, 9); GP142_circleXY(ent_light, ent_x - 50, ent_y, 1); GP142_lineXY(LT_GRAY, ent_x - 110, ent_y - 16, ent_x - 120, ent_y + 6, 3); /* Draw stars */ GP142_triangleXY(star_color, star_x, star_y + star_radius, star_x + (int)(star_radius * 0.87), star_y - (int) (star_radius / 2.0), star_x - (int)(star_radius * 0.87), star_y - (int) (star_radius / 2.0), FILL); GP142_triangleXY(star_color, star_x, star_y - star_radius, star_x - (int)(star_radius * 0.87), star_y + (int) (star_radius / 2.0), star_x + (int)(star_radius * 0.87), star_y + (int) (star_radius / 2.0), FILL); GP142_triangleXY(star2_color, star2_x, star2_y + star2_radius, star2_x + (int)(star2_radius * 0.87), star2_y - (int) (star2_radius / 2.0), star2_x - (int)(star2_radius * 0.87), star2_y - (int) (star2_radius / 2.0), FILL); GP142_triangleXY(star2_color, star2_x, star2_y - star2_radius, star2_x - (int)(star2_radius * 0.87), star2_y + (int) (star2_radius / 2.0), star2_x + (int)(star2_radius * 0.87), star2_y + (int) (star2_radius / 2.0), FILL); /* Draw mountains */ GP142_triangleXY(MED_GRAY, -GP142_XMAX, HORIZON, GP142_XMAX, HORIZON, -GP142_XMAX / 3, (3 * GP142_YMAX)/6, FILL); GP142_triangleXY(BROWN, -GP142_XMAX, HORIZON, GP142_XMAX, HORIZON, GP142_XMAX / 4, (2 * GP142_YMAX)/6, FILL); GP142_triangleXY(RED, -( 5 * GP142_XMAX/4), HORIZON, (GP142_XMAX)/3 , HORIZON, -(3 * GP142_XMAX)/4, (2 * GP142_YMAX)/6 , FILL); GP142_triangleXY(BROWN, -GP142_XMAX / 3 , HORIZON, GP142_XMAX, HORIZON, GP142_XMAX, (2 * GP142_YMAX)/6 , FILL); /* Draw arena ground */ GP142_rectangleXY(PEACH, -GP142_XMAX, -GP142_YMAX, GP142_XMAX, HORIZON, FILL); /*Draw arena back wall*/ GP142_lineXY(CHALK, -GP142_XMAX, HORIZON - 50, -GP142_XMAX / 2, HORIZON - 25, 70); GP142_lineXY(CHALK, -GP142_XMAX / 2, HORIZON - 25, GP142_XMAX / 2, HORIZON - 25, 70); GP142_lineXY(CHALK, GP142_XMAX / 2, HORIZON - 25, GP142_XMAX, HORIZON - 50, 70); /*arena deco design, right*/ for (i = 1; (i < 13); i++){ GP142_lineXY(ORANGE, 250 - (20 * i), HORIZON - 20, 250 + (20 * i), HORIZON - 70, 15); } /*arena deco design, left*/ for (i = 1; (i < 13); i++){ GP142_lineXY(ORANGE, -(250 - (20 * i)), HORIZON - 20, -(250 + (20 * i)), HORIZON - 70, 15); } /*armor rack*/ for (i = -4; (i < 5); ++i){ GP142_lineXY(BROWN, 8 * i,HORIZON + 10, 8 * i, HORIZON - 60, 5); } /*Armor rack contents and applicable display conditionals to make it so that the weapons are not on the rack while in use*/ if(((Spock == FALSE) || (Kirk == FALSE)) || (*pon_farr == FALSE)){ GP142_lineXY(LT_GRAY, -20, HORIZON, -20, HORIZON - 55, 4); GP142_lineXY(LT_GRAY, 20, HORIZON, 20, HORIZON - 55, 4); GP142_lineXY(LT_GRAY, -23, HORIZON - 7, -17, HORIZON - 7, 2); GP142_lineXY(LT_GRAY, 17, HORIZON - 7, 23, HORIZON - 7, 2); } /*Draw Spock*/ if(Spock == TRUE){ /*the drawing order is as follows- torso, head, left leg, right leg, starfleet insignia, pelvis, hair, left ear, right ear, right arm, left arm*/ GP142_lineXY(BLUE, spock_x, spock_y, spock_x, spock_y - 17, 20); GP142_ovalXY(WHITE, spock_x - 8, spock_y + 10, spock_x + 8, spock_y + 30, FILL); GP142_lineXY(BLACK, spock_x - 5, spock_y - 25, spock_x - 5, spock_y - 50, 7); GP142_lineXY(BLACK, spock_x + 5, spock_y - 25, spock_x + 5, spock_y - 50, 7); GP142_lineXY(MED_GRAY, spock_x + 7, spock_y - 4, spock_x + 5, spock_y - 3, 2); GP142_lineXY(BLACK, spock_x - 5, spock_y - 22, spock_x + 5, spock_y - 22, 10); GP142_lineXY(BLACK, spock_x - 5, spock_y + 27, spock_x + 5, spock_y + 27, 7); GP142_lineXY(WHITE, spock_x - 8, spock_y + 20, spock_x - 11, spock_y + 24, 2); GP142_lineXY(WHITE, spock_x + 8, spock_y + 20, spock_x + 11, spock_y + 24, 2); GP142_lineXY(BLUE, spock_x + 10, spock_y + 5, spock_x + 14, spock_y - 13, 4); GP142_lineXY(BLUE, spock_x - 10, spock_y + 5, spock_x - 14, spock_y - 13, 4); } /*Draw Kirk*/ if(Kirk == TRUE){ /*body parts drawn as follows- torso, head, left leg, right leg, starfleet insignia, pelvis, hair, right arm, left arm*/ GP142_lineXY(YELLOW, kirk_x, kirk_y, kirk_x, kirk_y - 17, 20); GP142_ovalXY(WHITE, kirk_x - 8, kirk_y + 10, kirk_x + 8, kirk_y + 30, FILL); GP142_lineXY(BLACK, kirk_x - 5, kirk_y - 25, kirk_x - 5, kirk_y - 50, 7); GP142_lineXY(BLACK, kirk_x + 5, kirk_y - 25, kirk_x + 5, kirk_y - 50, 7); GP142_lineXY(MED_GRAY, kirk_x + 7, kirk_y - 4, kirk_x + 5, kirk_y - 3, 2); GP142_lineXY(BLACK, kirk_x - 5, kirk_y - 22, kirk_x + 5, kirk_y - 22, 10); GP142_lineXY(BROWN, kirk_x - 5, kirk_y + 27, kirk_x + 5, kirk_y + 27, 7); GP142_lineXY(YELLOW, kirk_x + 10, kirk_y + 5, kirk_x + 14, kirk_y - 13, 4); GP142_lineXY(YELLOW, kirk_x - 10, kirk_y + 5, kirk_x - 14, kirk_y - 13, 4); } } /*end draw_landscape */ /***************************************************************************** BUTTONS AND MOUSE CLICKS *****************************************************************************/ /* Draws the buttons */ void draw_buttons(void) { int i; int text_offset = MENU_LEFT+10; /* offset of button text in button */ int font_size = 12; /* size of button text */ /* draw rectangles for each button */ for(i = 0; i < NUM_BUTTONS; i++) { GP142_rectangleXY(BLACK, MENU_LEFT, MENU_TOP - i * BUTTON_HEIGHT, MENU_LEFT + BUTTON_WIDTH, MENU_TOP - (i + 1) * BUTTON_HEIGHT, 1); } /* display button text */ i = MENU_TOP - (BUTTON_HEIGHT/2) - (font_size/2); GP142_printfXY(BLACK, text_offset, i, font_size, "Pon Farr"); i -= BUTTON_HEIGHT; GP142_printfXY(BLACK, text_offset, i, font_size, "Beam Spock"); i -= BUTTON_HEIGHT; GP142_printfXY(BLACK, text_offset, i, font_size, "Beam Kirk"); } /* Classify mouse click at (mouse_x,mouse_y) and return kind */ int classify_mouse_click(int mouse_x, int mouse_y) { if ((mouse_x > MENU_LEFT) && (mouse_x < MENU_LEFT + BUTTON_WIDTH) && (mouse_y < MENU_TOP) && (mouse_y > (MENU_TOP - NUM_BUTTONS * BUTTON_HEIGHT))) return BUTTON_CLICK; else return OTHER_CLICK; } /* Process button click at location x, y. React appropriately: */ /* i.e. change colors, tree tops, etc. if requested. */ void handle_button(int x, int y, int *Spock, int *beam_spock_done, int *Kirk, int *beam_kirk_done, int *pon_farr) { int buttonNum; /* number of selected button */ /* Complain if x coordinate couldn't be inside a button */ if (x < MENU_LEFT || x > MENU_LEFT + BUTTON_WIDTH) { something_is_wrong(); return; } /* Convert y coordinate to button number from top. */ buttonNum = (MENU_TOP - y)/BUTTON_HEIGHT; switch(buttonNum) { case 0: /* change pon_farr condition to TRUE if both characters present */ if((*Spock == TRUE) && (*Kirk == TRUE)){ *pon_farr = TRUE;} break; case 1: /* beam Spock up/down */ beam_switch(beam_spock_done, Spock); break; case 2: /* beam Kirk up/down */ beam_switch(beam_kirk_done, Kirk); break; default: /*Bad news if this is ever reached! */ GP142_animate(ANI_HALT); something_is_wrong(); break; } } /***************************************************************************** ANIMATED OBJECTS *****************************************************************************/ /* Make the stars blink */ void blink_star(int *star_radius, int *star_color) { *star_radius = rand() % MAX_STAR_RADIUS + 1; *star_color = rand() % MAX_COLORS; } /* Update moon coordinates moon_x, moon_y by one tick */ void move_moon(int *moon_x, int *moon_y) { /* Move the moon to the left. If it reaches the edge, move it */ /* to the other side and down a bit. */ (*moon_x) --; if (*moon_x < -GP142_XMAX -30) { *moon_x = - *moon_x; (*moon_y) --; } } /***************************************************************************** OTHER *****************************************************************************/ /* Initialize random number generator */ /* [Ignore or delete if your program */ /* doesn't user random numbers.] */ void initialize_random_numbers() { time_t t; /* current time */ srand (time(&t)); } /* Display error message if internal error is detected. */ void something_is_wrong (void) { GP142_printfXY (RED, 0, 0, 16, "Program error!"); }