修改渲染底层,新增场景摄像机逻辑,地图可行区域逻辑
This commit is contained in:
@@ -291,6 +291,24 @@ void GameMap::InitMapAnimation()
|
||||
}
|
||||
}
|
||||
|
||||
void GameMap::InitVirtualMovableArea()
|
||||
{
|
||||
std::vector<int> Info = std::get<std::vector<int>>(_MapInfo["virtual_movable_area"]);
|
||||
if (Info.size() > 0)
|
||||
{
|
||||
for (int i = 0; i < Info.size(); i += 4)
|
||||
{
|
||||
float x = Info[i];
|
||||
float y = Info[i + 1];
|
||||
float w = Info[i + 2];
|
||||
float h = Info[i + 3];
|
||||
if (_DebugMode)
|
||||
_LayerMap["max"]->AddDebugFeasibleAreaInfo(VecFPos(x, y), VecSize(w, h));
|
||||
_MovableArea.push_back(SDL_FRect{x, y, w, h});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GameMap::LoadMap(std::string mapName)
|
||||
{
|
||||
// 读取脚本配置
|
||||
@@ -301,11 +319,8 @@ void GameMap::LoadMap(std::string mapName)
|
||||
InitBackgroundAnimation();
|
||||
// 初始化场景Ani
|
||||
InitMapAnimation();
|
||||
|
||||
RefPtr<CharacterObject> obj = new CharacterObject();
|
||||
obj->SetPosition({620, 200, 0});
|
||||
obj->Construction(0);
|
||||
_LayerMap["normal"]->AddObject(obj);
|
||||
// 初始化可行区域
|
||||
InitVirtualMovableArea();
|
||||
}
|
||||
|
||||
void GameMap::Enter(Scene *scene)
|
||||
@@ -321,7 +336,7 @@ void GameMap::Enter(Scene *scene)
|
||||
scene->AddChild(_LayerMap["max"]);
|
||||
|
||||
// TODO
|
||||
int HSU = 230;
|
||||
int HSU = 0;
|
||||
_LayerMap["contact"]->SetPos(VecFPos{0, HSU});
|
||||
_LayerMap["distantback"]->SetPos(VecFPos{0, HSU});
|
||||
_LayerMap["middleback"]->SetPos(VecFPos{0, HSU});
|
||||
@@ -367,3 +382,67 @@ void GameMap::Update(float deltaTime)
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
void GameMap::AddObject(RefPtr<BaseObject> object)
|
||||
{
|
||||
object->_AffMap = this;
|
||||
_LayerMap["normal"]->AddObject(object);
|
||||
}
|
||||
|
||||
VecFPos3 GameMap::CheckIsItMovable(VecFPos3 CurPos, VecFPos3 PosOffset)
|
||||
{
|
||||
// 初始化结果为原坐标(默认不移动)
|
||||
VecFPos3 result = CurPos;
|
||||
|
||||
// 如果没有可移动区域限制,直接全量位移
|
||||
if (_MovableArea.empty())
|
||||
{
|
||||
result.x += PosOffset.x;
|
||||
result.y += PosOffset.y;
|
||||
result.z += PosOffset.z; // Z轴不受限
|
||||
return result;
|
||||
}
|
||||
|
||||
// 计算X轴单独位移后的目标位置
|
||||
float targetX = CurPos.x + PosOffset.x;
|
||||
// 计算Y轴单独位移后的目标位置
|
||||
float targetY = CurPos.y + PosOffset.y;
|
||||
|
||||
// 检查X轴位移是否合法(固定Y为当前值,仅移动X)
|
||||
SDL_FPoint xTestPoint{targetX, CurPos.y};
|
||||
bool isXValid = false;
|
||||
for (auto &area : _MovableArea)
|
||||
{
|
||||
if (SDL_PointInFRect(&xTestPoint, &area))
|
||||
{
|
||||
isXValid = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 检查Y轴位移是否合法(固定X为当前值,仅移动Y)
|
||||
SDL_FPoint yTestPoint{CurPos.x, targetY};
|
||||
bool isYValid = false;
|
||||
for (auto &area : _MovableArea)
|
||||
{
|
||||
if (SDL_PointInFRect(&yTestPoint, &area))
|
||||
{
|
||||
isYValid = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 应用合法的位移
|
||||
if (isXValid)
|
||||
{
|
||||
result.x = targetX; // X轴允许移动
|
||||
}
|
||||
if (isYValid)
|
||||
{
|
||||
result.y = targetY; // Y轴允许移动
|
||||
}
|
||||
// Z轴不受限制,直接应用位移
|
||||
result.z += PosOffset.z;
|
||||
|
||||
return result;
|
||||
}
|
||||
Reference in New Issue
Block a user