void GameSession::process_menu() { Menu* menu = Menu::current(); if(menu) { menu->action(); if(menu == game_menu) { switch (game_menu->check()) { case MNID_CONTINUE: st_pause_ticks_stop(); break; case MNID_ABORTLEVEL: st_pause_ticks_stop(); exit_status = ES_LEVEL_ABORT; break; } } else if(menu == options_menu) { process_options_menu(); } else if(menu == load_game_menu ) { process_load_game_menu(); } } }
bool process_load_game_menu() { int slot = load_game_menu->check(); if(slot != -1 && load_game_menu->get_item_by_id(slot).kind == MN_ACTION) { char slotfile[1024]; snprintf(slotfile, 1024, "%s/slot%d.stsg", st_save_dir, slot); if (access(slotfile, F_OK) != 0) { draw_intro(); } fadeout(); WorldMapNS::WorldMap worldmap; //TODO: Define the circumstances under which BonusIsland is chosen worldmap.set_map_file("world1.stwm"); worldmap.load_map(); // Load the game or at least set the savegame_file variable worldmap.loadgame(slotfile); worldmap.display(); Menu::set_current(main_menu); st_pause_ticks_stop(); return true; } else { return false; } }
void GameSession::process_events() { if (end_sequence != NO_ENDSEQUENCE) { Player& tux = *world->get_tux(); tux.input.fire = UP; tux.input.left = UP; tux.input.right = DOWN; tux.input.down = UP; if (int(last_x_pos) == int(tux.base.x)) tux.input.up = DOWN; else tux.input.up = UP; last_x_pos = tux.base.x; SDL_Event event; while (SDL_PollEvent(&event)) { /* Check for menu-events, if the menu is shown */ if (Menu::current()) { Menu::current()->event(event); if(!Menu::current()) st_pause_ticks_stop(); } switch(event.type) { case SDL_QUIT: /* Quit event - quit: */ st_abort("Received window close", ""); break; case SDL_KEYDOWN: /* A keypress! */ { SDLKey key = event.key.keysym.sym; switch(key) { case SDLK_ESCAPE: /* Escape: Open/Close the menu: */ on_escape_press(); break; default: break; } } case SDL_JOYBUTTONDOWN: if (event.jbutton.button == joystick_keymap.start_button) on_escape_press(); break; } } } else // normal mode { if(!Menu::current() && !game_pause) st_pause_ticks_stop(); SDL_Event event; while (SDL_PollEvent(&event)) { /* Check for menu-events, if the menu is shown */ if (Menu::current()) { Menu::current()->event(event); if(!Menu::current()) st_pause_ticks_stop(); /* Tell Tux that the keys are all down, otherwise it could have nasty bugs, like going allways to the right or whatever that key does */ Player& tux = *world->get_tux(); tux.key_event((SDLKey)keymap.jump, UP); tux.key_event((SDLKey)keymap.duck, UP); tux.key_event((SDLKey)keymap.left, UP); tux.key_event((SDLKey)keymap.right, UP); tux.key_event((SDLKey)keymap.fire, UP); } else { Player& tux = *world->get_tux(); switch(event.type) { case SDL_QUIT: /* Quit event - quit: */ st_abort("Received window close", ""); break; case SDL_KEYDOWN: /* A keypress! */ { SDLKey key = event.key.keysym.sym; if(tux.key_event(key,DOWN)) break; switch(key) { case SDLK_ESCAPE: /* Escape: Open/Close the menu: */ on_escape_press(); break; default: break; } } break; case SDL_KEYUP: /* A keyrelease! */ { SDLKey key = event.key.keysym.sym; if(tux.key_event(key, UP)) break; switch(key) { case SDLK_p: if(!Menu::current()) { if(game_pause) { game_pause = false; st_pause_ticks_stop(); } else { game_pause = true; st_pause_ticks_start(); } } break; case SDLK_TAB: if(debug_mode) { tux.size = !tux.size; if(tux.size == BIG) { tux.base.height = 64; } else tux.base.height = 32; } break; case SDLK_END: if(debug_mode) player_status.distros += 50; break; case SDLK_DELETE: if(debug_mode) tux.got_coffee = 1; break; case SDLK_INSERT: if(debug_mode) tux.invincible_timer.start(TUX_INVINCIBLE_TIME); break; case SDLK_l: if(debug_mode) --player_status.lives; break; case SDLK_s: if(debug_mode) player_status.score += 1000; case SDLK_f: if(debug_fps) debug_fps = false; else debug_fps = true; break; default: break; } } break; case SDL_JOYAXISMOTION: if (event.jaxis.axis == joystick_keymap.x_axis) { if (event.jaxis.value < -joystick_keymap.dead_zone) { tux.input.left = DOWN; tux.input.right = UP; } else if (event.jaxis.value > joystick_keymap.dead_zone) { tux.input.left = UP; tux.input.right = DOWN; } else { tux.input.left = DOWN; tux.input.right = DOWN; } } else if (event.jaxis.axis == joystick_keymap.y_axis) { if (event.jaxis.value > joystick_keymap.dead_zone) tux.input.down = DOWN; else if (event.jaxis.value < -joystick_keymap.dead_zone) tux.input.down = UP; else tux.input.down = UP; } break; case SDL_JOYBUTTONDOWN: if (event.jbutton.button == joystick_keymap.a_button) tux.input.up = DOWN; else if (event.jbutton.button == joystick_keymap.b_button) tux.input.fire = DOWN; else if (event.jbutton.button == joystick_keymap.start_button) on_escape_press(); break; case SDL_JOYBUTTONUP: if (event.jbutton.button == joystick_keymap.a_button) tux.input.up = UP; else if (event.jbutton.button == joystick_keymap.b_button) tux.input.fire = UP; break; default: break; } /* switch */ } } /* while */ } }