1 2 /* 3 ** OIDS.H 4 ** 5 ** Header file for Xoids. 6 ** 7 ** Tim Ebling 8 ** tebling@oce.orst.edu 9 ** 10 */ 11 12 /* 13 * standard colour indices 14 */ 15 #define BLACK 0 16 #define RED 1 17 #define GREEN 2 18 #define YELLOW 3 19 #define BLUE 4 20 #define MAGENTA 5 21 #define CYAN 6 22 #define WHITE 7 23 24 25 /* 26 * How to convert degrees to radians 27 */ 28 #ifndef PI 29 #define PI 3.14159265358979 30 #endif 31 32 #define D2R (PI / 180.0) 33 34 35 #define WINDOW_HEIGHT 800 36 #define WINDOW_WIDTH 960 37 38 #define MAPS_PER_360 32 39 #define OIDS_PER_360 32 40 #define OID_DIVIDE 2 41 #define DELTA_ANG (2 * PI / MAPS_PER_360) 42 43 #define MAX_PLAYERS 2 44 #define P_MAX_SPEED 8 45 #define N_THRUST_PTS 3 46 #define HYPER_DELAY 20 47 48 #define SLURB_SPEED 4 49 #define H_MAX_SPEED 12 50 #define INIT_BIG_OIDS 3 51 #define MAX_BIG_OIDS 8 52 #define BIG_OID_ROT 10 53 #define BO_MAX_SPEED 5 54 55 #define MED_OID_ROT 5 56 #define MO_MAX_SPEED 8 57 58 #define SML_OID_ROT 2 59 #define SO_MAX_SPEED 10 60 61 #define NUM_SHARDS 5 62 #define CARNAGE_SPEED 1.5 63 #define CARNAGE_LIFE 100 64 #define DYING_TIME 15 65 #define DEATH_THRESH 5 66 67 #define TIMER_VAL 30 68 #define NUM_STARS 40 69 #define LINK_LENGTH 40 70 71 #define NORMAL 0 72 #define DYING 1 73 #define WARPING 2 74 #define REVIVING 3 75 #define EXPLODING 4 76 #define DEAD 5 77 78 #define GUN 0 79 #define LASER 1 80 81 #define KEY_THRUST1 0x0001 82 #define KEY_LEFT1 0x0002 83 #define KEY_RIGHT1 0x0004 84 #define KEY_FIRE1 0x0008 85 #define KEY_HYPER1 0x0010 86 #define KEY_THRUST2 0x0020 87 #define KEY_LEFT2 0x0040 88 #define KEY_RIGHT2 0x0080 89 #define KEY_FIRE2 0x0100 90 #define KEY_HYPER2 0x0200 91 #define KEY_QUIT 0x0400 92 #define KEY_PAUSE 0x0800 93 #define KEY_ESC 0x1000 94 95 #define UPARROW 1 96 #define DOWNARROW 2 97 #define LEFTARROW 3 98 #define RIGHTARROW 4 99 #define ENTER 5 100 101 102 /* 103 * max number of characters in a font name 104 */ 105 #define FONTNAMELEN 32 106 107 typedef struct vdev { 108 char initialised, 109 clipoff, 110 inobject, 111 inpolygon, 112 upset, /* is up vector set */ 113 cpVvalid, /* is the current device position valid */ 114 inbackbuffer, /* are we in the backbuffer */ 115 clipplanes; /* active clipping planes */ 116 void (*pmove)(), /* Polygon moves */ 117 (*pdraw)(); /* Polygon draws */ 118 float hheight, hwidth; /* hardware character height, width */ 119 int depth, /* # bit planes on screen */ 120 maxVx, minVx, 121 maxVy, minVy, 122 sizeX, sizeY, /* size of square on screen */ 123 sizeSx, sizeSy, /* side in x, side in y (# pixels) */ 124 cpVx, cpVy; 125 } Device; 126 127 Device vdevice; /* device structure */ 128 129 130 131 struct Shot { 132 unsigned int clock; 133 134 int x, 135 y, 136 ox, 137 oy; 138 139 int pts_x[5], 140 pts_y[5], 141 num_kill_pts, 142 kill_pts[2]; 143 144 float x_vec, 145 y_vec; 146 147 }; 148 149 struct Wpn { 150 151 int pts_x[5], 152 pts_y[5]; 153 154 unsigned int max_shots, 155 shot_speed, 156 shot_life, 157 inhibit_time, 158 size, 159 num_kill_pts, 160 kill_pts[2]; 161 162 }; 163 164 165 typedef struct spr { 166 unsigned int width, 167 height, 168 wo2, 169 ho2, 170 num_members, 171 num_pixmaps, 172 shots, 173 shot_color, 174 burst_color, 175 value, 176 score, 177 shots_fired, 178 engine, 179 hits, 180 num_death_sprites, 181 rotation, 182 thrust, 183 state, 184 state_ctr, 185 max_dying, 186 max_exploding, 187 bounced; 188 189 int rot_dir, 190 curr_map, 191 lives; 192 193 float ox, 194 oy, 195 x, 196 y; 197 198 float x_vec, 199 y_vec, 200 max_speed, 201 point_angle, 202 delta_angle, 203 mass; 204 205 char name[40]; 206 207 unsigned int wpn; 208 209 struct Shot **S; 210 211 char ***pixmap_data; 212 213 Pixmap *pixmaps, 214 *clipmasks, 215 *orig_pixmaps, 216 *orig_clipmasks; 217 218 struct spr *death_sprite; 219 struct spr *next; 220 struct spr *next_draw; 221 222 void (*kill_func)(); 223 224 } Sprite; 225 226 227 struct explosion { 228 229 unsigned int radius, 230 max_radius, 231 color; 232 233 int x, 234 y, 235 dir, 236 x_vec, 237 y_vec; 238 239 }; 240 241 struct linkage { 242 243 float x, 244 y, 245 x_vec, 246 y_vec, 247 ang, 248 ang_vec; 249 250 unsigned int length; 251 252 }; 253 254 255 /* External variables */ 256 257 258 Sprite *P; 259 Sprite *Slrb; 260 Sprite *Homer; 261 Sprite *Resur; 262 Sprite *Big_O; 263 Sprite *Med_O[MAX_BIG_OIDS]; 264 Sprite *Sml_O[MAX_BIG_OIDS * OID_DIVIDE]; 265 Sprite *Shrd[4]; 266 Sprite *Flame; 267 Sprite *Power_Up; 268 Sprite *Meta; 269 270 int keyboard_state, 271 goal_score; 272 273 struct explosion burst[250]; 274 275 extern struct linkage link; 276 277 static struct Wpn Weapon[] = { 0, 0, 0, -2, 2, /* Gun */ 278 0, 2, -2, 0, 0, 279 6, 7, 90, 5, 2, 1, 0, 0, 280 1, 0, -1, 0, 1, /* Laser */ 281 -10, 0, -10, -11, -10, 282 9, 16, 45, 2, 10, 2, 1, 3 }; 283 284 static int thrust_pts_x[] = {-5, 0, 5}; 285 static int thrust_pts_y[] = {-11, -15, -11}; 286 287 static int hot_spot_x = 0; 288 static int hot_spot_y = 12; 289 290 static char *mm_items[] = { "Start One Player Game", 291 "Start Two Player Duel", 292 "Start Two Player Cooperative", 293 "Options", 294 "Quit" }; 295 296 static char *om_items[] = { "Game Speed:", 297 "Two Player Score Goal:", 298 "Return to Main Menu" }; 299 300 static char *goal_str[] = { "10,000 (Quick Fix)", 301 "20,000 (A Serious Game)", 302 "40,000 (Making Galactic History)", 303 "100,000 (Get a Life!)"}; 304 305 static int goal_array[] = { 10000, 20000, 40000, 100000 }; 306 307 static int mm_num_items = 5; 308 static int om_num_items = 3; 309 310 float cos_table[MAPS_PER_360]; 311 float sin_table[MAPS_PER_360]; 312 313 int r_num; /* Global random number */ 314 315 int delay; /* Main loop delay factor */ 316 317 unsigned int timer, /* Game countdown clock */ 318 shot_clock; /* Countdown from shot fired */ 319 320 XRectangle clip_rect; /* Clipping rectangle for scoreboard */ 321 322 XPoint starfield[NUM_STARS]; /* Coordinates of stars */ 323 324 unsigned int num_bursts, /* Number of bursts */ 325 num_players, /* Number of players */ 326 oids_shot, /* Number of oids currently destroyed */ 327 level, /* Play level */ 328 warp_levels, /* Warping to a new level? */ 329 extra_man_scr, /* Score to subtract for "bonus ship"? */ 330 coop, /* Flag for co-op play */ 331 game_over, /* Flag for end of game */ 332 leave; /* Flag to leave game loop */ 333 334 335 /* 336 ** Function prototypes 337 */ 338 339 void X_init_pixmaps(); 340 char **X_rotate_pixmap_data(); 341 char *X_rotate_bitmap(); 342 void X_update(); 343 void X_draw_one_object(); 344 int X_checkkey(); 345 int X_get_menu_keys(); 346 int X_getkey(); 347 void X_backbuf(); 348 void X_frontbuf(); 349 void X_clear(); 350 void X_color(); 351 void X_string(); 352 void X_exit(); 353 void X_spin_pixmap360(); 354 void X_init(); 355 void X_draw_object(); 356 void X_draw_thrust(); 357 void X_draw_shots(); 358 void X_draw_bursts(); 359 void X_copy_object_to_window(); 360 void X_clear_object(); 361 void X_clear_shots(); 362 void X_draw_bursts(); 363 void X_check_keypress(); 364 void X_clear_one_object(); 365 void X_flash_screen(); 366 void X_draw_status_bar(); 367 int X_mapcolor(); 368 void X_swapbuf(); 369 void X_update_status_bar(); 370 void X_copy_status_bar_to_window(); 371 void X_draw_stars(); 372 void X_draw_link(); 373 void X_clear_key_buffer(); 374 void X_point(); 375 376 void init_all_objects(); 377 Sprite *init_object(); 378 struct Shot **init_shots(); 379 void create_new_shot(); 380 Sprite *update_shots(); 381 void erase_shot(); 382 void update_object(); 383 float random_num(); 384 void rotate_oids(); 385 Sprite *check_collision(); 386 void explode_object(); 387 void revive_player(); 388 int bounce_objects(); 389 void check_input(); 390 void warp_object(); 391 Sprite *shot_collide(); 392 int simple_collision(); 393 float speed(); 394 void update_score(); 395 void kill_shard(); 396 void do_nothing_for_a_while(); 397 void revive_oid(); 398 void destroy_oid(); 399 void update_bursts(); 400 void make_burst(); 401 void main_menu(); 402 void draw_game_over(); 403 void pause_game(); 404 void test_for_aliens(); 405 float distance(); 406 void init_starfield(); 407 void draw_level_warp(); 408 void link_players(); 409 void options_menu(); 410 void put_inside_window(); 411 void kill_power_up(); 412 void destroy_object(); 413 void destroy_homer(); 414 void alien_lock_on(); 415 void draw_homer_trail(); 416