51 lines
1.2 KiB
C++
51 lines
1.2 KiB
C++
#include "ActiveObject.h"
|
|
|
|
void ActiveObject::SetPosition(VecFPos3 pos)
|
|
{
|
|
BaseObject::SetPosition(pos);
|
|
BaseObject::SetRenderZOrder(this->Position.y);
|
|
}
|
|
|
|
void ActiveObject::SetYpos(float y)
|
|
{
|
|
BaseObject::SetYpos(y);
|
|
BaseObject::SetRenderZOrder(this->Position.y);
|
|
}
|
|
|
|
void ActiveObject::SetSpeed(VecSpeed3 speed)
|
|
{
|
|
this->Speed = speed;
|
|
}
|
|
|
|
VecSpeed3 ActiveObject::GetSpeed()
|
|
{
|
|
return this->Speed;
|
|
}
|
|
|
|
void ActiveObject::Update(float deltaTime)
|
|
{
|
|
// X Y 轴方向的加速度计算
|
|
if (Speed.x != 0 || Speed.y != 0)
|
|
{
|
|
MoveBy(Speed.x * deltaTime, Speed.y * deltaTime, 0);
|
|
}
|
|
// Z轴只在Z轴大于0时 或者 Z轴速度向上时才会有重力
|
|
if (Position.z > 0 || Speed.z > 0)
|
|
{
|
|
// TODO 还没有写角色属性 要读了角色属性以后才是正确的
|
|
float Gravity = 68000.0 / 1000.0 * 15.0;
|
|
Speed.z -= Gravity * deltaTime;
|
|
MoveBy(0, 0, Speed.z * deltaTime);
|
|
}
|
|
// Z轴小于0时要修正
|
|
else if (Position.z < 0)
|
|
{
|
|
Position.z = 0;
|
|
Speed.z = 0;
|
|
SetPosition(Position);
|
|
SDL_LogError(0, "修正Z轴");
|
|
}
|
|
// 执行父类的更新
|
|
BaseObject::Update(deltaTime);
|
|
}
|