修改游戏底层矩阵相关

This commit is contained in:
2025-10-26 14:38:53 +08:00
parent dc0213dc16
commit 88f039348a
50 changed files with 1983 additions and 362 deletions

View File

@@ -221,7 +221,7 @@ void GameMap::InitTile()
{
std::string path = tileArr[i];
RefPtr<Tile> tile = new Tile(path);
tile->SetPos(VecFPos{i * 224, -200 - std::get<int>(_MapInfo["background_pos"])});
tile->SetPos(Vec2{i * 224, -200 - std::get<int>(_MapInfo["background_pos"])});
_LayerMap["bottom"]->AddComponent(tile);
}
_MapHeight = 560;
@@ -240,7 +240,7 @@ void GameMap::InitTile()
RefPtr<Tile> tile = new Tile(path);
int xbuf = i % NormalTileCount * 224;
int ybuf = -200 - std::get<int>(_MapInfo["background_pos"]) + NormalTileHeight + 120 * (i / NormalTileCount);
tile->SetPos(VecFPos{xbuf, ybuf});
tile->SetPos(Vec2{xbuf, ybuf});
_LayerMap["bottom"]->AddComponent(tile);
}
}
@@ -269,7 +269,7 @@ void GameMap::InitBackgroundAnimation()
}
for (int i = 0; i < (int)AniList.size(); i++)
{
AniList[i]->SetPos(VecFPos{i * width, -120});
AniList[i]->SetPos(Vec2{i * width, -120});
AniList[i]->SetRenderZOrder(-1000000);
std::string layer = ani.layer;
layer = layer.substr(1, layer.length() - 2);
@@ -294,7 +294,7 @@ void GameMap::InitMapAnimation()
{
std::string path = ani.filename;
RefPtr<Animation> AniObj = new Animation(path);
AniObj->SetPos(VecFPos{ani.XPos, ani.YPos - ani.ZPos});
AniObj->SetPos(Vec2{ani.XPos, ani.YPos - ani.ZPos});
AniObj->SetRenderZOrder(ani.YPos);
std::string layer = ani.layer;
layer = layer.substr(1, layer.length() - 2);
@@ -318,7 +318,7 @@ void GameMap::InitVirtualMovableArea()
float w = Info[i + 2];
float h = Info[i + 3];
if (_DebugMode)
_LayerMap["max"]->AddDebugFeasibleAreaInfo(VecFPos(x, y), VecSize(w, h));
_LayerMap["max"]->AddDebugFeasibleAreaInfo(Vec2(x, y), VecSize(w, h));
_MovableArea.push_back(SDL_FRect{x, y, w, h});
}
}
@@ -364,8 +364,8 @@ void GameMap::Update(float deltaTime)
int targetX = Cam->_currentPosition.x;
int targetY = Cam->_currentPosition.y;
// 屏幕中心
int width_Separate = Game::GetInstance().Screen_W / 2;
int height_Separate = Game::GetInstance().Screen_H / 2;
int width_Separate = 1067 / 2;
int height_Separate = 600 / 2;
// 获取摄像机可行区域限制
auto limitIt = _MapInfo.find("limit_map_camera_move");
@@ -400,7 +400,7 @@ void GameMap::Update(float deltaTime)
posX *= BackgroundMoveSpeed;
posX /= 100;
}
Layer.second->SetPos(VecFPos(posX, posY));
Layer.second->SetPos(Vec2(posX, posY));
}
}

View File

@@ -28,7 +28,7 @@ void GameMapLayer::Render()
}
}
void GameMapLayer::AddDebugFeasibleAreaInfo(VecFPos pos, VecSize size)
void GameMapLayer::AddDebugFeasibleAreaInfo(Vec2 pos, VecSize size)
{
SDL_Rect info;
info.x = pos.x;

View File

@@ -17,7 +17,7 @@ public:
// 重载Render以实现绘制可行区域
void Render() override;
// 添加调试可行区域信息
void AddDebugFeasibleAreaInfo(VecFPos pos, VecSize size);
void AddDebugFeasibleAreaInfo(Vec2 pos, VecSize size);
public:
void AddObject(RefPtr<Actor> obj); // 添加对象

View File

@@ -21,7 +21,7 @@ Tile::~Tile()
{
}
void Tile::SetPos(VecFPos pos)
void Tile::SetPos(Vec2 pos)
{
pos.y += std::get<int>(m_data["pos"]);
Sprite::SetPos(pos);

View File

@@ -16,7 +16,7 @@ public:
Tile(std::string Path);
~Tile();
void SetPos(VecFPos pos) override;
void SetPos(Vec2 pos) override;
void InitInfo(std::string Path);
};

View File

@@ -28,7 +28,7 @@ void BaseObject::SetPosition(VecPos3 pos)
SetRenderZOrder(pos.y); // 设置渲染顺序
}
this->Position = pos;
SetPos(VecFPos{this->Position.x, this->Position.y - this->Position.z});
SetPos(Vec2{this->Position.x, this->Position.y - this->Position.z});
}
VecPos3 BaseObject::GetPosition()
@@ -105,16 +105,16 @@ void BaseObject::MoveBy(int x, int y, int z)
void BaseObject::SetDirection(int dir)
{
this->Direction = dir;
VecFPos sc = GetScale();
Vec2 sc = GetScale();
// 朝右
if (dir == 0)
{
SetScale(VecFPos({SDL_fabsf(sc.x), sc.y}));
SetScale(Vec2({SDL_fabsf(sc.x), sc.y}));
}
// 朝左
else if (dir == 1)
{
SetScale(VecFPos({-SDL_fabsf(sc.x), sc.y}));
SetScale(Vec2({-SDL_fabsf(sc.x), sc.y}));
}
}

View File

@@ -44,7 +44,7 @@ void CharacterObject::ControllerMsg(CONTROLLER_MSG_TYPE msgType, void *msgData)
// 摇杆移动(左)
if (msgType == CONTROLLER_MSG_TYPE::CONTROLLER_MSG_TYPE_LEFT_JOYSTICK_MOVE)
{
VecFPos *pos = (VecFPos *)msgData;
Vec2 *pos = (Vec2 *)msgData;
std::vector<float> movedata = {pos->x, pos->y};
this->GetObjectVars().SetArray("_move_data_", movedata);
this->_StateMachine->ChangeState(BASE_STATE::MOVE);
@@ -56,7 +56,7 @@ void CharacterObject::Update(float deltaTime)
ActiveObject::Update(deltaTime);
}
void CharacterObject::SetPos(VecFPos pos)
void CharacterObject::SetPos(Vec2 pos)
{
BaseObject::SetPos(pos);
if(_Shadow)_Shadow->SetPos(this->GetPos());

View File

@@ -40,6 +40,6 @@ public:
void ControllerMsg(CONTROLLER_MSG_TYPE msgType, void* msgData);
void Update(float deltaTime) override;
void SetPos(VecFPos pos) override;
void SetPos(Vec2 pos) override;
void SetDirection(int dir) override;
};