/** * Add a Gozuky foe droped by a Naggys foe in the guardian phase * @param foe Pointer to a Naggys foe */ void lonely_foe_add_gozuky (enemy * foe, Uint32 cannon_pos) { Sint32 xcoord, ycoord; Sint16 power, current_image; spaceship_struct *ship = spaceship_get (); sprite *spr = &foe->spr; xcoord = (Sint32) (spr->xcoord + spr->img[spr-> current_image]->cannons_coords[cannon_pos][XCOORD]); /* check if the sprite is visible or not */ if (xcoord <= offscreen_startx || xcoord >= (offscreen_startx + offscreen_width_visible - 1)) { return; } ycoord = (Sint32) (spr->ycoord + spr->img[spr-> current_image]->cannons_coords[cannon_pos][YCOORD]); power = (Sint16) ((ship->type << 1) + 10); current_image = (Sint16) (rand () % ENEMIES_SPECIAL_NUM_OF_IMAGES); foe = lonely_foe_new (power, power, current_image, GOZUKY, 6000); if (foe == NULL) { return; } spr = &foe->spr; spr->anim_speed = 1; spr->speed = 0.2f; spr->xcoord = (float) (xcoord - spr->img[0]->x_gc); spr->ycoord = (float) (ycoord - spr->img[0]->y_gc); }
/** * Initialize a bonus (green, red, yellow, or purple gem) * or a lonely foe, into meteors phase * @param pos_x X-coordinate of the gem * @param pos_y Y-coordinate of the gem */ static void bonus_meteor_new (float pos_x, float pos_y) { Sint32 btype = 0; spaceship_struct *ship = spaceship_get (); /* get a bonus or penality value according to the difficulty */ if (num_level == 0) btype = (((Sint32) rand () % ((ship->type << 2) + 30))); if (num_level == 1) btype = (((Sint32) rand () % ((ship->type << 2) + 40))); if (num_level == 2) btype = (((Sint32) rand () % ((ship->type << 2) + 50))); if (num_level >= 3) btype = (((Sint32) rand () % ((ship->type << 2) + 60))); btype = bonus_meteor_get (btype); switch (btype) { /* one level in the options range (green gem) */ case BONUS_INC_BY_1: bonus_new_gem (BONUS_INC_BY_1, pos_x, pos_y, 0.25f); break; /* two levels in the options range (red gem) */ case BONUS_INC_BY_2: bonus_new_gem (BONUS_INC_BY_2, pos_x, pos_y, 0.35f); break; /* add a satellite protection bonus (yellow gem) */ case BONUS_ADD_SATELLITE: bonus_new_gem (BONUS_ADD_SATELLITE, pos_x, pos_y, 0.55f); break; /* add a energy bonus (purple gem) */ case BONUS_INC_ENERGY: bonus_new_gem (BONUS_INC_ENERGY, pos_x, pos_y, 0.45f); break; /* add a bonus score multiplier (blue gem) */ case BONUS_SCR_MULTIPLIER: bonus_new_gem (BONUS_SCR_MULTIPLIER, pos_x, pos_y, 0.65f); break; /* add a new lonely foe */ case PENALITY_LONELY_FOE: if (num_of_enemies < (MAX_OF_ENEMIES - 2)) { lonely_foe_add (-1); } break; default: break; } }
/** * Display player's ernergy level bar */ void energy_gauge_spaceship_update (void) { spaceship_struct *ship = spaceship_get (); if (!energy_gauge_spaceship_is_update) { return; } draw_energy_gauge (GAUGE_SPACESHIP_WIDTH * pixel_size, ship->spr.energy_level, 210 * pixel_size, (ship->type * 20 + 20) * pixel_size); }
/** * Add a satellite protection or enable electrical shocks */ void satellite_add (void) { Sint32 i; satellite_struct *sat; spaceship_struct *ship = spaceship_get (); /* restore the energy of all satellites */ for (i = 0; i < SATELLITES_MAXOF; i++) { /* set level of energy */ satellites[i].energy_level = (Sint16) (50 + ship->type * 10); /* set power of destruction */ satellites[i].pow_of_dest = (Sint16) (15 + ship->type * 5); } if (num_of_satellites < 5) { /* get a free satellite protection */ sat = satellite_get (); if (sat == NULL) { return; } /* set level of energy (zero correspond to destruction of the satellite) */ sat->energy_level = (Sint16) (50 + ship->type * 10); /* set power of the satellite's shot */ sat->pow_of_dest = (Sint16) (15 + ship->type * 5); /* set number of images of the sprite */ sat->numof_images = SATELLITES_NUMOF_IMAGES; /* set current image */ sat->current_image = 0; /* value of delay between two images */ sat->anim_speed = 8; /* counter of delay between two images */ sat->anim_count = 0; /* set shot time-frequency */ sat->fire_rate = 25; sat->fire_rate_count = sat->fire_rate; /* set addresses of the images buffer */ for (i = 0; i < sat->numof_images; i++) { sat->img[i] = (image *) & satellites_images[ship->type][i]; } satellites_setup (); } else { /* maximum number of satellites reached, enable electrical shocks */ electrical_shock_enable = TRUE; } }
/** * Create a new enemy * @param delay_next Animation speed * @param type Identifier of this enemy * @param shot_delay Delay value before two shots * @param speed Speed of the displacement * @return Pointer to the new enemy element */ static enemy * lonely_foe_create (Sint16 delay_next, Sint32 type, Sint32 shot_delay, float speed) { spaceship_struct *ship = spaceship_get (); Sint16 power = (Sint16) ((ship->type << 1) + type - 40); Sint16 energy = (Sint16) ((ship->type << 2) + (power << 3) / 3 + 10); enemy *foe = lonely_foe_new (power, energy, 0, type, shot_delay); if (foe == NULL) { return NULL; } foe->spr.anim_speed = delay_next; foe->spr.speed = speed; return foe; }
/** * Create a new enemy element which follow a curve * @param type Identifier of this enemy * @param shot_delay Delay value before two shots */ void lonely_foe_curve_create (Sint32 type, Sint32 shot_delay) { enemy *foe; Sint16 curve_num; Sint16 current_image, power, energy; spaceship_struct *ship = spaceship_get (); curve_num = 51 + (Sint16) (rand () % 4); current_image = initial_curve[curve_num].angle[0]; power = (Sint16) ((ship->type << 1) + type - 40); energy = (Sint16) ((ship->type << 2) + (power << 3) / 3 + 10); foe = lonely_foe_new (power, energy, current_image, type, shot_delay); if (foe == NULL) { return; } foe->num_courbe = curve_num; foe->spr.xcoord = (float) (initial_curve[curve_num].pos_x + 128 - 32); foe->spr.ycoord = (float) (initial_curve[curve_num].pos_y + 128 - 32); foe->pos_vaiss[POS_CURVE] = 0; }
/** * Add a circular shockwave from the player's spaceship */ void shockwave_add (void) { shockwave_struct *shock; spaceship_struct *ship = spaceship_get (); shock = shockwave_get (); if (shock == NULL) { return; } shock->ring_index = 0; shock->color_index = 0; shock->center_x = (Sint32) (ship->spr.xcoord + ship->spr.img[ship->spr.current_image]->x_gc); shock->center_y = (Sint32) (ship->spr.ycoord + ship->spr.img[ship->spr.current_image]->y_gc); #ifdef USE_SDLMIXER sound_play (SOUND_CIRCULAR_SHOCK); #endif }
/** * Collision between a gem and the spaceship * @param gem_str pointer to a gem structure * @return TRUE if the gem touched the spaceship */ static bool bonus_collision (const gem_str * const gem) { image *gem_img, *ship_img; Sint32 i; Sint32 collisionx, collisiony, gemx, gemy; spaceship_struct *ship = spaceship_get (); gem_img = gem->img[gem->current_image]; ship_img = ship->spr.img[ship->spr.current_image]; gemx = (Sint32) gem->xcoord + gem_img->collisions_coords[0][XCOORD]; gemy = (Sint32) gem->ycoord + gem_img->collisions_coords[0][YCOORD]; /* for each collision point of the spaceship */ for (i = 0; i < ship_img->numof_collisions_points; i++) { collisionx = (Sint32) ship->spr.xcoord + ship_img->collisions_points[i][XCOORD]; collisiony = (Sint32) ship->spr.ycoord + ship_img->collisions_points[i][YCOORD]; /* check if collision point is into gem collision zone */ if (collisionx >= gemx && collisiony >= gemy && collisionx < (gemx + gem_img->collisions_sizes[0][IMAGE_WIDTH]) && collisiony < (gemy + gem_img->collisions_sizes[0][IMAGE_HEIGHT])) { /* increase score of the player */ player_score += 250 << score_multiplier; switch (gem->type) { /* * add one level in the options range (green gem) */ case BONUS_INC_BY_1: { ship->gems_count++; option_change = TRUE; #ifdef USE_SDLMIXER sound_play (SOUND_GREEN_GEM); #endif } break; /* * add two levels in the options range (red gem) */ case BONUS_INC_BY_2: { ship->gems_count += 2; option_change = TRUE; #ifdef USE_SDLMIXER sound_play (SOUND_RED_GEM); #endif } break; /* * add a satellite protection (yellow gem) */ case BONUS_ADD_SATELLITE: { satellite_add (); #ifdef USE_SDLMIXER sound_play (SOUND_YELLOW_GEM); #endif } break; /* * restore energy level of the spaceship * (purple gem) */ case BONUS_INC_ENERGY: { if (ship->spr.energy_level < ship->spr.pow_of_dest) { option_boxes[1].close_option = FALSE; #ifdef USE_SDLMIXER sound_play (SOUND_PURPLE_GEM); #endif } /* maximum energy level reached: * circular shock wave is propagated */ else { shockwave_add (); } /* increase the level of energy of the spaceship */ ship->spr.energy_level += 20; if (ship->spr.energy_level >= ship->spr.pow_of_dest) { ship->spr.energy_level = ship->spr.pow_of_dest; if (!option_boxes[OPTION_PANEL_REPAIR].close_option) { /* maximum energy level: * start anim of closing option box */ option_anim_init (OPTION_PANEL_REPAIR, TRUE); } } energy_gauge_spaceship_is_update = TRUE; } break; /* * add a score multiplier (blue gem) */ case 4: { score_multiplier++; /* multiplier x4 maximum is allowed */ if (score_multiplier > 2) { score_multiplier = 2; } } break; } return TRUE; } } return FALSE; }
/** * The main loop of game * @return TRUE if it completed successfully or FALSE otherwise */ bool update_frame (void) { spaceship_struct *ship = spaceship_get (); #ifdef DEVELOPPEMENT /* 1 = phase grid editor enable (don't work) */ static bool grid_editor = FALSE; #endif /* global frame counter */ global_counter++; /* play start and congratulations animations files * ("movie_congratulation.gca" and "movie_introduction.gca") */ if (movie_playing_switch != MOVIE_NOT_PLAYED) { if (!movie_player ()) { LOG_ERR ("movie_player() failed!"); return FALSE; } else { return TRUE; } } display_clear_offscreen (); #ifdef __EMSCRIPTEN__ lock_surface_game (); lock_surface_options (); lock_surface_scores (); #endif /* restores the level of energy of the player spaceship */ spaceship_energy_restore (); /* phase grid and curve phase editor (don't work) */ #ifdef DEVELOPPEMENT if (grid_editor || curve_editor_enable) { if (grid_editor) { Grid_Edit (); } else { courbe_editeur (); } } else #endif /* pause or main menu enable */ if (!player_pause && menu_status == MENU_OFF && menu_section == NO_SECTION_SELECTED) { /* * handle the phases of the game */ /* phase 2: grids (enemy wave like Space Invaders) */ grid_handle (); /* phase 1: curves (little skirmish) */ curve_phase (); /* phase 3: meteor storm */ meteors_handle (); } /* draw the starfield background */ starfield_handle (); /* handle bonus: green, red, yellow, blue and purple gems */ bonus_handle (); /* handle protection satellites and extra gun of the player spaceship */ if (!gameover_enable && menu_section == NO_SECTION_SELECTED) { /* orbital protection satellites gravitate around player's spaceship */ satellites_handle (); /* extra gun positioned on the sides */ guns_handle (); } /* handle enemies */ if (!is_congratulations_enabled) { /* handling of all the possible types of enemies */ enemies_handle (); } else { /* congratulations, end of the game */ congratulations (); } /* spaceship temporary invincibility */ spaceship_invincibility (); /* handle the powerful electrical shocks */ electrical_shock (); /* draw the player's spaceship */ spaceship_draw (); /* handle explosions */ explosions_handle (); /* handle shots */ shots_handle (); /* wait until all enemies are dead before jumping on next phase */ if (num_of_enemies == 0 && !player_pause && menu_status == MENU_OFF && menu_section == NO_SECTION_SELECTED) { /* end of a guardian phase? */ if (!guardian_finished ()) { LOG_ERR ("guardian_finished() failed!"); return FALSE; } /* check if curve phase is finished */ curve_finished (); /* check if grid phase is finished */ grid_finished (); /* check if meteors phase is finished */ if (!meteors_finished ()) { LOG_ERR ("meteors_finished failed!"); return FALSE; } } /* display pixel mouse pointer */ #ifdef DEVELOPPEMENT if (mouse_here) { put_pixel (game_offscreen, mouse_x, mouse_y, 5); } #endif /* draw powerful circular shock wave propagated by the player spaceship */ shockwave_draw (); /* animations of the options box on the right options panel */ option_execution (); /* handle high score table, game over, about and order sections */ menu_sections_run (); /* display "PAUSE" chars sprites */ if (is_pause_draw) { text_pause_draw (); } /* player's spaceship come */ if (spaceship_appears_count > 0) { spaceship_appears_count--; /* accelerate the speed of the starfield */ starfield_speed += 0.028f; if (starfield_speed > 2.0) { starfield_speed = 2.0; } /* invincibility time */ spaceship_set_invincibility (SPACESHIP_INVINCIBILITY_TIME / 3); } /* player's spaceship disappearing to the bottom of the screen. */ if (spaceship_disappears && is_congratulations_enabled == 0) { /* decelerate the speed of the starfield */ starfield_speed -= 0.02f; if (starfield_speed <= 0.0) { starfield_speed = 0.0; ship->y_speed = 0.0; } else { /* accelerate the speed of the spaceship */ ship->y_speed += -0.15f; } } /* display number level */ text_level_draw (); /* display scrolltext in the main menu */ scrolltext_handle (); /* handle the main menu of Powermanga */ menu_handle (); /* [F1] spaceship_appears / [F2] spaceship disappears */ #ifdef DEVELOPPEMENT if (keys_down[K_F1]) { spaceship_disappears = 1; } if (keys_down[K_F2] && starfield_speed == 0.0) { spaceship_show (); } #endif /* handle "TLK Games" sprite logo */ if (tlk_logo_is_move) { draw_bitmap (&logotlk[tlk_logo_image_index], tlk_logo_xcoord, tlk_logo_ycoord); if (tlk_logo_is_next_image) { tlk_logo_image_index++; if (tlk_logo_image_index >= TLKLOGO_MAXOF_IMAGES) { tlk_logo_image_index = 0; } tlk_logo_is_next_image = FALSE; tlk_logo_ycoord--; } else { tlk_logo_is_next_image = TRUE; } if (tlk_logo_ycoord <= 32) { tlk_logo_is_move = FALSE; } } /* display text overlay (about, cheats menu and variables) */ text_overlay_draw (); /* handle the loss and the regression of the spaceship or cause game over */ spaceship_downgrading (); /* handle spaceship's energy level */ energy_gauge_spaceship_update (); /* handle guardian's energy level */ energy_gauge_guardian_update (); /* draw player's score into the top panel */ text_draw_score (); #ifdef DEVELOPPEMENT if (keys_down[K_E] && keys_down[K_G]) { /* [e]+[g] = enable the grid editor */ grid_editor = 1; } if (keys_down[K_E] && keys_down[K_C]) { /* [e]+[c] enable the curve editor */ curve_editor_enable = 1; } /* [p]+[g] back to the game */ if (keys_down[K_P] && keys_down[K_G]) { grid_editor = 0; curve_editor_enable = 0; } #endif /* control the spaceship movements */ if (!player_pause && !gameover_enable && menu_status == MENU_OFF && menu_section == NO_SECTION_SELECTED) { spaceship_control_movements (); } /* [P] or [Pause] enable/disable pause */ if (!keys_down[K_CTRL] && (keys_down[K_P] || keys_down[K_PAUSE])) { toggle_pause (); } keys_down[K_P] = FALSE; keys_down[K_PAUSE] = FALSE; /* clear flag pause key */ /* switch between full screen and windowed mode */ #ifdef POWERMANGA_SDL if ((keys_down[K_F] && !is_playername_input () && menu_section != SECTION_ORDER) || keys_down[K_F11]) { if (power_conf->fullscreen) { power_conf->fullscreen = FALSE; } else { power_conf->fullscreen = TRUE; } init_video_mode (); } keys_down[K_F] = FALSE; keys_down[K_F11] = FALSE; #endif /* control the speed of the spaceship */ spaceship_speed_control (); /* cheat code keys */ #ifdef UNDER_DEVELOPMENT special_keys (); #endif /* handle weapon's player spaceship */ #ifdef DEVELOPPEMENT if (!grid_editor && !curve_editor_enable && !spaceship_is_dead && !player_pause && menu_status == MENU_OFF && menu_section == NO_SECTION_SELECTED) #else if (!spaceship_is_dead && !player_pause && menu_status == MENU_OFF && menu_section == NO_SECTION_SELECTED) #endif { spaceship_weapons (); } #ifdef __EMSCRIPTEN__ unlock_surface_scores (); unlock_surface_options (); unlock_surface_game (); #endif return TRUE; }
/** * Initialize grid phase */ void grid_start (void) { Sint32 i, j, k; enemy *foe; spaceship_struct *ship = spaceship_get (); for (i = 0; i < GRID_WIDTH; i++) { for (j = 0; j < GRID_HEIGHT; j++) { /* enemy exists? */ if (grid.enemy_num[i][j] != -1) { /* get a new enemy element */ foe = enemy_get (); if (foe == NULL) { continue; } /* little enemy or big enemy (Bloodsuckers, chief of the wave)? */ if (grid.enemy_num[i][j] < ENEMIES_MAX_SMALL_TYPES) { /* set power of the destruction */ foe->spr.pow_of_dest = (Sint16) (1 + grid.enemy_num[i][j]); /* the level of energy of the sprite */ foe->spr.energy_level = (Sint16) ((ship->type << 1) + foe->spr.pow_of_dest); /* size of the enemy sprite as 16x16 pixels */ foe->type = 0; } else /* * Bloodsuckers, the chief of the wave */ { /* set power of the destruction */ foe->spr.pow_of_dest = (Sint16) (6 + (grid.enemy_num[i][j] - ENEMIES_MAX_SMALL_TYPES) * 2); /* the level of energy of the sprite */ foe->spr.energy_level = (Sint16) ((ship->type << 2) + foe->spr.pow_of_dest + 10); /* size of the enemy sprite as 32x32 pixels */ foe->type = 1; } /* set number of images of the sprite */ foe->spr.numof_images = 8; /* set current image of the enemy sprite */ foe->spr.current_image = (Sint16) (rand () % 8); /* delay before next image: speed of the animation */ foe->spr.anim_speed = 10; /* counter delay before next image */ foe->spr.anim_count = 0; /* set addresses of the images buffer */ for (k = 0; k < foe->spr.numof_images; k++) { if (grid.enemy_num[i][j] < ENEMIES_MAX_SMALL_TYPES) /* enemy sprite of 16x16 pixels */ foe->spr.img[k] = (image *) & enemi[grid.enemy_num[i][j]][32 + k]; else /* enemy sprite of 32x32 pixels */ foe->spr.img[k] = (image *) & enemi[grid.enemy_num[i][j]][k]; } /* delay value before next shot */ foe->fire_rate_count = grid.shoot_speed[i][j]; /* type of displacement */ foe->displacement = DISPLACEMENT_GRID; foe->pos_vaiss[XCOORD] = (Sint16) i; foe->pos_vaiss[YCOORD] = (Sint16) j; } } } /* set grid x coordinate */ grid.coor_x = 128; /* set grid y coordinate */ grid.coor_y = -176; /* enable the appearance of the grid of enemies */ grid.is_appearing = TRUE; /* grid phase disable */ grid.is_enable = FALSE; /* set movement toward right or left */ grid.right_movement = rand () % 2 ? TRUE : FALSE; if (grid.right_movement) { grid.speed_x = grid.vit_dep_x; } else { grid.speed_x = -grid.vit_dep_x; } }
/** * Add a lonely foe to the enemies list * @param foe_num Foe number of -1 if foe is selected by this function */ void lonely_foe_add (Sint32 foe_num) { enemy *foe; spaceship_struct *ship = spaceship_get (); #ifdef USE_SDLMIXER sound_play (SOUND_LONELY_FOE); #endif /* select an foes */ if (foe_num == -1) { lonely_foes_count++; /* all the lonely foes were selected once? */ if (lonely_foes_count > LONELY_FOES_MAX_OF) { /* select a foe randomly */ lonely_foes_count = LONELY_FOES_MAX_OF; foe_num = (Sint32) (((long) rand () % lonely_foes_count)); } /* select one after the other all the foes available */ else { foe_num = lonely_foes_count - 1; if (foe_num < 0) { foe_num = 0; } } } switch (foe_num) { /* SUBJUGANEERS */ case LONELY_SUBJUGANEERS: foe = lonely_foe_create (4, SUBJUGANEERS, 60 + (Sint32) (((long) rand () % (50))), -0.5); if (foe == NULL) { break; } foe->spr.xcoord = (float) (offscreen_startx + 64 + offscreen_width_visible); foe->spr.ycoord = offscreen_starty + (float) (((long) rand () % (offscreen_height_visible - foe->spr.img[0]->h))); break; /* MILLOUZ */ case LONELY_MILLOUZ: foe = lonely_foe_create (3, MILLOUZ, 0, 0.4f); if (foe == NULL) { break; } foe->spr.xcoord = (float) (offscreen_startx + ((long) rand () % (offscreen_width_visible - foe->spr.img[0]->w))); foe->spr.ycoord = (float) (offscreen_starty - 64 - foe->spr.img[0]->h); break; /* SWORDINIANS */ case LONELY_SWORDINIANS: foe = lonely_foe_create (4, SWORDINIANS, 50 + (Sint32) ((long) rand () % (50)), -0.3f); if (foe == NULL) { break; } foe->spr.xcoord = offscreen_startx + (float) (((long) rand () % (offscreen_width_visible - foe->spr.img[0]->w))); foe->spr.ycoord = (float) offscreen_starty + 64 + offscreen_height_visible; break; /* TOUBOUG */ case LONELY_TOUBOUG: foe = lonely_foe_create (4, TOUBOUG, 0, 0.35f); if (foe == NULL) { break; } foe->spr.xcoord = (float) (offscreen_startx + ((long) rand () % (offscreen_width_visible - foe->spr.img[0]->w))); foe->spr.ycoord = (float) (offscreen_starty - 64 - foe->spr.img[0]->h); break; /* DISGOOSTEES */ case LONELY_DISGOOSTEES: foe = lonely_foe_create (4, DISGOOSTEES, 50 + (Sint32) ((long) rand () % (50)), 0.6f); if (foe == NULL) { break; } foe->spr.xcoord = offscreen_startx + (float) (((long) rand () % (offscreen_width_visible - foe->spr.img[0]->w))); foe->spr.ycoord = (float) (offscreen_starty - 64 - foe->spr.img[0]->h); break; /* EARTHINIANS */ case LONELY_EARTHINIANS: foe = lonely_foe_create (4, EARTHINIANS, 50 + (Sint32) ((long) rand () % (50)), 0.6f); if (foe == NULL) { break; } foe->spr.xcoord = offscreen_startx + (float) (((long) rand () % (offscreen_width_visible - foe->spr.img[0]->w))); foe->spr.ycoord = (float) (offscreen_starty - 64 - foe->spr.img[0]->h); break; /* BIRIANSTEES */ case LONELY_BIRIANSTEES: foe = lonely_foe_create (4, BIRIANSTEES, 50 + (Sint32) ((long) rand () % (50)), 0.6f); if (foe == NULL) { break; } foe->spr.xcoord = offscreen_startx + (float) (((long) rand () % (offscreen_width_visible - foe->spr.img[0]->w))); foe->spr.ycoord = (float) (offscreen_starty - 64 - foe->spr.img[0]->h); break; /* BELCHOUTIES */ case LONELY_BELCHOUTIES: foe = lonely_foe_create (4, BELCHOUTIES, 60 + (Sint32) ((long) rand () % (50)), 0.6f); if (foe == NULL) { break; } foe->spr.xcoord = offscreen_startx + (float) (((long) rand () % (offscreen_width_visible - foe->spr.img[0]->w))); foe->spr.ycoord = (float) (offscreen_starty - 64 - foe->spr.img[0]->h); break; /* VIONIEES */ case LONELY_VIONIEES: foe = lonely_foe_create (4, VIONIEES, 50 + (Sint32) ((long) rand () % (50)), 2.0f + (float) (((long) rand () % (100))) / 100.0f); if (foe == NULL) { break; } foe->spr.xcoord = offscreen_startx + (float) (((long) rand () % (offscreen_width_visible - foe->spr.img[0]->w))); foe->spr.ycoord = (float) (offscreen_starty - 32 - foe->spr.img[0]->h); foe->retournement = FALSE; foe->change_dir = FALSE; break; /* HOCKYS */ case LONELY_HOCKYS: foe = lonely_foe_create (4, HOCKYS, 50 + (Sint32) ((long) rand () % (50)), -0.4f); if (foe == NULL) { break; } foe->spr.xcoord = offscreen_startx + (float) (((long) rand () % (offscreen_width_visible - foe->spr.img[0]->w))); foe->spr.ycoord = (float) (offscreen_starty + 64 + offscreen_height_visible); break; /* TODHAIRIES */ case LONELY_TODHAIRIES: foe = lonely_foe_create (4, TODHAIRIES, 60 + (Sint32) ((long) rand () % (60)), 0.6f); if (foe == NULL) { break; } foe->spr.xcoord = offscreen_startx + (float) (((long) rand () % (offscreen_width_visible - foe->spr.img[0]->w))); foe->spr.ycoord = (float) (offscreen_starty - 64 - foe->spr.img[0]->h); break; /* DEFECTINIANS */ case LONELY_DEFECTINIANS: foe = lonely_foe_create (4, DEFECTINIANS, 60 + (Sint32) ((long) rand () % (60)), 0.6f); if (foe == NULL) { break; } foe->spr.xcoord = offscreen_startx + (float) (((long) rand () % (offscreen_width_visible - foe->spr.img[0]->w))); foe->spr.ycoord = (float) (offscreen_starty - 64 - foe->spr.img[0]->h); break; /* BLAVIRTHE */ case LONELY_BLAVIRTHE: lonely_foe_curve_create (BLAVIRTHE, 60 + (Sint32) (((long) rand () % (60)))); break; /* SOONIEES */ case LONELY_SOONIEES: foe = lonely_foe_create (4, SOONIEES, 60 + (Sint32) ((long) rand () % (60)), 0.6f); if (foe == NULL) { break; } foe->spr.xcoord = offscreen_startx + (float) (((long) rand () % (offscreen_width_visible - foe->spr.img[0]->w))); foe->spr.ycoord = (float) (offscreen_starty - 64 - foe->spr.img[0]->h); break; /* ANGOUFF */ case LONELY_ANGOUFF: foe = lonely_foe_create (4, ANGOUFF, 50 + (Sint32) ((long) rand () % (50)), 2.0f + (float) (((long) rand () % (100))) / 100.0f); if (foe == NULL) { break; } foe->spr.xcoord = offscreen_startx + (float) (((long) rand () % (offscreen_width_visible - foe->spr.img[0]->w))); foe->spr.ycoord = (float) (offscreen_starty - 32 - foe->spr.img[0]->h); foe->retournement = FALSE; foe->change_dir = FALSE; break; /* GAFFIES */ case LONELY_GAFFIES: foe = lonely_foe_create (6, GAFFIES, 60 + (Sint32) ((long) rand () % (60)), 0.2f); if (foe == NULL) { break; } foe->spr.xcoord = offscreen_startx + (float) (((long) rand () % (offscreen_width_visible - foe->spr.img[0]->w))); foe->spr.ycoord = (float) (offscreen_starty - 64 - foe->spr.img[0]->h); break; /* BITTERIANS */ case LONELY_BITTERIANS: foe = lonely_foe_create (4, BITTERIANS, 60 + (Sint32) ((long) rand () % (50)), -0.5); if (foe == NULL) { break; } foe->spr.xcoord = (float) (offscreen_startx + 64 + offscreen_width_visible); foe->spr.ycoord = offscreen_starty + (float) (((long) rand () % (offscreen_height_visible - foe->spr.img[0]->h))); break; /* BLEUERCKS */ case LONELY_BLEUERCKS: lonely_foe_curve_create (BLEUERCKS, 50 + (Sint32) (((long) rand () % (50)))); break; /* ARCHINIANS */ case LONELY_ARCHINIANS: foe = lonely_foe_create (4, ARCHINIANS, 60 + (Sint32) ((long) rand () % (50)), -0.2f); if (foe == NULL) { break; } foe->spr.xcoord = offscreen_startx + (float) (((long) rand () % (offscreen_width_visible - foe->spr.img[0]->w))); foe->spr.ycoord = (float) (offscreen_starty + 64 + offscreen_height_visible); break; /* CLOWNIES */ case LONELY_CLOWNIES: foe = lonely_foe_create (4, CLOWNIES, 50 + (Sint32) ((long) rand () % (50)), 2.5f + (float) (((long) rand () % (100))) / 100.0f); if (foe == NULL) { break; } foe->spr.xcoord = offscreen_startx + (float) (((long) rand () % (offscreen_width_visible - foe->spr.img[0]->w))); foe->spr.ycoord = (float) (offscreen_starty - 64 - foe->spr.img[0]->h); foe->retournement = FALSE; foe->change_dir = FALSE; break; /* DEMONIANS */ case LONELY_DEMONIANS: foe = lonely_foe_create (4, DEMONIANS, 50 + (Sint32) ((long) rand () % (50)), 0.5); if (foe == NULL) { break; } foe->spr.xcoord = offscreen_startx + (float) (((long) rand () % (offscreen_width_visible - foe->spr.img[0]->w))); foe->spr.ycoord = (float) (offscreen_starty - 64 - foe->spr.img[0]->h); break; /* TOUTIES */ case LONELY_TOUTIES: foe = lonely_foe_create (4, TOUTIES, 60 + (Sint32) ((long) rand () % (50)), -0.35f); if (foe == NULL) { break; } foe->spr.xcoord = (float) (offscreen_startx + 64 + offscreen_width_visible); foe->spr.ycoord = offscreen_starty + (float) (((long) rand () % (offscreen_height_visible - foe->spr.img[0]->h))); break; /* FIDGETINIANS */ case LONELY_FIDGETINIANS: foe = lonely_foe_create (4, FIDGETINIANS, 50 + (Sint32) ((long) rand () % (50)), 0.5); if (foe == NULL) { break; } foe->spr.speed = 0.5; foe->spr.xcoord = offscreen_startx + (float) (((long) rand () % (offscreen_width_visible - foe->spr.img[0]->w))); foe->spr.ycoord = (float) (offscreen_starty - 64 - foe->spr.img[0]->h); break; /* EFFIES */ case LONELY_EFFIES: foe = lonely_foe_create (4, EFFIES, 50 + (Sint32) ((long) rand () % (50)), 2.5f + (float) (((long) rand () % (100))) / 100.0f); if (foe == NULL) { break; } foe->spr.xcoord = offscreen_startx + (float) (((long) rand () % (offscreen_width_visible - foe->spr.img[0]->w))); foe->spr.ycoord = (float) (offscreen_starty - 64 - foe->spr.img[0]->h); foe->retournement = FALSE; foe->change_dir = FALSE; break; /* DIMITINIANS */ case LONELY_DIMITINIANS: foe = lonely_foe_create (6, DIMITINIANS, 50 + (Sint32) ((long) rand () % (50)), 0.3f); if (foe == NULL) { break; } foe->spr.xcoord = offscreen_startx + (float) (((long) rand () % (offscreen_width_visible - foe->spr.img[0]->w))); foe->spr.ycoord = (float) (offscreen_starty - 64 - foe->spr.img[0]->h); foe->sens_anim = 0; break; /* PAINIANS */ case LONELY_PAINIANS: foe = lonely_foe_create (4, PAINIANS, 60 + (Sint32) ((long) rand () % (50)), 0.5); if (foe == NULL) { break; } foe->spr.xcoord = (float) (offscreen_startx - 64 - foe->spr.img[0]->w); foe->spr.ycoord = offscreen_starty + (float) (((long) rand () % (offscreen_height_visible - foe->spr.img[0]->h))); break; /* ENSLAVEERS */ case LONELY_ENSLAVEERS: foe = lonely_foe_create (4, ENSLAVEERS, 60 + (Sint32) ((long) rand () % (50)), +0.6f); if (foe == NULL) { break; } foe->spr.xcoord = offscreen_startx + (float) (((long) rand () % (offscreen_width_visible - foe->spr.img[0]->w))); foe->spr.ycoord = (float) (offscreen_starty - 64 - foe->spr.img[0]->h); break; /* FEABILIANS */ case LONELY_FEABILIANS: foe = lonely_foe_create (3, FEABILIANS, 60 + (Sint32) ((long) rand () % (50)), -0.5); if (foe == NULL) { break; } foe->spr.xcoord = (float) (offscreen_startx + 64 + offscreen_width_visible); foe->spr.ycoord = offscreen_starty + (float) (((long) rand () % (offscreen_height_visible - foe->spr.img[0]->h))); break; /* DIVERTIZERS */ case LONELY_DIVERTIZERS: foe = lonely_foe_create (3, DIVERTIZERS, 60 + (Sint32) ((long) rand () % (50)), +0.6f); if (foe == NULL) { break; } foe->spr.xcoord = offscreen_startx + (float) ((((long) rand () % (offscreen_width_visible - foe->spr.img[0]->w)))); foe->spr.ycoord = (float) (offscreen_starty - 64 - foe->spr.img[0]->h); break; /* SAPOUCH */ case SAPOUCH: case LONELY_SAPOUCH: foe = lonely_foe_create (4, SAPOUCH, 50 + (Sint32) ((long) rand () % (50)), 2.5f + (float) (((long) rand () % (100))) / 100.0f); if (foe == NULL) { break; } foe->spr.xcoord = offscreen_startx + (float) (((long) rand () % (offscreen_width_visible - foe->spr.img[0]->w))); foe->spr.ycoord = (float) (offscreen_starty - 64 - foe->spr.img[0]->h); foe->retournement = FALSE; foe->change_dir = FALSE; break; /* HORRIBIANS */ case LONELY_HORRIBIANS: foe = lonely_foe_create (3, HORRIBIANS, 60 + (Sint32) ((long) rand () % (50)), 0.6f); if (foe == NULL) { break; } foe->spr.xcoord = offscreen_startx + (float) ((((long) rand () % (offscreen_width_visible - foe->spr.img[0]->w)))); foe->spr.ycoord = (float) (offscreen_starty - 64 - foe->spr.img[0]->h); break; /* CARRYONIANS */ case LONELY_CARRYONIANS: foe = lonely_foe_create (5, CARRYONIANS, 60 + (Sint32) ((long) rand () % (50)), -0.2f); if (foe == NULL) { break; } foe->spr.xcoord = offscreen_startx + (float) (((long) rand () % (offscreen_width_visible - foe->spr.img[0]->w))); foe->spr.ycoord = (float) (offscreen_starty + 64 + offscreen_height_visible); break; /* DEVILIANS */ case DEVILIANS: case LONELY_DEVILIANS: foe = lonely_foe_create (5, DEVILIANS, 60 + (Sint32) ((long) rand () % (50)), +0.5); if (foe == NULL) { break; } foe->spr.xcoord = offscreen_startx + (float) ((((long) rand () % (offscreen_width_visible - foe->spr.img[0]->w)))); foe->spr.ycoord = (float) (offscreen_starty - 64 - foe->spr.img[0]->h); break; /* ROUGHLEERS */ case LONELY_ROUGHLEERS: foe = lonely_foe_create (6, ROUGHLEERS, 50 + (Sint32) ((long) rand () % (50)), 0.5); if (foe == NULL) { break; } foe->spr.xcoord = offscreen_startx + (float) (((long) rand () % (offscreen_width_visible - foe->spr.img[0]->w))); foe->spr.ycoord = (float) (offscreen_starty - 64 - foe->spr.img[0]->h); break; /* ABASCUSIANS */ case LONELY_ABASCUSIANS: foe = lonely_foe_create (4, ABASCUSIANS, 50 + (Sint32) ((long) rand () % (50)), 0.5); if (foe == NULL) { break; } foe->spr.xcoord = offscreen_startx + (float) (((long) rand () % (offscreen_width_visible - foe->spr.img[0]->w))); foe->spr.ycoord = (float) (offscreen_starty - 64 - foe->spr.img[0]->h); break; /* ROTIES */ case LONELY_ROTIES: lonely_foe_curve_create (ROTIES, 50 + (Sint32) (((long) rand () % (50)))); break; /* STENCHIES */ case LONELY_STENCHIES: lonely_foe_curve_create (STENCHIES, 50 + (Sint32) (((long) rand () % (50)))); break; /* PERTURBIANS */ case LONELY_PERTURBIANS: foe = lonely_foe_create (6, PERTURBIANS, 50 + (Sint32) ((long) rand () % (50)), 0.2f); if (foe == NULL) { break; } foe->spr.xcoord = offscreen_startx + (float) (((long) rand () % (offscreen_width_visible - foe->spr.img[0]->w))); foe->spr.ycoord = (float) (offscreen_starty - 64 - foe->spr.img[0]->h); break; /* MADIRIANS */ case LONELY_MADIRIANS: lonely_foe_curve_create (MADIRIANS, 50 + (Sint32) (((long) rand () % (50)))); break; /* BAINIES */ case LONELY_BAINIES: foe = lonely_foe_create (4, BAINIES, 50 + (Sint32) ((long) rand () % (40)), 0.4f); if (foe == NULL) { break; } foe->spr.xcoord = (float) (offscreen_startx - 64 - foe->spr.img[0]->w); foe->spr.ycoord = offscreen_starty + (float) (((long) rand () % (offscreen_height_visible - foe->spr.img[0]->h))); break; /* NAGGYS */ case NAGGYS: foe = lonely_foe_new ((Sint32) (ship->type << 2), (Sint32) ((ship->type << 2) + 20), 0, NAGGYS, 15); if (foe == NULL) { break; } foe->spr.anim_speed = 2; foe->spr.speed = 2.0; foe->spr.xcoord = (float) (offscreen_startx - 64 - foe->spr.img[0]->w); foe->spr.ycoord = offscreen_starty + 48 + (float) (((long) rand () % 32)); break; } }
/** * Move and draw the sprites of the protections satellite */ void satellites_handle (void) { Sint32 i, k; satellite_struct *sat; spaceship_struct *ship = spaceship_get (); sat = satellite_first; if (sat == NULL) { return; } /* process each satellite sprite */ for (i = 0; i < num_of_satellites; i++, sat = sat->next) { #ifdef UNDER_DEVELOPMENT if (sat == NULL && i < (num_of_satellites - 1)) { LOG_ERR ("sat->next is null %i/%i", i, num_of_satellites); break; } #endif if (!player_pause && menu_status == MENU_OFF) { /* increment index to next position on the precalculated circle table */ sat->pos_in_circle++; if (sat->pos_in_circle >= SATELLITE_NUMOF_POINTS_CIRCLE) { sat->pos_in_circle = 0; } /* update x and y coordinates */ sat->xcoord = (Sint16) (ship->spr.xcoord) + ship->spr.img[ship->spr.current_image]->x_gc + satellite_circle_x[sat->pos_in_circle] - sat->img[sat->current_image]->x_gc; sat->ycoord = (Sint16) (ship->spr.ycoord) + ship->spr.img[ship->spr.current_image]->y_gc + satellite_circle_y[sat->pos_in_circle] - sat->img[sat->current_image]->y_gc; /* decrease delay before next shot */ sat->fire_rate_count--; /* check if the satellite fire or not a shot * (this part is used normally never) */ if (sat->fire_rate_count <= 0) { /* reset shot time-frequency */ sat->fire_rate_count = sat->fire_rate; /* process each origin of the shot (location of the cannon) */ for (k = 0; k < sat->img[sat->current_image]->numof_cannons; k++) { shot_satellite_add (sat->xcoord + sat->img[sat->current_image]-> cannons_coords[k][XCOORD], sat->ycoord + sat->img[sat->current_image]-> cannons_coords[k][YCOORD], sat->img[sat->current_image]-> cannons_angles[k]); } } } /* check if the sprite is visible or not */ if ((sat->xcoord + sat->img[0]->w) < offscreen_startx || (sat->ycoord + sat->img[0]->h) < offscreen_starty || sat->xcoord > (offscreen_startx + offscreen_width_visible - 1) || sat->ycoord > (offscreen_starty + offscreen_height_visible - 1)) { /* satellite is not visible, don't perform the tests of collision */ sat->is_visible = FALSE; } else { /* satellite is visible, perform the tests of collision */ sat->is_visible = TRUE; /* increase counter delay between two images */ sat->anim_count++; /* value of delay between two images reached? */ if (sat->anim_count >= sat->anim_speed) { /* clear counter delay between two images */ sat->anim_count = 0; /* flip to the next image */ sat->current_image++; /* check if last image has been reached */ if (sat->current_image >= sat->numof_images) { /* resets the animation to the first image of the animation * sequence */ sat->current_image = 0; } } /* draw the satellite sprite image */ if (sat->is_mask) { /* draw white mask of the sprite image */ draw_sprite_mask (coulor[WHITE], sat->img[sat->current_image], sat->xcoord, sat->ycoord); sat->is_mask = FALSE; } else { draw_sprite (sat->img[sat->current_image], sat->xcoord, sat->ycoord); } } } }