feat(地图系统): 实现角色移动约束和地图切换功能
添加地图移动区域检测和角色移动约束逻辑 引入地图切换请求队列机制,支持延迟处理角色传送 在CharacterObject中实现地图边界检测和位置约束应用
This commit is contained in:
@@ -15,6 +15,8 @@
|
||||
|
||||
namespace frostbite2D {
|
||||
|
||||
class GameMap;
|
||||
|
||||
/// @brief 角色系统的主聚合对象。
|
||||
///
|
||||
/// 这个类可以理解为“角色外壳”:
|
||||
@@ -170,6 +172,9 @@ private:
|
||||
void CommitPendingActionContext(const std::string& defaultRequestedActionId,
|
||||
const std::string& defaultSourceActionId,
|
||||
CharacterStateId defaultSourceStateId);
|
||||
GameMap* FindOwningMap() const;
|
||||
void ApplyMapMovementConstraints(const CharacterWorldPosition& previousPosition);
|
||||
void QueueMapTransitionIfNeeded();
|
||||
void SyncActorPositionFromWorld();
|
||||
bool SetActionStrict(const std::string& actionName,
|
||||
const char* phase,
|
||||
|
||||
@@ -44,6 +44,7 @@ public:
|
||||
Vec3 CheckIsItMovable(const Vec3& curPos, const Vec3& posOffset) const;
|
||||
/// 检查当前位置是否进入 town move area,用于切图/传送判定。
|
||||
MapMoveArea CheckIsItMoveArea(const Vec3& curPos) const;
|
||||
bool TryGetMoveAreaTarget(const Vec3& curPos, MapMoveArea& outTarget) const;
|
||||
const std::vector<MapMoveArea>& GetMoveAreaInfo() const;
|
||||
Rect GetMovablePositionArea(size_t index) const;
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "world/GameTown.h"
|
||||
#include <frostbite2D/scene/scene.h>
|
||||
#include <map>
|
||||
#include <optional>
|
||||
|
||||
namespace frostbite2D {
|
||||
|
||||
@@ -13,18 +14,28 @@ public:
|
||||
|
||||
void onEnter() override;
|
||||
void onExit() override;
|
||||
void Update(float deltaTime) override;
|
||||
|
||||
void AddCharacter(RefPtr<Actor> actor, int townId);
|
||||
void MoveCharacter(RefPtr<Actor> actor, int townId, int area);
|
||||
void RequestMoveCharacter(RefPtr<Actor> actor, int townId, int area);
|
||||
|
||||
static GameWorld* GetWorld();
|
||||
|
||||
private:
|
||||
struct PendingCharacterMove {
|
||||
RefPtr<Actor> actor;
|
||||
int townId = -1;
|
||||
int area = -1;
|
||||
};
|
||||
|
||||
bool InitWorld();
|
||||
void ProcessPendingCharacterMove();
|
||||
|
||||
std::map<int, std::string> townPathMap_;
|
||||
std::map<int, RefPtr<GameTown>> townMap_;
|
||||
RefPtr<Actor> mainActor_;
|
||||
std::optional<PendingCharacterMove> pendingCharacterMove_;
|
||||
int curTown_ = -1;
|
||||
bool initialized_ = false;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user