void startup_menu(void) { reset_menu_palette(); menu_select = 0; key_wait = 30; // int counter; menu_counter = 0; counter2 = 0; arena.difficulty = 0; int y1 = 170; int y2 = 190 + menu_select * 30; int y3 = 218 + menu_select * 30; int y4 = 218 + menu_select * 30; int anykey = 0; int i; //#define TEST_MUSIC #ifdef TEST_MUSIC arena.level = 3; init_beat_new_level(); #endif init_menu_circles(); while (TRUE) { #ifdef TEST_MUSIC run_beat(); #endif clear_to_color(display, COL_BACK1); run_menu_background(); menu_counter += 4; if (menu_counter >= 40) menu_counter = 0; counter2 ++; if (counter2 >= 256) counter2 = 0; // textprintf_centre_ex(display, font, 300, 190, -1, -1, "W H I T E B U T T E R F L Y"); draw_rle_sprite(display, white_RLE, 150, 150); int my = 300; y1 = my - 23; y2 = my - 10 + menu_select * 30; y3 = my + 19 + menu_select * 30; y4 = my + 150; // rectfill(display, 370, y1, 600, y2, COL_COL1); TRANS_MODE rectfill(display, 370, y2 + 9, 640, y3 - 2, TRANS_BLUE3); rect(display, 368, y2 + 7, 641, y3 - 0, TRANS_BLUE3); END_TRANS // rectfill(display, 370, y3, 600, y4, TRANS_DGREEN); textprintf_ex(display, font, 400, my, -1, -1, "START GAME"); switch(arena.difficulty) { case 0: textprintf_ex(display, font, 400, my + 30, -1, -1, "DIFFICULTY - NORMAL"); break; case 1: textprintf_ex(display, font, 400, my + 30, -1, -1, "DIFFICULTY - HARD"); break; case 2: textprintf_ex(display, font, 400, my + 30, -1, -1, "DIFFICULTY - PUNISHMENT"); break; } // textprintf_ex(display [2], font, 400, 260, -1, -1, "STAGE - %i", arena.starting_level); textprintf_ex(display, font, 400, my + 90, -1, -1, "SET KEYS"); textprintf_ex(display, font, 400, my + 120, -1, -1, "OPTIONS"); textprintf_ex(display, font, 400, my + 150, -1, -1, "EXIT"); // textprintf_ex(display, font, 40, 10, -1, -1, "%i", joy[0].stick[options.joy_stick].axis[0].pos); // textprintf_ex(display, font, 40, 30, -1, -1, "%i", joy[0].stick[options.joy_stick].axis[1].pos); /* if (options.joystick) textprintf_ex(display, font, 400, my + 120, -1, -1, "CALIBRATE JOYSTICK"); else { textprintf_ex(display, font, 400, my + 120, -1, -1, "NO JOYSTICK"); drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0); rectfill(display, 399, my + 110, 530, my + 135, CONVERT_WHITE_TO_GREY); drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0); } */ if (options.joystick) { if (options.key_or_joy == 1) textprintf_ex(display, font, 400, my + 60, -1, -1, "CONTROLS - JOYSTICK"); else textprintf_ex(display, font, 400, my + 60, -1, -1, "CONTROLS - KEYBOARD"); } else { textprintf_ex(display, font, 400, my + 60, -1, -1, "NO JOYSTICK"); drawing_mode(DRAW_MODE_TRANS, NULL, 0, 0); rectfill(display, 399, my + 50, 530, my + 75, CONVERT_WHITE_TO_GREY); drawing_mode(DRAW_MODE_SOLID, NULL, 0, 0); } // textprintf_ex(display, font, 5, 5, -1, -1, "%i", any_joystick_input()); my = 330; y2 = my + 7 + arena.just_got_highscore * 30; y3 = my + 29 + arena.just_got_highscore * 30; if (arena.just_got_highscore > 0) { rectfill(display, 0, y2 - 5, 250, y3, COL_COL3); rect(display, -1, y2 - 5 - 2, 250 + 2, y3 + 2, COL_COL4); } // textprintf_right_ex(display, font, 137, my, -1, -1, "HIGH"); // textprintf_ex(display, font, 157, my, -1, -1, "SCORES"); textprintf_centre_ex(display, font, 147, my, -1, -1, "HIGHSCORES"); textprintf_right_ex(display, font, 137, my + 40, -1, -1, "NORMAL"); textprintf_ex(display, font, 157, my + 40, -1, -1, "%i", options.highscore [0]); textprintf_right_ex(display, font, 137, my + 70, -1, -1, "HARD"); textprintf_ex(display, font, 157, my + 70, -1, -1, "%i", options.highscore [1]); textprintf_right_ex(display, font, 137, my + 100, -1, -1, "PUNISHMENT"); textprintf_ex(display, font, 157, my + 100, -1, -1, "%i", options.highscore [2]); textprintf_right_ex(display, font, 600, 570, -1, -1, "COPYRIGHT 2009 LINLEY HENZELL"); // should print last score here... anykey = 0; for (i = KEY_A; i < KEY_CAPSLOCK + 1; i ++) { if (key [i]) { anykey = 1; } } if (anykey == 0 && (options.joystick == 0 || any_joystick_input() == 0)) key_wait = 0; if (key_wait == 0) { if (menu_command(MC_UP)) { menu_select --; if (menu_select < 0) menu_select = MENU_EXIT; if (menu_select == MENU_JOY_OR_KEYS && options.joystick == 0) menu_select = MENU_JOY_OR_KEYS - 1; key_wait = 7; } if (menu_command(MC_DOWN)) { menu_select ++; if (menu_select > MENU_EXIT) menu_select = 0; if (menu_select == MENU_JOY_OR_KEYS && options.joystick == 0) menu_select = MENU_KEYS; key_wait = 7; } if (menu_command(MC_LEFT)) { // if (menu_select == 2) // arena.starting_level = 1; if (menu_select == MENU_JOY_OR_KEYS) { if (options.key_or_joy == 0) options.key_or_joy = 1; else options.key_or_joy = 0; } if (menu_select == MENU_DIFFICULTY) { arena.difficulty --; if (arena.difficulty < 0) arena.difficulty = 0; } key_wait = 7; } if (menu_command(MC_RIGHT)) { // if (menu_select == 2) // arena.starting_level = 2; if (menu_select == MENU_JOY_OR_KEYS) { if (options.key_or_joy == 0) options.key_or_joy = 1; else options.key_or_joy = 0; } if (menu_select == MENU_DIFFICULTY) { arena.difficulty ++; if (arena.difficulty > 2) arena.difficulty = 2; } key_wait = 7; } // if (key [KEY_ESC]) // exit(0); if (menu_command(MC_SELECT)) { if (menu_select == MENU_EXIT) { goodbye_menu_circles(); return; } if (menu_select == MENU_KEYS) { key_wait = 10; define_keys(); key_wait = 10; } if (menu_select == MENU_OPTIONS) { key_wait = 10; set_options(); key_wait = 10; } /* if (menu_select == MENU_CALIBRATE) { jstick_calibrate(); key_wait = 20; ticked = 0; }*/ if (menu_select == MENU_START) { arena.level = 1;//arena.starting_level; ticked = 0; key_wait = 30; if (ship_select() == 1) { vsync(); // clear_bitmap(screen); // clear_bitmap(display); player.type = PTYPE_BASIC; // player.type = PTYPE_BOMBER; // player.type = PTYPE_ANENOME; // player.type = PTYPE_HAND; player.weapon_level = 0; int ship_select = select_a_ship(); if (ship_select != -1) { switch(ship_select) { default: case 0: player.type = PTYPE_BASIC; break; case 1: player.type = PTYPE_ANENOME; break; case 2: player.type = PTYPE_BOMBER; break; case 3: player.type = PTYPE_HAND; break; case 4: player.type = PTYPE_SQUID; break; } if (arena.level == 1) arena.from_start = 1; else arena.from_start = 0; arena.cleared = 0; arena.unlocked = 0; menu_counter = 0; goodbye_menu_circles(); new_game(); game_loop(); if (arena.level == 4) congratulations(); arena.target_palette = PAL_MENU; arena.shift_palette = 2; init_menu_circles(); // reset_menu_palette(); key_wait = 10; // was 1 // flower_dir *= -1; ticked = 0; } } else key_wait = 20; } else key_wait = 20; } } else key_wait --; do { thing ++; } while (ticked == 0); ticked = 0; if (arena.shift_palette > 0 && menu_counter % 12 == 0) { run_palette_shift(); build_new_palette(0, 0, 0, 0); set_palette(palet); if (arena.shift_palette == 1) arena.shift_palette = 0; } vsync(); blit(display, screen, 0, 0, 100, 0, 600, 600); }; }
/** * 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; }