// ********************************************************************************************** // // // // ********************************************************************************************** // int inputLib::waitScapeTime(int wait_period) { int now_time = 0; waitTime(50); now_time = timer.getTimer(); wait_period = now_time + wait_period; while (now_time < wait_period) { readInput(); if (p1_input[BTN_START] == 1 || p2_input[BTN_START] == 1) { return 1; } else if (p1_input[BTN_QUIT] == 1 || p2_input[BTN_QUIT] == 1) { #if !defined(PLAYSTATION2) && !defined(PSP) && !defined(WII) && !defined(DREAMCAST) std::cout << "LEAVE #2" << std::endl; std::fflush(stdout); gameControl.leave_game(); #endif } now_time = timer.getTimer(); #ifdef PLAYSTATION RotateThreadReadyQueue(_MIXER_THREAD_PRIORITY); #endif SDL_Delay(5); } return 0; }
void sceneShow::show_animation(int n, int repeat_n, int repeat_mode) { int frame_n = 0; CURRENT_FILE_FORMAT::file_scene_show_animation scene = animation_list.at(n); long frame_timer = timer.getTimer() + scene.frame_delay; long started_timer = timer.getTimer(); int repeat_times = 0; graphicsLib_gSurface image; graphLib.surfaceFromFile(FILEPATH + "images/scenes/animations/" + scene.filename, &image); int max_frames = image.width / scene.frame_w; graphicsLib_gSurface bg_image; graphLib.initSurface(st_size(scene.frame_w, scene.frame_h), &bg_image); graphLib.copy_gamescreen_area(st_rectangle(scene.x, scene.y, scene.frame_w, scene.frame_h), st_position(0, 0), &bg_image); while (true) { std::cout << "sceneShow::show_animation::LOOP" << std::endl; //graphLib.showSurfaceAt(&bg_image, st_position(scene.x, scene.y), false); int x = frame_n*scene.frame_w; std::cout << "origin.x: " << x << ", dest.x: " << scene.x << ", frame.w: " << scene.frame_w << ", frame.h: " << scene.frame_h << std::endl; graphLib.showSurfaceRegionAt(&image, st_rectangle(x, 0, scene.frame_w, scene.frame_h), st_position(scene.x, scene.y)); graphLib.updateScreen(); if (frame_timer < timer.getTimer()) { frame_n++; if (frame_n > max_frames) { frame_n = 0; repeat_times++; } frame_timer = timer.getTimer() + scene.frame_delay; } // stop condition if (repeat_times > 0 && repeat_n <= 1) { std::cout << "sceneShow::show_animation::LEAVE#1" << std::endl; return; } else { if (repeat_mode == 0) { // time-mode if ((timer.getTimer() - started_timer) > repeat_n) { std::cout << "sceneShow::show_animation::LEAVE#2" << std::endl; return; } } else { // repeat number mode if (repeat_times > repeat_n) { std::cout << "sceneShow::show_animation::LEAVE#3" << std::endl; return; } } } timer.delay(10); } }
void classboss::boss_move() { if (state.move_timer > timer.getTimer()) { return; } if (_initialized == 0) { /// @TODO: move this logic to map (player should not move while boss is presenting) _initialized++; gameControl.boss_intro(); return; } else if (_initialized == 1) { if (position.x > RES_H/2 && gravity(true) == false) { _initialized++; } state.move_timer = timer.getTimer()+100; return; } //std::cout << "classboss::move [" << name << "]" << std::endl; /* int mapScrollX = map->getMapScrolling().x; int lock_point = map->getMapPointLock(st_position(position.x/16, position.y/16)); struct struct_player_dist dist_players = dist_npc_players(); */ if (first_run == 0) { // show boss dialogs here first_run = 1; //boss_energy = temp_npc; //play_boss_music(); //show_dialog(STAGE_N, 1); } if (name == "Daisie Bot") { exec_daisiebot(); //npc_gravity(temp_npc); return; } else if (name == "Ape Bot") { //exec_IA_Apebot(temp_npc); //exec_daisiebot(); return; } else { gravity(false); return; } }
// ********************************************************************************************** // // // // ********************************************************************************************** // void inputLib::waitTime(int wait_period) const { /* #ifdef PLAYSTATION2 if (wait_period < 20) { return; } #endif */ int now_time=0; now_time = timer.getTimer(); wait_period = now_time + wait_period; while (now_time < wait_period) { now_time = timer.getTimer(); SDL_Delay(1); #ifdef PLAYSTATION RotateThreadReadyQueue(_MIXER_THREAD_PRIORITY); #endif graphLib.updateScreen(); } }
void draw::show_rain() { if (rain_obj.gSurface == NULL) { // load rain std::string filename = FILEPATH + "/data/images/tilesets/rain.png"; graphLib.surfaceFromFile(filename, &rain_obj); } for (int i=0; i<MAP_W; i++) { for (int j=0; j<MAP_H; j++) { graphLib.showSurfaceRegionAt(&rain_obj, st_rectangle(_rain_pos*TILESIZE, 0, TILESIZE, TILESIZE), st_position(i*TILESIZE, j*TILESIZE)); } } if (timer.getTimer() > _rain_timer) { _rain_pos++; if (_rain_pos > 2) { _rain_pos = 0; } _rain_timer = timer.getTimer() + RAIN_DELAY; } }
void inputLib::readInput() { _used_keyboard = false; while (SDL_PollEvent(&event)) { if (_show_btn_debug == false) { _show_btn_debug = true; } if (game_config.input_type == INPUT_TYPE_DOUBLE || game_config.input_type == INPUT_TYPE_KEYBOARD) { if (event.type == SDL_KEYDOWN) { for (int i=0; i<BTN_COUNT; i++) { if (game_config.keys_codes[i] != -1 && game_config.keys_codes[i] == event.key.keysym.sym) { p1_input[i] = 1; _used_keyboard = true; if (i == BTN_JUMP) { p1_input[BTN_JUMP_TIMER] = timer.getTimer(); } } } } else if (event.type == SDL_KEYUP) { for (int i=0; i<BTN_COUNT; i++) { if (game_config.keys_codes[i] != -1 && game_config.keys_codes[i] == event.key.keysym.sym) { p1_input[i] = 0; _used_keyboard = true; if (i == BTN_JUMP) { p1_input[BTN_JUMP_TIMER] = 0; } } } } SDL_PumpEvents(); // check keyboard events #if !defined(PLAYSTATION2) && !defined(PSP) && !defined(WII) && !defined(DREAMCAST) if (event.type == SDL_QUIT) { std::cout << "LEAVE #1" << std::endl; std::fflush(stdout); gameControl.leave_game(); } #endif } if (_used_keyboard == true) { // next commands are all joystick only return; } if (game_config.input_type == INPUT_TYPE_DOUBLE || game_config.input_type == INPUT_TYPE_JOYSTICK) { if (event.type == SDL_JOYBUTTONDOWN) { //std::cout << "#1 INPUT::readInput - joystick button[" << (int)event.jbutton.button << "] pressed." << std::endl; for (int i=0; i<BTN_COUNT; i++) { //std::cout << "#1 INPUT::readInput - button_codes[" << i << "]: " << game_config.button_codes[i] << std::endl; if (game_config.button_codes[i] != -1 && game_config.button_codes[i] == event.jbutton.button) { //std::cout << "#1 INPUT::readInput - FOUND ACTION for i: " << i << std::endl; p1_input[i] = 1; if (i == BTN_JUMP) { p1_input[BTN_JUMP_TIMER] = timer.getTimer(); } //break; } } } else if (event.type == SDL_JOYBUTTONUP) { //std::cout << "#2 INPUT::readInput - joystick button[" << event.jbutton.button << "] released" << std::endl; for (int i=0; i<BTN_COUNT; i++) { if (game_config.button_codes[i] != -1 && game_config.button_codes[i] == event.jbutton.button) { p1_input[i] = 0; if (i == BTN_JUMP) { p1_input[BTN_JUMP_TIMER] = 0; } break; } } } } if ((game_config.input_mode == INPUT_MODE_ANALOG || game_config.input_mode == INPUT_MODE_DOUBLE) && event.type == SDL_JOYAXISMOTION) { if (event.jaxis.axis == 0) { if (event.jaxis.value < -JOYVAL) { p1_input[BTN_RIGHT] = 0; p1_input[BTN_LEFT] = 1; _used_keyboard = false; } else if (event.jaxis.value > JOYVAL) { p1_input[BTN_RIGHT] = 1; p1_input[BTN_LEFT] = 0; _used_keyboard = false; } else if ((event.jaxis.value < JOYVAL || event.jaxis.value > -JOYVAL) && _used_keyboard == false) { p1_input[BTN_RIGHT] = 0; p1_input[BTN_LEFT] = 0; } } if (event.jaxis.axis == 1) { if (event.jaxis.value < -JOYVAL) { p1_input[BTN_DOWN] = 0; p1_input[BTN_UP] = 1; _used_keyboard = false; } else if (event.jaxis.value > JOYVAL) { p1_input[BTN_DOWN] = 1; p1_input[BTN_UP] = 0; _used_keyboard = false; } else if ((event.jaxis.value < JOYVAL || event.jaxis.value > -JOYVAL) && _used_keyboard == false) { p1_input[BTN_DOWN] = 0; p1_input[BTN_UP] = 0; } } } if ((game_config.input_mode == INPUT_MODE_DIGITAL || game_config.input_mode == INPUT_MODE_DOUBLE) && event.type == SDL_JOYHATMOTION) { // CODES: up - 1, right: 2, down: 4, left: 8 if (event.jhat.value == 1 || event.jhat.value == 3 || event.jhat.value == 9) { // up p1_input[BTN_DOWN] = 0; p1_input[BTN_UP] = 1; _used_keyboard = false; } if (event.jhat.value == 2 || event.jhat.value == 3 || event.jhat.value == 6) { // right p1_input[BTN_RIGHT] = 1; p1_input[BTN_LEFT] = 0; _used_keyboard = false; } if (event.jhat.value == 4 || event.jhat.value == 6 || event.jhat.value == 12) { // down p1_input[BTN_DOWN] = 1; p1_input[BTN_UP] = 0; _used_keyboard = false; } if (event.jhat.value == 8 || event.jhat.value == 9 || event.jhat.value == 12) { // left p1_input[BTN_LEFT] = 1; p1_input[BTN_RIGHT] = 0; _used_keyboard = false; } if (event.jhat.value == 0 && _used_keyboard == false) { p1_input[BTN_LEFT] = 0; p1_input[BTN_RIGHT] = 0; p1_input[BTN_DOWN] = 0; p1_input[BTN_UP] = 0; } } } }
void classboss::exec_daisiebot() { unsigned short int shot_type = IA_STATE_SHOT_RAINBOW; std::cout << "classboss::exec_daisiebot" << std::endl; if (IA_state == IA_STATE_WAIT_TIME) { IA_state = IA_STAND; } // stand -> shot rainbow -> cross screen -> use flowers if (IA_state == IA_STAND) { IA_state = IA_STATE_CROSS_SCREEN; state.animation_type = ANIM_TYPE_WALK; return; } if (IA_state == IA_STATE_SHOT_RAINBOW) { state.animation_type = ANIM_TYPE_STAND; /// @TODO (use attacks/weapons system) shot_rainbow(); IA_state = IA_STATE_CROSS_SCREEN; initial_position.x = position.x; initial_position.y = position.y; IA_state = IA_STATE_WAIT_TIME; state.move_timer = timer.getTimer()+300; } if (IA_state == IA_STATE_SHOT_FLOWER) { state.animation_type = ANIM_TYPE_STAND; /// @TODO (use attacks/weapons system) shot_flower(temp_npc); /// temp_npc->projectile.timer = getTimer()+60; initial_position.x = position.x; initial_position.y = position.y; IA_state = IA_STATE_WAIT_TIME; state.move_timer = timer.getTimer()+3000; } // TODO: move to generic npc, once more will use it if (IA_state == IA_STATE_CROSS_SCREEN) { // check if must stop/invert state.move_timer = timer.getTimer() + 10; if (state.direction == ANIM_DIRECTION_LEFT) { int map_tile_x = (position.x-move_speed)/16; int map_tile_y = position.y/16; if (distance.width < 18*TILESIZE && (position.x-move_speed > 0 && (map->getMapPointLock(st_position(map_tile_x, map_tile_y)) == 0 || map->getMapPointLock(st_position(map_tile_x, map_tile_y)) == TERRAIN_WATER))) { position.x-= move_speed; distance.width += move_speed; } else { distance.width = 0; invert_direction(); if (shot_type == IA_STATE_SHOT_RAINBOW) { shot_type = IA_STATE_SHOT_FLOWER; } else { shot_type = IA_STATE_SHOT_RAINBOW; } IA_state = shot_type; } } else { // ANIM_RIGHT int map_tile_x = (position.x+frameSize.width+move_speed)/16; int map_tile_y = position.y/16; //map->getMapPointLock(st_position(map_tile_x, map_tile_y)) if (distance.width < 18*TILESIZE && (map->getMapPointLock(st_position(map_tile_x, map_tile_y)) == 0 || map->getMapPointLock(st_position(map_tile_x, map_tile_y)) == TERRAIN_WATER)) { position.x+= move_speed; distance.width += move_speed; } else { distance.width = 0; invert_direction(); IA_state = shot_type; } } } }
void sceneShow::show_animation(int n, int repeat_n, int repeat_mode) { int frame_n = 0; CURRENT_FILE_FORMAT::file_scene_show_animation scene = animation_list.at(n); long frame_timer = timer.getTimer() + scene.frame_delay; long started_timer = timer.getTimer(); int repeat_times = 0; graphicsLib_gSurface image; graphLib.surfaceFromFile(FILEPATH + "images/scenes/animations/" + scene.filename, &image); int max_frames = image.width / scene.frame_w; graphicsLib_gSurface bg_image; graphLib.initSurface(st_size(scene.frame_w, scene.frame_h), &bg_image); graphLib.copy_gamescreen_area(st_rectangle(scene.x, scene.y, scene.frame_w, scene.frame_h), st_position(0, 0), &bg_image); std::cout << "max_frames[" << max_frames << "], image.w[" << image.width << "], scene.frame_w[" << scene.frame_w << "]" << std::endl; while (true) { input.read_input(); int x = frame_n*scene.frame_w; // stop condition if (repeat_times > 0 && repeat_n <= 1) { std::cout << "sceneShow::show_animation::LEAVE#1" << std::endl; break; } else { if (repeat_mode == 0) { // time-mode if ((timer.getTimer() - started_timer) > repeat_n) { std::cout << "sceneShow::show_animation::LEAVE#2" << std::endl; break; } } else { // repeat number mode if (repeat_times > repeat_n) { std::cout << "sceneShow::show_animation::LEAVE#3" << std::endl; break; } } } graphLib.showSurfaceAt(&bg_image, st_position(scene.x, scene.y), false); std::cout << "x[" << x << "], img.w[" << image.width << "], frame.w[" << scene.frame_w << "]" << std::endl; graphLib.showSurfaceRegionAt(&image, st_rectangle(x, 0, scene.frame_w, scene.frame_h), st_position(scene.x, scene.y)); graphLib.updateScreen(); timer.delay(scene.frame_delay); if (frame_timer < timer.getTimer()) { frame_n++; if (frame_n >= max_frames) { frame_n = 0; repeat_times++; } frame_timer = timer.getTimer() + scene.frame_delay; } } // avoid leaving animation image trail if it is a repeating one if (repeat_n > 1) { graphLib.showSurfaceAt(&bg_image, st_position(scene.x, scene.y), false); graphLib.updateScreen(); timer.delay(scene.frame_delay); } }