/* * SPEED - by Shawn Hargreaves, 1999 * * Main player control functions. */ #include #include #include "speed.h" /* how many lives do we have left? */ int lives; /* counters for various time delays */ static int init_time; static int die_time; static int fire_time; /* current position and velocity */ static float pos; static float vel; /* which segments of health we currently possess */ #define SEGMENTS 16 static int ganja[SEGMENTS]; /* Did you ever come across a DOS shareware game called "Ganja Farmer"? * It is really very cool: you have to protect your crop from "Da Man", * who is trying to bomb it, spray it with defoliants, etc. Superb * reggae soundtrack, and the gameplay concept here is kind of similar, * hence my variable names... */ /* tell other people where we are */ float player_pos() { return pos; } /* tell other people where to avoid us */ float find_target(float x) { int seg = (int)(x * SEGMENTS) % SEGMENTS; int i, j; if (seg < 0) seg += SEGMENTS; for (i=0; i= 0.97) { int seg = (int)(x * SEGMENTS) % SEGMENTS; if (ganja[seg]) { ganja[seg] = FALSE; explode(x, 0.98, 1); sfx_explode_block(); } ret = TRUE; } if ((y >= 0.95) && (!init_time) && (!die_time) && (!cheat)) { float d = pos - x; if (d < -0.5) d += 1; else if (d > 0.5) d -= 1; if (ABS(d) < 0.06) { die_time = 128; explode(x, 0.98, 2); explode(x, 0.98, 4); sfx_explode_player(); message("Ship Destroyed"); ret = TRUE; } } return ret; } /* initialises the player functions */ void init_player() { int i; lives = 3; init_time = 128; die_time = 0; fire_time = 0; pos = 0.5; vel = 0; for (i=0; i 0) && (score > get_hiscore()) && (old_score <= get_hiscore())) { message("New Record Score!"); sfx_ping(3); } else if ((bonus == SEGMENTS) || (cycle)) { sfx_ping(1); } } /* updates the player position */ int update_player() { poll_keyboard(); poll_joystick(); /* quit game? */ if (key[KEY_ESC]) return -1; /* safe period while initing */ if (init_time) init_time--; /* blown up? */ if (die_time) { die_time--; if (!die_time) { lives--; if (!lives) return 1; init_time = 128; pos = 0.5; vel = 0; if (lives == 1) message("This Is Your Final Life"); else message("One Life Remaining"); } } /* handle user left/right input */ if (!die_time) { if ((joy_left) || (key[KEY_LEFT])) vel -= 0.005; if ((joy_right) || (key[KEY_RIGHT])) vel += 0.005; } /* move left and right */ pos += vel; if (pos >= 1.0) pos -= 1.0; if (pos < 0.0) pos += 1.0; vel *= 0.67; /* fire bullets */ if ((!die_time) && (!init_time) && (!fire_time)) { if ((key[KEY_SPACE]) || (joy_b1)) { fire_bullet(); fire_time = 24; } } if (fire_time) fire_time--; return 0; } /* draws the player */ void draw_player(BITMAP *bmp, int r, int g, int b, int (*project)(float *f, int *i, int c)) { float shape[12]; int ishape[12]; int i; /* draw health segments */ for (i=0; i