Files
DNF_DEV/source_game/Actor/Object/ActiveObject.cpp
2026-02-08 16:20:50 +08:00

55 lines
1007 B
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#include "ActiveObject.h"
void ActiveObject::SetPosition(VecFPos3 pos)
{
BaseObject::SetPosition(pos);
}
void ActiveObject::SetYpos(int y)
{
BaseObject::SetYpos(y);
}
void ActiveObject::SetSpeed(VecSpeed3 speed)
{
this->Speed = speed;
}
VecSpeed3 ActiveObject::GetSpeed()
{
return this->Speed;
}
void ActiveObject::OnUpdate(float deltaTime)
{
VecFPos3 MovePos;
// X轴移动含余数补偿
if (Speed.x != 0)
{
MovePos.x = Speed.x * deltaTime;
}
// Y轴移动同上
if (Speed.y != 0)
{
MovePos.y = Speed.y * deltaTime;
}
// Z轴重力与移动含余数补偿
if (Position.z > 0 || Speed.z > 0)
{
int speedZTotal = -1020 * deltaTime;
// 基于更新后的Speed.z计算移动量同样含余数
MovePos.z = Speed.z * deltaTime;
}
else if (Position.z < 0)
{
Position.z = 0;
Speed.z = 0;
SetPosition(Position);
}
MoveBy(MovePos);
}