加入 Node节点类 还未测试新框架

This commit is contained in:
2025-10-27 23:12:56 +08:00
parent 80d088316b
commit 0ae47e5d6a
52 changed files with 1642 additions and 458 deletions

View File

@@ -1,10 +1,10 @@
#include "GameMap.h"
#include "Asset/AssetManager.h"
#include "EngineCore/Game.h"
#include "EngineFrame/Scene/Scene.h"
#include "EngineFrame/Component/Animation.h"
#include "Actor/Map/GameMapCamera.h"
#include "Global/Global_Game.h"
#include "Actor/Object/CharacterObject.h"
#include "EngineCore/Game.h"
GameMap::GameMap()
{
@@ -217,34 +217,21 @@ void GameMap::InitTile()
{
NormalTileCount = tileArr.size();
_MapLength = NormalTileCount * 224;
for (int i = 0; i < NormalTileCount; i++)
{
std::string path = tileArr[i];
RefPtr<Tile> tile = new Tile(path);
tile->SetPos(Vec2{i * 224, -200 - std::get<int>(_MapInfo["background_pos"])});
_LayerMap["bottom"]->AddComponent(tile);
}
_MapHeight = 560;
}
if (_MapInfo.count("extended_tile"))
if (!_MapInfo.count("extended_tile"))
return;
std::vector<std::string> extileArr = std::get<std::vector<std::string>>(_MapInfo["extended_tile"]);
if (extileArr.size() > 0)
{
std::vector<std::string> extileArr = std::get<std::vector<std::string>>(_MapInfo["extended_tile"]);
if (extileArr.size() > 0)
{
int ExTileCount = extileArr.size();
int Buffer = (ExTileCount / NormalTileCount);
_MapHeight += (Buffer < 1 ? 1 : Buffer) * 40;
for (int i = 0; i < ExTileCount; i++)
{
std::string path = extileArr[i];
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(Vec2{xbuf, ybuf});
_LayerMap["bottom"]->AddComponent(tile);
}
}
int ExTileCount = extileArr.size();
int Buffer = (ExTileCount / NormalTileCount);
_MapHeight += (Buffer < 1 ? 1 : Buffer) * 40;
}
_Tile = new Tile(this, tileArr, extileArr);
_LayerMap["bottom"]->AddChild(_Tile);
}
void GameMap::InitBackgroundAnimation()
@@ -340,45 +327,42 @@ void GameMap::LoadMap(std::string mapName)
void GameMap::Enter(Scene *scene)
{
_Scene = scene;
scene->AddChild(_LayerMap["contact"]);
scene->AddChild(_LayerMap["distantback"]);
scene->AddChild(_LayerMap["middleback"]);
scene->AddChild(_LayerMap["bottom"]);
scene->AddChild(_LayerMap["closeback"]);
scene->AddChild(_LayerMap["normal"]);
scene->AddChild(_LayerMap["close"]);
scene->AddChild(_LayerMap["cover"]);
scene->AddChild(_LayerMap["max"]);
}
void GameMap::HandleEvents(SDL_Event *e)
{
AddChild(_LayerMap["contact"]);
AddChild(_LayerMap["distantback"]);
AddChild(_LayerMap["middleback"]);
AddChild(_LayerMap["bottom"]);
AddChild(_LayerMap["closeback"]);
AddChild(_LayerMap["normal"]);
AddChild(_LayerMap["close"]);
AddChild(_LayerMap["cover"]);
AddChild(_LayerMap["max"]);
}
void GameMap::Update(float deltaTime)
{
if (_Scene->GetCamera() == nullptr)
Actor::Update(deltaTime);
RefPtr<GameCamera> Cam = Global_Game::GetInstance().GetCamera();
if (Cam == nullptr)
return;
GameMapCamera *Cam = (GameMapCamera *)(_Scene->GetCamera().Get());
int targetX = Cam->_currentPosition.x;
int targetY = Cam->_currentPosition.y;
float targetX = Cam->_currentPosition.x;
float targetY = Cam->_currentPosition.y;
// 屏幕中心
int width_Separate = 1067 / 2;
int height_Separate = 600 / 2;
float width_Separate = 1280.0f / 1.2f / 2.0f;
float height_Separate = 600.0f / 2.0f;
// 获取摄像机可行区域限制
auto limitIt = _MapInfo.find("limit_map_camera_move");
if (limitIt != _MapInfo.end())
{
std::vector<int> limit = std::get<std::vector<int>>(_MapInfo["limit_map_camera_move"]);
int X_Limit_Min = limit[0];
int X_Limit_Max = limit[1];
int Y_Limit_Min = limit[2];
int Y_Limit_Max = limit[3];
float X_Limit_Min = limit[0];
float X_Limit_Max = limit[1];
float Y_Limit_Min = limit[2];
float Y_Limit_Max = limit[3];
// 应用地图边界限制
targetX = std::clamp(targetX, width_Separate, _MapLength - width_Separate);
targetY = std::clamp(targetY, height_Separate, _MapHeight - height_Separate);
targetX = std::clamp(targetX, width_Separate, (float)_MapLength - width_Separate);
targetY = std::clamp(targetY, height_Separate, (float)_MapHeight - height_Separate);
// 应用自定义摄像机移动限制
if (X_Limit_Min != -1)
targetX = std::max(targetX, X_Limit_Min);
@@ -393,12 +377,12 @@ void GameMap::Update(float deltaTime)
// 更新图层位置
for (auto &Layer : _LayerMap)
{
int posX = -targetX + width_Separate;
int posY = -targetY + height_Separate + MapOffsetY;
float posX = -targetX + width_Separate;
float posY = -targetY + height_Separate + MapOffsetY;
if (Layer.first == "distantback")
{
posX *= BackgroundMoveSpeed;
posX /= 100;
posX /= 100.0f;
}
Layer.second->SetPos(Vec2(posX, posY));
}
@@ -412,14 +396,17 @@ void GameMap::AddObject(RefPtr<BaseObject> object)
if (object->m_objecttype == ObjectType::CHARACTER)
{
CharacterObject *chr = (CharacterObject *)(object.Get());
if( chr->_Shadow != nullptr)_LayerMap["bottom"]->AddComponent(chr->_Shadow);
Global_Game::GetInstance().GetCamera()->SetFromActor(chr);
if (chr->_Shadow)
_LayerMap["bottom"]->AddChild(chr->_Shadow);
}
}
VecPos3 GameMap::CheckIsItMovable(VecPos3 CurPos, VecPos3 PosOffset)
VecFPos3 GameMap::CheckIsItMovable(VecFPos3 CurPos, VecFPos3 PosOffset)
{
// 初始化结果为原坐标(默认不移动)
VecPos3 result = CurPos;
VecFPos3 result = CurPos;
// 如果没有可移动区域限制,直接全量位移
if (_MovableArea.empty())