/* type of game.. */ static void game_timed_out( void) { if(player_controlling_game()) { set_game_state(_close_game); } else { set_game_state(_switch_demo); } }
void init_game(int tile_index) { if ((game_hero = load_actor_XML("aron.stat")) == NULL) { fprintf(stderr, "ERROR - Unable to initialize hero.\n"); exit(1); } if ((game_player = new_player(128 * 32, 96 * 32, game_hero)) == NULL) { fprintf(stderr, "ERROR - Unable to initialize player.\n"); exit(1); } if ((game_world = new_world("world.png", tile_index, game_player->x, game_player->y, 300, 200, DEFAULT_CELL_WIDTH, DEFAULT_CELL_HEIGHT)) == NULL) { fprintf(stderr, "ERROR - Unable to initialize world\n"); exit(1); } if ((game_scanner = new_scanner("marker4x4.png")) == NULL) { fprintf(stderr, "ERROR - Unable to initialize scanner\n"); exit(1); } if ((game_battle = new_battle(game_world)) == NULL) { fprintf(stderr, "ERROR - Unable to initialize battle\n"); exit(1); } set_game_state(GAME_STATE_WORLD); update_game(); }
static void bridge_next_bid(void) { /* closely based on Suaro code, below */ if (BRIDGE.pass_count == 4) { /* done bidding */ if (BRIDGE.contract == 0) { ggz_debug(DBG_GAME, "Four passes; redealing hand."); set_global_message("", "Everyone passed; redealing."); set_game_state(STATE_NEXT_HAND); /* redeal hand */ } else { ggz_debug(DBG_GAME, "Three passes; bidding is over."); game.bid_total = game.bid_count; /* contract was determined in game_handle_bid */ } } else { if (game.bid_count == 0) game.next_bid = game.dealer; else game.next_bid = (game.next_bid + 1) % game.num_players; } }
/* Called by the time manager task in vbl_macintosh.c */ boolean input_controller( void) { if (input_task_active) { if((heartbeat_count-dynamic_world->tick_count) < MAXIMUM_TIME_DIFFERENCE) { if (game_is_networked) // input from network { ; // all handled elsewhere now. (in network.c) } else if (replay.game_is_being_replayed) // input from recorded game file { static short phase= 0; /* When this gets to 0, update the world */ /* Minimum replay speed is a pause. */ if(replay.replay_speed != MINIMUM_REPLAY_SPEED) { if (replay.replay_speed > 0 || (--phase<=0)) { short flag_count= MAX(replay.replay_speed, 1); if (!pull_flags_from_recording(flag_count)) // oops. silly me. { if (replay.have_read_last_chunk) { assert(get_game_state()==_game_in_progress || get_game_state()==_switch_demo); set_game_state(_switch_demo); } } else { /* Increment the heartbeat.. */ heartbeat_count+= flag_count; } /* Reset the phase-> doesn't matter if the replay speed is positive */ /* +1 so that replay_speed 0 is different from replay_speed 1 */ phase= -(replay.replay_speed) + 1; } } } else // then getting input from the keyboard/mouse { long action_flags= parse_keymap(); process_action_flags(local_player_index, &action_flags, 1); heartbeat_count++; // ba-doom } } else { // dprintf("Out of phase.. (%d);g", heartbeat_count - dynamic_world->tick_count); } } return TRUE; // tells the time manager library to reschedule this task }
void update_game(void) { switch(state) { case GAME_STATE_WORLD : if (move_player(game_player, game_world)) set_game_state(GAME_STATE_BATTLE); break; case GAME_STATE_MENU : break; case GAME_STATE_BATTLE : move_battle(game_battle); break; default : break; } }
static void check_esc(int key) { int input = get_input_keydown(key); if (input & PRESS_ESC) { switch(state) { case GAME_STATE_WORLD : set_game_state(GAME_STATE_MENU); break; case GAME_STATE_MAP : set_game_state(GAME_STATE_WORLD); break; case GAME_STATE_STATUS : set_game_state(GAME_STATE_WORLD); break; case GAME_STATE_BATTLE : deinit_battle(game_battle); set_game_state(GAME_STATE_WORLD); break; default : break; } } }
static void handle_game_key(const SDL_Event &event) { SDL_Keycode key = event.key.keysym.sym; SDL_Scancode sc = event.key.keysym.scancode; bool changed_screen_mode = false; bool changed_prefs = false; if (!game_is_networked && (event.key.keysym.mod & KMOD_CTRL) && CheatsActive) { int type_of_cheat = process_keyword_key(key); if (type_of_cheat != NONE) handle_keyword(type_of_cheat); } if (Console::instance()->input_active()) { switch(key) { case SDLK_RETURN: case SDLK_KP_ENTER: Console::instance()->enter(); break; case SDLK_ESCAPE: Console::instance()->abort(); break; case SDLK_BACKSPACE: Console::instance()->backspace(); break; case SDLK_DELETE: Console::instance()->del(); break; case SDLK_UP: Console::instance()->up_arrow(); break; case SDLK_DOWN: Console::instance()->down_arrow(); break; case SDLK_LEFT: Console::instance()->left_arrow(); break; case SDLK_RIGHT: Console::instance()->right_arrow(); break; case SDLK_HOME: Console::instance()->line_home(); break; case SDLK_END: Console::instance()->line_end(); break; case SDLK_a: if (event.key.keysym.mod & KMOD_CTRL) Console::instance()->line_home(); break; case SDLK_b: if (event.key.keysym.mod & KMOD_CTRL) Console::instance()->left_arrow(); break; case SDLK_d: if (event.key.keysym.mod & KMOD_CTRL) Console::instance()->del(); break; case SDLK_e: if (event.key.keysym.mod & KMOD_CTRL) Console::instance()->line_end(); break; case SDLK_f: if (event.key.keysym.mod & KMOD_CTRL) Console::instance()->right_arrow(); break; case SDLK_h: if (event.key.keysym.mod & KMOD_CTRL) Console::instance()->backspace(); break; case SDLK_k: if (event.key.keysym.mod & KMOD_CTRL) Console::instance()->forward_clear(); break; case SDLK_n: if (event.key.keysym.mod & KMOD_CTRL) Console::instance()->down_arrow(); break; case SDLK_p: if (event.key.keysym.mod & KMOD_CTRL) Console::instance()->up_arrow(); break; case SDLK_t: if (event.key.keysym.mod & KMOD_CTRL) Console::instance()->transpose(); break; case SDLK_u: if (event.key.keysym.mod & KMOD_CTRL) Console::instance()->clear(); break; case SDLK_w: if (event.key.keysym.mod & KMOD_CTRL) Console::instance()->delete_word(); break; } } else { if (sc == SDL_SCANCODE_ESCAPE) // (ZZZ) Quit gesture (now safer) { if(!player_controlling_game()) do_menu_item_command(mGame, iQuitGame, false); else { if(get_ticks_since_local_player_in_terminal() > 1 * TICKS_PER_SECOND) { if(!game_is_networked) { do_menu_item_command(mGame, iQuitGame, false); } else { #if defined(__APPLE__) && defined(__MACH__) screen_printf("If you wish to quit, press Command-Q"); #else screen_printf("If you wish to quit, press Alt+Q."); #endif } } } } else if (input_preferences->shell_key_bindings[_key_volume_up].count(sc)) { changed_prefs = SoundManager::instance()->AdjustVolumeUp(Sound_AdjustVolume()); } else if (input_preferences->shell_key_bindings[_key_volume_down].count(sc)) { changed_prefs = SoundManager::instance()->AdjustVolumeDown(Sound_AdjustVolume()); } else if (input_preferences->shell_key_bindings[_key_switch_view].count(sc)) { walk_player_list(); render_screen(NONE); } else if (input_preferences->shell_key_bindings[_key_zoom_in].count(sc)) { if (zoom_overhead_map_in()) PlayInterfaceButtonSound(Sound_ButtonSuccess()); else PlayInterfaceButtonSound(Sound_ButtonFailure()); } else if (input_preferences->shell_key_bindings[_key_zoom_out].count(sc)) { if (zoom_overhead_map_out()) PlayInterfaceButtonSound(Sound_ButtonSuccess()); else PlayInterfaceButtonSound(Sound_ButtonFailure()); } else if (input_preferences->shell_key_bindings[_key_inventory_left].count(sc)) { if (player_controlling_game()) { PlayInterfaceButtonSound(Sound_ButtonSuccess()); scroll_inventory(-1); } else decrement_replay_speed(); } else if (input_preferences->shell_key_bindings[_key_inventory_right].count(sc)) { if (player_controlling_game()) { PlayInterfaceButtonSound(Sound_ButtonSuccess()); scroll_inventory(1); } else increment_replay_speed(); } else if (input_preferences->shell_key_bindings[_key_toggle_fps].count(sc)) { PlayInterfaceButtonSound(Sound_ButtonSuccess()); extern bool displaying_fps; displaying_fps = !displaying_fps; } else if (input_preferences->shell_key_bindings[_key_activate_console].count(sc)) { if (game_is_networked) { #if !defined(DISABLE_NETWORKING) Console::instance()->activate_input(InGameChatCallbacks::SendChatMessage, InGameChatCallbacks::prompt()); #endif PlayInterfaceButtonSound(Sound_ButtonSuccess()); } else if (Console::instance()->use_lua_console()) { PlayInterfaceButtonSound(Sound_ButtonSuccess()); Console::instance()->activate_input(ExecuteLuaString, ">"); } else { PlayInterfaceButtonSound(Sound_ButtonFailure()); } } else if (input_preferences->shell_key_bindings[_key_show_scores].count(sc)) { PlayInterfaceButtonSound(Sound_ButtonSuccess()); { extern bool ShowScores; ShowScores = !ShowScores; } } else if (sc == SDL_SCANCODE_F1) // Decrease screen size { if (!graphics_preferences->screen_mode.hud) { PlayInterfaceButtonSound(Sound_ButtonSuccess()); graphics_preferences->screen_mode.hud = true; changed_screen_mode = changed_prefs = true; } else { int mode = alephone::Screen::instance()->FindMode(get_screen_mode()->width, get_screen_mode()->height); if (mode < alephone::Screen::instance()->GetModes().size() - 1) { PlayInterfaceButtonSound(Sound_ButtonSuccess()); graphics_preferences->screen_mode.width = alephone::Screen::instance()->ModeWidth(mode + 1); graphics_preferences->screen_mode.height = alephone::Screen::instance()->ModeHeight(mode + 1); graphics_preferences->screen_mode.auto_resolution = false; graphics_preferences->screen_mode.hud = false; changed_screen_mode = changed_prefs = true; } else PlayInterfaceButtonSound(Sound_ButtonFailure()); } } else if (sc == SDL_SCANCODE_F2) // Increase screen size { if (graphics_preferences->screen_mode.hud) { PlayInterfaceButtonSound(Sound_ButtonSuccess()); graphics_preferences->screen_mode.hud = false; changed_screen_mode = changed_prefs = true; } else { int mode = alephone::Screen::instance()->FindMode(get_screen_mode()->width, get_screen_mode()->height); int automode = get_screen_mode()->fullscreen ? 0 : 1; if (mode > automode) { PlayInterfaceButtonSound(Sound_ButtonSuccess()); graphics_preferences->screen_mode.width = alephone::Screen::instance()->ModeWidth(mode - 1); graphics_preferences->screen_mode.height = alephone::Screen::instance()->ModeHeight(mode - 1); if ((mode - 1) == automode) graphics_preferences->screen_mode.auto_resolution = true; graphics_preferences->screen_mode.hud = true; changed_screen_mode = changed_prefs = true; } else PlayInterfaceButtonSound(Sound_ButtonFailure()); } } else if (sc == SDL_SCANCODE_F3) // Resolution toggle { if (!OGL_IsActive()) { PlayInterfaceButtonSound(Sound_ButtonSuccess()); graphics_preferences->screen_mode.high_resolution = !graphics_preferences->screen_mode.high_resolution; changed_screen_mode = changed_prefs = true; } else PlayInterfaceButtonSound(Sound_ButtonFailure()); } else if (sc == SDL_SCANCODE_F4) // Reset OpenGL textures { #ifdef HAVE_OPENGL if (OGL_IsActive()) { // Play the button sound in advance to get the full effect of the sound PlayInterfaceButtonSound(Sound_OGL_Reset()); OGL_ResetTextures(); } else #endif PlayInterfaceButtonSound(Sound_ButtonInoperative()); } else if (sc == SDL_SCANCODE_F5) // Make the chase cam switch sides { if (ChaseCam_IsActive()) PlayInterfaceButtonSound(Sound_ButtonSuccess()); else PlayInterfaceButtonSound(Sound_ButtonInoperative()); ChaseCam_SwitchSides(); } else if (sc == SDL_SCANCODE_F6) // Toggle the chase cam { PlayInterfaceButtonSound(Sound_ButtonSuccess()); ChaseCam_SetActive(!ChaseCam_IsActive()); } else if (sc == SDL_SCANCODE_F7) // Toggle tunnel vision { PlayInterfaceButtonSound(Sound_ButtonSuccess()); SetTunnelVision(!GetTunnelVision()); } else if (sc == SDL_SCANCODE_F8) // Toggle the crosshairs { PlayInterfaceButtonSound(Sound_ButtonSuccess()); player_preferences->crosshairs_active = !player_preferences->crosshairs_active; Crosshairs_SetActive(player_preferences->crosshairs_active); changed_prefs = true; } else if (sc == SDL_SCANCODE_F9) // Screen dump { dump_screen(); } else if (sc == SDL_SCANCODE_F10) // Toggle the position display { PlayInterfaceButtonSound(Sound_ButtonSuccess()); { extern bool ShowPosition; ShowPosition = !ShowPosition; } } else if (sc == SDL_SCANCODE_F11) // Decrease gamma level { if (graphics_preferences->screen_mode.gamma_level) { PlayInterfaceButtonSound(Sound_ButtonSuccess()); graphics_preferences->screen_mode.gamma_level--; change_gamma_level(graphics_preferences->screen_mode.gamma_level); changed_prefs = true; } else PlayInterfaceButtonSound(Sound_ButtonFailure()); } else if (sc == SDL_SCANCODE_F12) // Increase gamma level { if (graphics_preferences->screen_mode.gamma_level < NUMBER_OF_GAMMA_LEVELS - 1) { PlayInterfaceButtonSound(Sound_ButtonSuccess()); graphics_preferences->screen_mode.gamma_level++; change_gamma_level(graphics_preferences->screen_mode.gamma_level); changed_prefs = true; } else PlayInterfaceButtonSound(Sound_ButtonFailure()); } else { if (get_game_controller() == _demo) set_game_state(_close_game); } } if (changed_screen_mode) { screen_mode_data temp_screen_mode = graphics_preferences->screen_mode; temp_screen_mode.fullscreen = get_screen_mode()->fullscreen; change_screen_mode(&temp_screen_mode, true); render_screen(0); } if (changed_prefs) write_preferences(); }
static void process_event(const SDL_Event &event) { switch (event.type) { case SDL_MOUSEMOTION: if (get_game_state() == _game_in_progress) { mouse_moved(event.motion.xrel, event.motion.yrel); } break; case SDL_MOUSEWHEEL: if (get_game_state() == _game_in_progress) { bool up = (event.wheel.y > 0); #if SDL_VERSION_ATLEAST(2,0,4) if (event.wheel.direction == SDL_MOUSEWHEEL_FLIPPED) up = !up; #endif mouse_scroll(up); } break; case SDL_MOUSEBUTTONDOWN: if (get_game_state() == _game_in_progress) { if (!get_keyboard_controller_status()) { hide_cursor(); validate_world_window(); set_keyboard_controller_status(true); } else { SDL_Event e2; memset(&e2, 0, sizeof(SDL_Event)); e2.type = SDL_KEYDOWN; e2.key.keysym.sym = SDLK_UNKNOWN; e2.key.keysym.scancode = (SDL_Scancode)(AO_SCANCODE_BASE_MOUSE_BUTTON + event.button.button - 1); process_game_key(e2); } } else process_screen_click(event); break; case SDL_JOYBUTTONDOWN: if (get_game_state() == _game_in_progress) { SDL_Event e2; memset(&e2, 0, sizeof(SDL_Event)); e2.type = SDL_KEYDOWN; e2.key.keysym.sym = SDLK_UNKNOWN; e2.key.keysym.scancode = (SDL_Scancode)(AO_SCANCODE_BASE_JOYSTICK_BUTTON + event.button.button); process_game_key(e2); } break; case SDL_KEYDOWN: process_game_key(event); break; case SDL_TEXTINPUT: if (Console::instance()->input_active()) { Console::instance()->textEvent(event); } break; case SDL_QUIT: set_game_state(_quit_game); break; case SDL_WINDOWEVENT: switch (event.window.event) { case SDL_WINDOWEVENT_FOCUS_LOST: if (get_game_state() == _game_in_progress && get_keyboard_controller_status() && !Movie::instance()->IsRecording()) { darken_world_window(); set_keyboard_controller_status(false); show_cursor(); } break; case SDL_WINDOWEVENT_EXPOSED: #if !defined(__APPLE__) && !defined(__MACH__) // double buffering :) #ifdef HAVE_OPENGL if (MainScreenIsOpenGL()) MainScreenSwap(); else #endif update_game_window(); #endif break; } break; } }