feat(地图系统): 实现角色移动约束和地图切换功能

添加地图移动区域检测和角色移动约束逻辑
引入地图切换请求队列机制,支持延迟处理角色传送
在CharacterObject中实现地图边界检测和位置约束应用
This commit is contained in:
2026-04-05 12:04:07 +08:00
parent 2b0cfc6ce5
commit 6cd1b42fef
6 changed files with 117 additions and 4 deletions

View File

@@ -20,6 +20,11 @@ void GameWorld::onExit() {
Scene::onExit();
}
void GameWorld::Update(float deltaTime) {
Scene::Update(deltaTime);
ProcessPendingCharacterMove();
}
bool GameWorld::InitWorld() {
townPathMap_ = game::loadTownList();
if (townPathMap_.empty()) {
@@ -77,6 +82,26 @@ void GameWorld::MoveCharacter(RefPtr<Actor> actor, int townId, int area) {
AddChild(townIt->second);
}
void GameWorld::RequestMoveCharacter(RefPtr<Actor> actor, int townId, int area) {
if (!actor) {
SDL_LogWarn(SDL_LOG_CATEGORY_APPLICATION,
"GameWorld: ignore move request without actor");
return;
}
pendingCharacterMove_ = PendingCharacterMove{actor, townId, area};
}
void GameWorld::ProcessPendingCharacterMove() {
if (!pendingCharacterMove_) {
return;
}
PendingCharacterMove move = *pendingCharacterMove_;
pendingCharacterMove_.reset();
MoveCharacter(move.actor, move.townId, move.area);
}
GameWorld* GameWorld::GetWorld() {
return dynamic_cast<GameWorld*>(SceneManager::get().GetCurrentScene());
}