加入 Node节点类 还未测试新框架
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
#include "ActiveObject.h"
|
||||
void ActiveObject::SetPosition(VecPos3 pos)
|
||||
void ActiveObject::SetPosition(VecFPos3 pos)
|
||||
{
|
||||
BaseObject::SetPosition(pos);
|
||||
}
|
||||
@@ -21,49 +21,36 @@ VecSpeed3 ActiveObject::GetSpeed()
|
||||
|
||||
void ActiveObject::Update(float deltaTime)
|
||||
{
|
||||
int IntegerDelta = static_cast<int>(deltaTime * 1000);
|
||||
const int Gravity = 1020;
|
||||
|
||||
VecFPos3 MovePos;
|
||||
// X轴移动(含余数补偿)
|
||||
if (Speed.x != 0)
|
||||
{
|
||||
int totalX = Speed.x * IntegerDelta + Remainder.x; // 加上上次余数
|
||||
int moveX = totalX / 1000; // 整数部分为实际移动
|
||||
Remainder.x = totalX % 1000; // 保留余数(-999~999)
|
||||
MoveBy(moveX, 0, 0);
|
||||
MovePos.x = Speed.x * deltaTime;
|
||||
}
|
||||
|
||||
// Y轴移动(同上)
|
||||
if (Speed.y != 0)
|
||||
{
|
||||
int totalY = Speed.y * IntegerDelta + Remainder.y;
|
||||
int moveY = totalY / 1000;
|
||||
Remainder.y = totalY % 1000;
|
||||
MoveBy(0, moveY, 0);
|
||||
MovePos.y = Speed.y * deltaTime;
|
||||
}
|
||||
|
||||
// Z轴重力与移动(含余数补偿)
|
||||
if (Position.z > 0 || Speed.z > 0)
|
||||
{
|
||||
// 重力对速度的影响(先更新Speed.z,含余数)
|
||||
int speedZTotal = -Gravity * IntegerDelta + Remainder.z; // 注意负号(减速)
|
||||
Speed.z += speedZTotal / 1000; // 速度的整数部分
|
||||
Remainder.z = speedZTotal % 1000; // 速度的余数
|
||||
int speedZTotal = -1020 * deltaTime;
|
||||
|
||||
// 基于更新后的Speed.z计算移动量(同样含余数)
|
||||
int moveZTotal = Speed.z * IntegerDelta + _zRemainderMove; // 新增_zRemainderMove记录移动余数
|
||||
int moveZ = moveZTotal / 1000;
|
||||
_zRemainderMove = moveZTotal % 1000;
|
||||
MoveBy(0, 0, moveZ);
|
||||
MovePos.z = Speed.z * deltaTime;
|
||||
}
|
||||
else if (Position.z < 0)
|
||||
{
|
||||
Position.z = 0;
|
||||
Speed.z = 0;
|
||||
Remainder.z = 0; // 重置余数
|
||||
_zRemainderMove = 0;
|
||||
SetPosition(Position);
|
||||
}
|
||||
|
||||
MoveBy(MovePos);
|
||||
|
||||
BaseObject::Update(deltaTime);
|
||||
}
|
||||
|
||||
@@ -7,13 +7,12 @@ class ActiveObject : public BaseObject
|
||||
public:
|
||||
// 三轴速度
|
||||
VecSpeed3 Speed;
|
||||
// 三轴移动余数
|
||||
VecPos3 Remainder;
|
||||
|
||||
int _zRemainderMove = 0;
|
||||
|
||||
public:
|
||||
void
|
||||
SetPosition(VecPos3 pos) override;
|
||||
SetPosition(VecFPos3 pos) override;
|
||||
void SetYpos(int y) override;
|
||||
|
||||
void SetSpeed(VecSpeed3 speed);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#include "BaseObject.h"
|
||||
#include "Actor/Map/GameMap.h"
|
||||
#include "Actor/Map/GameMapCamera.h"
|
||||
|
||||
BaseObject::BaseObject()
|
||||
{
|
||||
@@ -14,15 +13,13 @@ BaseObject::~BaseObject()
|
||||
|
||||
void BaseObject::Update(float deltaTime)
|
||||
{
|
||||
if (_AffCamera != nullptr)
|
||||
{
|
||||
_AffCamera->SyncPos(deltaTime);
|
||||
}
|
||||
Actor::Update(deltaTime);
|
||||
}
|
||||
|
||||
void BaseObject::SetPosition(VecPos3 pos)
|
||||
void BaseObject::SetPosition(VecFPos3 pos)
|
||||
{
|
||||
if(pos == this->Position)
|
||||
return;
|
||||
if (pos.y != this->Position.y)
|
||||
{
|
||||
SetRenderZOrder(pos.y); // 设置渲染顺序
|
||||
@@ -31,19 +28,23 @@ void BaseObject::SetPosition(VecPos3 pos)
|
||||
SetPos(Vec2{this->Position.x, this->Position.y - this->Position.z});
|
||||
}
|
||||
|
||||
VecPos3 BaseObject::GetPosition()
|
||||
VecFPos3 BaseObject::GetPosition()
|
||||
{
|
||||
return this->Position;
|
||||
}
|
||||
|
||||
void BaseObject::SetXpos(int x)
|
||||
{
|
||||
if (x == this->Position.x)
|
||||
return;
|
||||
this->Position.x = x;
|
||||
SetPos({this->Position.x, this->Position.y - this->Position.z});
|
||||
}
|
||||
|
||||
void BaseObject::SetYpos(int y)
|
||||
{
|
||||
if (y == this->Position.y)
|
||||
return;
|
||||
if (y != this->Position.y)
|
||||
{
|
||||
SetRenderZOrder(y); // 设置渲染顺序
|
||||
@@ -54,6 +55,8 @@ void BaseObject::SetYpos(int y)
|
||||
|
||||
void BaseObject::SetZpos(int z)
|
||||
{
|
||||
if (z == this->Position.z)
|
||||
return;
|
||||
this->Position.z = z;
|
||||
SetPos({this->Position.x, this->Position.y - this->Position.z});
|
||||
}
|
||||
@@ -73,10 +76,12 @@ int BaseObject::GetZpos()
|
||||
return this->Position.z;
|
||||
}
|
||||
|
||||
void BaseObject::MoveBy(VecPos3 pos)
|
||||
void BaseObject::MoveBy(VecFPos3 pos)
|
||||
{
|
||||
// 只有moveby移动时判断所在地图中是否能够这样移动
|
||||
VecPos3 RealPos = this->_AffMap->CheckIsItMovable(GetPosition(), pos);
|
||||
VecFPos3 RealPos = this->_AffMap->CheckIsItMovable(GetPosition(), pos);
|
||||
if (RealPos == this->Position)
|
||||
return;
|
||||
if (RealPos.y != this->Position.y)
|
||||
{
|
||||
SetRenderZOrder(RealPos.y); // 设置渲染顺序
|
||||
@@ -90,7 +95,9 @@ void BaseObject::MoveBy(VecPos3 pos)
|
||||
void BaseObject::MoveBy(int x, int y, int z)
|
||||
{
|
||||
// 只有moveby移动时判断所在地图中是否能够这样移动
|
||||
VecPos3 RealPos = this->_AffMap->CheckIsItMovable(GetPosition(), VecPos3({x, y, z}));
|
||||
VecFPos3 RealPos = this->_AffMap->CheckIsItMovable(GetPosition(), VecFPos3({x, y, z}));
|
||||
if (RealPos == this->Position)
|
||||
return;
|
||||
if (RealPos.y != this->Position.y)
|
||||
{
|
||||
SetRenderZOrder(RealPos.y); // 设置渲染顺序
|
||||
|
||||
@@ -1,18 +1,16 @@
|
||||
#pragma once
|
||||
#include "EngineFrame/Actor/Actor.h"
|
||||
#include "EngineFrame/Base/Actor.h"
|
||||
#include "Asset/Common/ObjectVars.h"
|
||||
#include "Global/Global_Enum.h"
|
||||
class GameMap;
|
||||
class GameMapCamera;
|
||||
class BaseObject : public Actor
|
||||
{
|
||||
public:
|
||||
public:
|
||||
ObjectType m_objecttype; // 对象类型
|
||||
VecPos3 Position; // 位置
|
||||
VecFPos3 Position; // 位置
|
||||
int Direction = 0; // 方向
|
||||
GameMap *_AffMap = nullptr; // 所在地图
|
||||
GameMapCamera *_AffCamera = nullptr; // 跟随相机
|
||||
|
||||
public:
|
||||
BaseObject(/* args */);
|
||||
@@ -24,17 +22,17 @@ public:
|
||||
ObjectVars _ObjectVars;
|
||||
|
||||
public:
|
||||
virtual void SetPosition(VecPos3 pos);
|
||||
virtual void SetPosition(VecFPos3 pos);
|
||||
virtual void SetXpos(int x);
|
||||
virtual void SetYpos(int y);
|
||||
virtual void SetZpos(int z);
|
||||
|
||||
VecPos3 GetPosition();
|
||||
VecFPos3 GetPosition();
|
||||
int GetXpos();
|
||||
int GetYpos();
|
||||
int GetZpos();
|
||||
|
||||
virtual void MoveBy(VecPos3 pos);
|
||||
virtual void MoveBy(VecFPos3 pos);
|
||||
virtual void MoveBy(int x, int y, int z);
|
||||
|
||||
virtual void SetDirection(int dir);
|
||||
|
||||
Reference in New Issue
Block a user