feat(地图系统): 增强移动区域调试功能
- 添加移动区域边界结构体MoveAreaBounds并集成到地图配置中 - 实现移动区域索引查找和高亮显示功能 - 增加可移动区域检查开关movableAreaCheckEnabled - 优化调试信息显示,包括坐标和当前所在移动区域 - 重构移动区域相关代码,提高可维护性
This commit is contained in:
@@ -41,6 +41,11 @@ struct MoveAreaTarget {
|
||||
int area = -2;
|
||||
};
|
||||
|
||||
struct MoveAreaBounds {
|
||||
Vec2 leftTop = Vec2::Zero();
|
||||
Vec2 rightBottom = Vec2::Zero();
|
||||
};
|
||||
|
||||
struct TileInfo {
|
||||
std::string spritePath;
|
||||
int spriteIndex = 0;
|
||||
@@ -65,6 +70,7 @@ struct MapConfig {
|
||||
std::vector<std::string> soundIds;
|
||||
std::vector<Vec2> virtualMovablePolygon;
|
||||
std::vector<Rect> townMovableAreas;
|
||||
std::vector<MoveAreaBounds> townMovableAreaBounds;
|
||||
std::vector<MoveAreaTarget> townMovableAreaTargets;
|
||||
};
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ namespace frostbite2D {
|
||||
*/
|
||||
class GameMap : public Actor {
|
||||
public:
|
||||
static constexpr size_t kInvalidMoveAreaIndex = static_cast<size_t>(-1);
|
||||
using MapMoveArea = game::MoveAreaTarget;
|
||||
|
||||
GameMap();
|
||||
@@ -45,11 +46,16 @@ public:
|
||||
/// 检查当前位置是否进入 town move area,用于切图/传送判定。
|
||||
MapMoveArea CheckIsItMoveArea(const Vec3& curPos) const;
|
||||
bool TryGetMoveAreaTarget(const Vec3& curPos, MapMoveArea& outTarget) const;
|
||||
size_t FindMoveAreaIndex(const Vec3& curPos) const;
|
||||
const std::vector<MapMoveArea>& GetMoveAreaInfo() const;
|
||||
size_t GetMoveAreaCount() const { return moveArea_.size(); }
|
||||
Rect GetMovablePositionArea(size_t index) const;
|
||||
const std::string& GetMapPath() const { return mapConfig_.mapPath; }
|
||||
void SetDebugHighlightedMoveAreaIndex(size_t index);
|
||||
|
||||
int GetBackgroundRepeatWidth() const { return backgroundRepeatWidth_; }
|
||||
bool IsDebugModeEnabled() const { return debugMode_; }
|
||||
bool IsMovableAreaCheckEnabled() const { return movableAreaCheckEnabled_; }
|
||||
|
||||
private:
|
||||
/// 初始化固定图层。图层名字与 DNF 地图层概念保持一致。
|
||||
@@ -84,6 +90,8 @@ private:
|
||||
/// 地图配置里的整体 Y 偏移;既影响层位置,也影响地板校准。
|
||||
int mapOffsetY_ = 0;
|
||||
bool debugMode_ = true;
|
||||
/// 硬编码调试开关:关闭后忽略可行走区域检测,允许角色自由移动。
|
||||
bool movableAreaCheckEnabled_ = false;
|
||||
/// 当前地图正在播放的背景音乐。
|
||||
Ptr<Music> currentMusic_;
|
||||
};
|
||||
|
||||
@@ -7,17 +7,26 @@ namespace frostbite2D {
|
||||
|
||||
class GameMapLayer : public Actor {
|
||||
public:
|
||||
static constexpr size_t kInvalidMoveAreaIndex = static_cast<size_t>(-1);
|
||||
|
||||
void Render() override;
|
||||
|
||||
void SetDebugFeasibleAreaPolygon(const std::vector<Vec2>& polygon);
|
||||
void AddDebugMoveAreaInfo(const Rect& rect);
|
||||
void AddDebugMoveAreaInfo(const Rect& rect, size_t index);
|
||||
void SetDebugHighlightedMoveAreaIndex(size_t index);
|
||||
void ClearDebugAreaInfo();
|
||||
void AddObject(RefPtr<Actor> obj);
|
||||
|
||||
private:
|
||||
struct DebugMoveAreaInfo {
|
||||
Rect rect;
|
||||
size_t index = kInvalidMoveAreaIndex;
|
||||
};
|
||||
|
||||
std::vector<Vec2> feasibleAreaPolygon_;
|
||||
std::vector<Rect> feasibleAreaFillRects_;
|
||||
std::vector<Rect> moveAreaInfoList_;
|
||||
std::vector<DebugMoveAreaInfo> moveAreaInfoList_;
|
||||
size_t highlightedMoveAreaIndex_ = kInvalidMoveAreaIndex;
|
||||
};
|
||||
|
||||
} // namespace frostbite2D
|
||||
|
||||
Reference in New Issue
Block a user