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::Move(int dir) { int dx = (dir == Right || dir == UpRight || dir == DownRight) - (dir == Left || dir == DownLeft || dir == UpLeft); int dy = (dir == Down || dir == DownRight || dir == DownLeft) - (dir == Up || dir == UpRight || dir == UpLeft); SetDirection(dir); if (!(IsDirectionFixed() || IsFacingLocked())) { if (dir > 3) // Diagonal SetSpriteDirection(GetSpriteDirection() % 2 ? -dx + 2 : dy + 1); else SetSpriteDirection(dir); } if (jumping) { jump_plus_x += dx; jump_plus_y += dy; return; } move_failed = !IsPassable(GetX(), GetY(), dir); if (move_failed) { if (!CheckEventTriggerTouch(Game_Map::RoundX(GetX() + dx), Game_Map::RoundY(GetY() + dy))) return; } else { SetX(Game_Map::RoundX(GetX() + dx)); SetY(Game_Map::RoundY(GetY() + dy)); remaining_step = SCREEN_TILE_WIDTH; BeginMove(); } stop_count = 0; max_stop_count = (GetMoveFrequency() > 7) ? 0 : pow(2.0, 9 - GetMoveFrequency()); }
void Game_Event::StopTalkToHero() { if (!(IsDirectionFixed() || IsFacingLocked())) { SetSpriteDirection(GetDirection()); } halting = true; }
void Game_Event::StartTalkToHero() { if (!(IsDirectionFixed() || IsFacingLocked())) { int prelock_dir = GetDirection(); TurnTowardHero(); SetDirection(prelock_dir); } }
bool Game_Character::IsDirectionFixed() { return animation_type == RPG::EventPage::AnimType_fixed_continuous || animation_type == RPG::EventPage::AnimType_fixed_graphic || animation_type == RPG::EventPage::AnimType_fixed_non_continuous || IsFacingLocked(); }
void Game_Event::Setup(RPG::EventPage* new_page) { bool from_null = page == NULL; page = new_page; // Free resources if needed if (interpreter) { // If the new page is null and the interpreter is running, it should // carry on executing its command list during this frame if (page) interpreter->Clear(); Game_Map::ReserveInterpreterDeletion(interpreter); interpreter.reset(); } if (page == NULL) { tile_id = 0; SetSpriteName(""); SetSpriteIndex(0); SetDirection(RPG::EventPage::Direction_down); //move_type = 0; trigger = -1; list.clear(); return; } SetSpriteName(page->character_name); SetSpriteIndex(page->character_index); tile_id = page->character_name.empty() ? page->character_index : 0; if (original_pattern != page->character_pattern) { pattern = page->character_pattern; original_pattern = pattern; } move_type = page->move_type; SetMoveSpeed(page->move_speed); SetMoveFrequency(page->move_frequency); max_stop_count = (GetMoveFrequency() > 7) ? 0 : (int)pow(2.0, 8 - GetMoveFrequency()); original_move_frequency = page->move_frequency; original_move_route = page->move_route; SetOriginalMoveRouteIndex(0); bool last_direction_fixed = IsDirectionFixed() || IsFacingLocked(); animation_type = page->animation_type; if (from_null || !(last_direction_fixed || IsMoving()) || IsDirectionFixed()) SetSpriteDirection(page->character_direction); if (!IsMoving()) SetDirection(page->character_direction); SetOpacity(page->translucent ? 160 : 255); SetLayer(page->layer); data.overlap_forbidden = page->overlap_forbidden; trigger = page->trigger; list = page->event_commands; if (trigger == RPG::EventPage::Trigger_parallel) { interpreter.reset(new Game_Interpreter_Map()); } }
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); } }