int Game_Character::EndJump(const RPG::MoveRoute* current_route, int current_index) { jumping = false; if (!IsLandable(jump_x + jump_plus_x, jump_y + jump_plus_y)) { // Reset to begin jump command and try again... move_failed = true; if (current_route->skippable) { return current_index; } return jump_index; } SetX(jump_x + jump_plus_x); SetY(jump_y + jump_plus_y); //TODO: C++11 got round() function defined in math.h float distance = sqrt((float)(jump_plus_x * jump_plus_x + jump_plus_y * jump_plus_y)); if (distance >= floor(distance) + 0.5) distance = ceil(distance); else distance = floor(distance); jump_peak = 10 + (int)distance - GetMoveSpeed(); move_count = jump_peak * 2; stop_count = 0; move_failed = false; return current_index; }
void Game_Character::BeginJump(const RPG::MoveRoute* current_route, int* current_index) { jump_x = GetX(); jump_y = GetY(); jump_plus_x = 0; jump_plus_y = 0; jumping = true; bool end_found = false; unsigned int i; for (i = *current_index; i < current_route->move_commands.size(); ++i) { const RPG::MoveCommand& move_command = current_route->move_commands[i]; switch (move_command.command_id) { case RPG::MoveCommand::Code::move_up: case RPG::MoveCommand::Code::move_right: case RPG::MoveCommand::Code::move_down: case RPG::MoveCommand::Code::move_left: case RPG::MoveCommand::Code::move_upright: case RPG::MoveCommand::Code::move_downright: case RPG::MoveCommand::Code::move_downleft: case RPG::MoveCommand::Code::move_upleft: Move(move_command.command_id); break; case RPG::MoveCommand::Code::move_random: MoveRandom(); break; case RPG::MoveCommand::Code::move_towards_hero: MoveTowardsPlayer(); break; case RPG::MoveCommand::Code::move_away_from_hero: MoveAwayFromPlayer(); break; case RPG::MoveCommand::Code::move_forward: MoveForward(); break; default: break; } if (move_command.command_id == RPG::MoveCommand::Code::end_jump) { end_found = true; break; } } if (!end_found) { // No EndJump found. Move route ends directly *current_index = i; jumping = false; return; } int new_x = jump_x + jump_plus_x; int new_y = jump_y + jump_plus_y; if (Game_Map::LoopHorizontal()) { int map_width = Game_Map::GetWidth(); if (new_x < 0) { jump_x += map_width; new_x += map_width; } else if (new_x >= map_width) { jump_x -= map_width; new_x -= map_width; } } if (Game_Map::LoopVertical()) { int map_height = Game_Map::GetHeight(); if (new_y < 0) { jump_y += map_height; new_y += map_height; } else if (new_y >= map_height) { jump_y -= map_height; new_y -= map_height; } } if ( // A character can always land on a tile they were already standing on !(jump_plus_x == 0 && jump_plus_y == 0) && !IsLandable(new_x, new_y) ) { // Reset to begin jump command and try again... move_failed = true; jumping = false; if (current_route->skippable) { *current_index = i; return; } return; } SetX(new_x); SetY(new_y); *current_index = i; remaining_step = SCREEN_TILE_WIDTH; stop_count = 0; max_stop_count = (GetMoveFrequency() > 7) ? 0 : pow(2.0, 9 - GetMoveFrequency()); move_failed = false; }