void Game_Event::MoveTypeAwayFromPlayer() { int sx = DistanceXfromPlayer(); int sy = DistanceYfromPlayer(); int last_direction = GetDirection(); if ( std::abs(sx) + std::abs(sy) >= 20 ) { MoveRandom(); } else { switch (Utils::GetRandomNumber(0, 5)) { case 0: MoveRandom(); break; case 1: MoveForward(); break; default: MoveAwayFromPlayer(); } } if (move_failed && !starting) { if (stop_count >= max_stop_count + 60) { stop_count = 0; } else { SetDirection(last_direction); if (!(IsDirectionFixed() || IsFacingLocked())) SetSpriteDirection(last_direction); } } }
void Game_Character::MoveTypeAwayFromPlayer() { if (IsStopping()) { int sx = x - Main_Data::game_player->GetX(); int sy = y - Main_Data::game_player->GetY(); if ( std::abs(sx) + std::abs(sy) >= 20 ) { MoveRandom(); } else { switch (rand() % 6) { case 0: MoveRandom(); break; case 1: MoveForward(); break; default: MoveAwayFromPlayer(); } } } }
void Game_Character::MoveTypeRandom() { if (IsStopping()) { switch (rand() % 6) { case 0: stop_count = 0; break; case 1: case 2: MoveRandom(); break; default: MoveForward(); } } }
// Define the main function int main() { // Seed the random number generator srandom(0); NcInit(); Init(); for (int time = 0; time < TIME_COUNT; time++) { NcOutput(time); StickParticles(); MoveRandom(); } NcFinalize(); return 0; }
//движение монстров void MovingMonsters::Move() { _fullFieldLeft = GameField::Get()->_fieldLeft; _fullFieldRight = GameField::Get()->_fieldRight; _fullFieldTop = GameField::Get()->_fieldTop; _fullFieldBottom = GameField::Get()->_fieldBottom; _fieldLeft = Game::activeRect.x; //это размеры активной области _fieldRight = Game::activeRect.x + Game::activeRect.width - 1; _fieldTop = Game::activeRect.y + Game::activeRect.height - 1; _fieldBottom = Game::activeRect.y; //грузим и распространяем энергию LoadEnergy(); GrowEnergy(); _someMonsterStillCanMove = true; while (_someMonsterStillCanMove) { //грузим состояние игры LoadGameState(); //проверяем что монстры вообще есть if (_monstersPositions.empty()) { _movesToRecievers.Release(); break; } _someMonsterStillCanMove = false; if (!_haveRecieversOnScreen) //если приемников нету ходим рандомно { MoveRandom(); } else { //////////////////////// этап 1////////////////////////////////////////////// MoveRound1(); //////////////////////// этап 2////////////////////////////////////////////// MoveRound2(); } //чистим массив _movesToRecievers.Release(); } _energy.Release(); GameField::Get()->_maybeMoveGadget.NeedUpdate(); //возможно, кончились ходы }
MenuCodeEnum MI_SelectField::SendInput(CPlayerInput * playerInput) { for (int iPlayer = 0; iPlayer < 4; iPlayer++) { short iNumMoves = 1; if (fFastScroll && playerInput->outputControls[iPlayer].menu_scrollfast.fDown) iNumMoves = 10; if (playerInput->outputControls[iPlayer].menu_right.fPressed || playerInput->outputControls[iPlayer].menu_down.fPressed) { bool fMoved = false; for (short iMove = 0; iMove < iNumMoves; iMove++) fMoved |= MoveNext(); if (fMoved) return mcItemChangedCode; } if (playerInput->outputControls[iPlayer].menu_left.fPressed || playerInput->outputControls[iPlayer].menu_up.fPressed) { bool fMoved = false; for (short iMove = 0; iMove < iNumMoves; iMove++) fMoved |= MovePrev(); if (fMoved) return mcItemChangedCode; } if (playerInput->outputControls[iPlayer].menu_random.fPressed) { if (MoveRandom()) return mcItemChangedCode; } if (playerInput->outputControls[iPlayer].menu_select.fPressed || playerInput->outputControls[iPlayer].menu_cancel.fPressed) { miModifyImageLeft->Show(false); miModifyImageRight->Show(false); fModifying = false; SetValues(); return MENU_CODE_UNSELECT_ITEM; } } return MENU_CODE_NONE; }
void Game_Event::MoveTypeRandom() { int last_direction = GetDirection(); switch (Utils::GetRandomNumber(0, 5)) { case 0: stop_count -= Utils::GetRandomNumber(0, stop_count); if (stop_count < 0) { stop_count = 0; } return; case 1: MoveForward(); break; default: MoveRandom(); } if (move_failed && !starting) { SetDirection(last_direction); if (!(IsDirectionFixed() || IsFacingLocked())) SetSpriteDirection(last_direction); } else { max_stop_count = max_stop_count / 5 * Utils::GetRandomNumber(3, 6); } }
void Game_Character::MoveTypeCustom() { if (IsStopping()) { move_failed = false; if ((size_t)move_route_index >= move_route->move_commands.size()) { // End of Move list if (move_route->repeat) { move_route_index = 0; } else if (move_route_forcing) { move_route_forcing = false; if (move_route_owner != NULL) { move_route_owner->EndMoveRoute(move_route); } move_route = original_move_route; move_route_index = original_move_route_index; original_move_route = NULL; } } else { RPG::MoveCommand& move_command = move_route->move_commands[move_route_index]; switch (move_command.command_id) { case RPG::MoveCommand::Code::move_up: MoveUp(); break; case RPG::MoveCommand::Code::move_right: MoveRight(); break; case RPG::MoveCommand::Code::move_down: MoveDown(); break; case RPG::MoveCommand::Code::move_left: MoveLeft(); break; case RPG::MoveCommand::Code::move_upright: break; case RPG::MoveCommand::Code::move_downright: break; case RPG::MoveCommand::Code::move_downleft: break; case RPG::MoveCommand::Code::move_upleft: 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; case RPG::MoveCommand::Code::face_up: TurnUp(); break; case RPG::MoveCommand::Code::face_right: TurnRight(); break; case RPG::MoveCommand::Code::face_down: TurnDown(); break; case RPG::MoveCommand::Code::face_left: TurnLeft(); break; case RPG::MoveCommand::Code::turn_90_degree_right: Turn90DegreeRight(); break; case RPG::MoveCommand::Code::turn_90_degree_left: Turn90DegreeLeft(); break; case RPG::MoveCommand::Code::turn_180_degree: Turn180Degree(); break; case RPG::MoveCommand::Code::turn_90_degree_random: Turn90DegreeLeftOrRight(); break; case RPG::MoveCommand::Code::face_random_direction: break; case RPG::MoveCommand::Code::face_hero: break; case RPG::MoveCommand::Code::face_away_from_hero: break; case RPG::MoveCommand::Code::wait: break; case RPG::MoveCommand::Code::begin_jump: break; case RPG::MoveCommand::Code::end_jump: break; case RPG::MoveCommand::Code::lock_facing: Lock(); break; case RPG::MoveCommand::Code::unlock_facing: Unlock(); break; case RPG::MoveCommand::Code::increase_movement_speed: move_speed = min(move_speed + 1, 6); break; case RPG::MoveCommand::Code::decrease_movement_speed: move_speed = max(move_speed - 1, 1); break; case RPG::MoveCommand::Code::increase_movement_frequence: break; case RPG::MoveCommand::Code::decrease_movement_frequence: break; case RPG::MoveCommand::Code::switch_on: // Parameter A: Switch to turn on Game_Switches[move_command.parameter_a] = true; Game_Map::SetNeedRefresh(true); break; case RPG::MoveCommand::Code::switch_off: // Parameter A: Switch to turn off Game_Switches[move_command.parameter_a] = false; Game_Map::SetNeedRefresh(true); break; case RPG::MoveCommand::Code::change_graphic: // String: File, Parameter A: index character_name = move_command.parameter_string; character_index = move_command.parameter_a; break; case RPG::MoveCommand::Code::play_sound_effect: // String: File, Parameters: Volume, Tempo, Balance if (move_command.parameter_string != "(OFF)") { Audio().SE_Play(move_command.parameter_string, move_command.parameter_a, move_command.parameter_b); } break; case RPG::MoveCommand::Code::walk_everywhere_on: through = true; break; case RPG::MoveCommand::Code::walk_everywhere_off: through = false; break; case RPG::MoveCommand::Code::stop_animation: break; case RPG::MoveCommand::Code::start_animation: break; case RPG::MoveCommand::Code::increase_transp: break; // ??? case RPG::MoveCommand::Code::decrease_transp: break; // ??? } if (move_route->skippable || !move_failed) { ++move_route_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; }
void Game_Character::MoveTypeCustom() { // Detect if custom movement or event overwrite const RPG::MoveRoute* active_route; int active_route_index; bool overwrite_changed = IsMoveRouteOverwritten(); if (IsMoveRouteOverwritten()) { active_route = &GetMoveRoute(); active_route_index = GetMoveRouteIndex(); } else { active_route = &original_move_route; active_route_index = GetOriginalMoveRouteIndex(); } if (IsStopping()) { move_failed = false; for (; (size_t)active_route_index < active_route->move_commands.size(); ++active_route_index) { if (!IsStopping() || wait_count > 0 || stop_count < max_stop_count) break; const RPG::MoveCommand& move_command = active_route->move_commands[active_route_index]; 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; case RPG::MoveCommand::Code::face_up: Turn(Up); break; case RPG::MoveCommand::Code::face_right: Turn(Right); break; case RPG::MoveCommand::Code::face_down: Turn(Down); break; case RPG::MoveCommand::Code::face_left: Turn(Left); break; case RPG::MoveCommand::Code::turn_90_degree_right: Turn90DegreeRight(); break; case RPG::MoveCommand::Code::turn_90_degree_left: Turn90DegreeLeft(); break; case RPG::MoveCommand::Code::turn_180_degree: Turn180Degree(); break; case RPG::MoveCommand::Code::turn_90_degree_random: Turn90DegreeLeftOrRight(); break; case RPG::MoveCommand::Code::face_random_direction: FaceRandomDirection(); break; case RPG::MoveCommand::Code::face_hero: TurnTowardHero(); break; case RPG::MoveCommand::Code::face_away_from_hero: TurnAwayFromHero(); break; case RPG::MoveCommand::Code::wait: Wait(); break; case RPG::MoveCommand::Code::begin_jump: BeginJump(active_route, &active_route_index); break; case RPG::MoveCommand::Code::end_jump: // EndJump(); break; case RPG::MoveCommand::Code::lock_facing: SetFacingLocked(true); break; case RPG::MoveCommand::Code::unlock_facing: SetFacingLocked(false); break; case RPG::MoveCommand::Code::increase_movement_speed: SetMoveSpeed(min(GetMoveSpeed() + 1, 6)); break; case RPG::MoveCommand::Code::decrease_movement_speed: SetMoveSpeed(max(GetMoveSpeed() - 1, 1)); break; case RPG::MoveCommand::Code::increase_movement_frequence: SetMoveFrequency(min(GetMoveFrequency() + 1, 8)); break; case RPG::MoveCommand::Code::decrease_movement_frequence: SetMoveFrequency(max(GetMoveFrequency() - 1, 1)); break; case RPG::MoveCommand::Code::switch_on: // Parameter A: Switch to turn on Game_Switches[move_command.parameter_a] = true; Game_Map::SetNeedRefresh(Game_Map::Refresh_All); break; case RPG::MoveCommand::Code::switch_off: // Parameter A: Switch to turn off Game_Switches[move_command.parameter_a] = false; Game_Map::SetNeedRefresh(Game_Map::Refresh_All); break; case RPG::MoveCommand::Code::change_graphic: // String: File, Parameter A: index SetGraphic(move_command.parameter_string, move_command.parameter_a); break; case RPG::MoveCommand::Code::play_sound_effect: // String: File, Parameters: Volume, Tempo, Balance if (move_command.parameter_string != "(OFF)" && move_command.parameter_string != "(Brak)") { RPG::Sound sound; sound.name = move_command.parameter_string; sound.volume = move_command.parameter_a; sound.tempo = move_command.parameter_b; sound.balance = move_command.parameter_c; Game_System::SePlay(sound); } break; case RPG::MoveCommand::Code::walk_everywhere_on: through = true; break; case RPG::MoveCommand::Code::walk_everywhere_off: through = false; break; case RPG::MoveCommand::Code::stop_animation: walk_animation = false; break; case RPG::MoveCommand::Code::start_animation: walk_animation = true; break; case RPG::MoveCommand::Code::increase_transp: SetOpacity(max(40, GetOpacity() - 45)); break; case RPG::MoveCommand::Code::decrease_transp: SetOpacity(GetOpacity() + 45); break; } last_move_failed = move_failed; if (move_failed) { if (active_route->skippable) { last_move_failed = false; continue; } break; } } if ((size_t)active_route_index >= active_route->move_commands.size() && IsStopping()) { // End of Move list if (active_route->repeat) { active_route_index = 0; SetMoveRouteRepeated(true); } else if (IsMoveRouteOverwritten()) { CancelMoveRoute(); Game_Map::RemovePendingMove(this); stop_count = 0; } } } // When the overwrite status changed the active_index belongs to the // current non-active move route if (overwrite_changed != IsMoveRouteOverwritten()) { if (IsMoveRouteOverwritten()) { SetOriginalMoveRouteIndex(active_route_index); } else { SetMoveRouteIndex(active_route_index); } } else { if (IsMoveRouteOverwritten()) { SetMoveRouteIndex(active_route_index); } else { SetOriginalMoveRouteIndex(active_route_index); } } }
void Game_Character::MoveTypeCustom() { // Detect if custom movement or event overwrite const RPG::MoveRoute* active_route; int active_route_index; bool overwrite_changed = IsMoveRouteOverwritten(); if (IsMoveRouteOverwritten()) { active_route = &GetMoveRoute(); active_route_index = GetMoveRouteIndex(); } else { active_route = &original_move_route; active_route_index = GetOriginalMoveRouteIndex(); } if (IsStopping()) { move_failed = false; if ((size_t)active_route_index >= active_route->move_commands.size()) { // End of Move list if (active_route->repeat) { active_route_index = 0; SetMoveRouteRepeated(true); } else if (IsMoveRouteOverwritten()) { SetMoveRouteOverwritten(false); EndMoveRoute(); stop_count = 0; } } else { do { const RPG::MoveCommand& move_command = active_route->move_commands[active_route_index]; int command_id = move_command.command_id; if (!jumping && command_id == RPG::MoveCommand::Code::begin_jump) { active_route_index = BeginJump(active_route, active_route_index); } switch (move_command.command_id) { case RPG::MoveCommand::Code::move_up: MoveUp(); break; case RPG::MoveCommand::Code::move_right: MoveRight(); break; case RPG::MoveCommand::Code::move_down: MoveDown(); break; case RPG::MoveCommand::Code::move_left: MoveLeft(); break; case RPG::MoveCommand::Code::move_upright: MoveUpRight(); break; case RPG::MoveCommand::Code::move_downright: MoveDownRight(); break; case RPG::MoveCommand::Code::move_downleft: MoveDownLeft(); break; case RPG::MoveCommand::Code::move_upleft: MoveUpLeft(); 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; case RPG::MoveCommand::Code::face_up: TurnUp(); break; case RPG::MoveCommand::Code::face_right: TurnRight(); break; case RPG::MoveCommand::Code::face_down: TurnDown(); break; case RPG::MoveCommand::Code::face_left: TurnLeft(); break; case RPG::MoveCommand::Code::turn_90_degree_right: Turn90DegreeRight(); break; case RPG::MoveCommand::Code::turn_90_degree_left: Turn90DegreeLeft(); break; case RPG::MoveCommand::Code::turn_180_degree: Turn180Degree(); break; case RPG::MoveCommand::Code::turn_90_degree_random: Turn90DegreeLeftOrRight(); break; case RPG::MoveCommand::Code::face_random_direction: FaceRandomDirection(); break; case RPG::MoveCommand::Code::face_hero: TurnTowardHero(); break; case RPG::MoveCommand::Code::face_away_from_hero: TurnAwayFromHero(); break; case RPG::MoveCommand::Code::wait: Wait(); break; case RPG::MoveCommand::Code::begin_jump: // Multiple BeginJumps are ignored break; case RPG::MoveCommand::Code::end_jump: active_route_index = EndJump(active_route, active_route_index); break; case RPG::MoveCommand::Code::lock_facing: SetFacingLocked(true); break; case RPG::MoveCommand::Code::unlock_facing: SetFacingLocked(false); break; case RPG::MoveCommand::Code::increase_movement_speed: SetMoveSpeed(min(GetMoveSpeed() + 1, 6)); break; case RPG::MoveCommand::Code::decrease_movement_speed: SetMoveSpeed(max(GetMoveSpeed() - 1, 1)); break; case RPG::MoveCommand::Code::increase_movement_frequence: SetMoveFrequency(min(GetMoveFrequency() + 1, 8)); break; case RPG::MoveCommand::Code::decrease_movement_frequence: SetMoveFrequency(max(GetMoveFrequency() - 1, 1)); break; case RPG::MoveCommand::Code::switch_on: // Parameter A: Switch to turn on Game_Switches[move_command.parameter_a] = true; Game_Map::SetNeedRefresh(true); break; case RPG::MoveCommand::Code::switch_off: // Parameter A: Switch to turn off Game_Switches[move_command.parameter_a] = false; Game_Map::SetNeedRefresh(true); break; case RPG::MoveCommand::Code::change_graphic: // String: File, Parameter A: index SetGraphic(move_command.parameter_string, move_command.parameter_a); break; case RPG::MoveCommand::Code::play_sound_effect: // String: File, Parameters: Volume, Tempo, Balance if (move_command.parameter_string != "(OFF)") { Audio().SE_Play(move_command.parameter_string, move_command.parameter_a, move_command.parameter_b); } break; case RPG::MoveCommand::Code::walk_everywhere_on: through = true; break; case RPG::MoveCommand::Code::walk_everywhere_off: through = false; break; case RPG::MoveCommand::Code::stop_animation: walk_animation = false; break; case RPG::MoveCommand::Code::start_animation: walk_animation = true; break; case RPG::MoveCommand::Code::increase_transp: SetOpacity(max(40, GetOpacity() - 45)); break; case RPG::MoveCommand::Code::decrease_transp: SetOpacity(GetOpacity() + 45); break; } if (active_route->skippable || !move_failed) { ++active_route_index; } } while (jumping); if ((size_t)active_route_index >= active_route->move_commands.size()) { stop_count = (active_route->repeat ? 0 : 256); } } } // When the overwrite status changed the active_index belongs to the // current non-active move route if (overwrite_changed != IsMoveRouteOverwritten()) { if (IsMoveRouteOverwritten()) { SetOriginalMoveRouteIndex(active_route_index); } else { SetMoveRouteIndex(active_route_index); } } else { if (IsMoveRouteOverwritten()) { SetMoveRouteIndex(active_route_index); } else { SetOriginalMoveRouteIndex(active_route_index); } } }