feat(地图系统): 实现角色移动约束和地图切换功能
添加地图移动区域检测和角色移动约束逻辑 引入地图切换请求队列机制,支持延迟处理角色传送 在CharacterObject中实现地图边界检测和位置约束应用
This commit is contained in:
@@ -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());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user