137 lines
2.9 KiB
C++
137 lines
2.9 KiB
C++
#include "BaseObject.h"
|
|
#include "Actor/Map/GameMap.h"
|
|
|
|
BaseObject::BaseObject()
|
|
{
|
|
Init(); // 调用了RenderBase的Init函数 对象才会被执行回调
|
|
SetAnchor({0.5f, 0.5f});
|
|
}
|
|
|
|
BaseObject::~BaseObject()
|
|
{
|
|
}
|
|
|
|
void BaseObject::Update(float deltaTime)
|
|
{
|
|
Actor::Update(deltaTime);
|
|
}
|
|
|
|
void BaseObject::SetPosition(VecFPos3 pos)
|
|
{
|
|
if(pos == this->Position)
|
|
return;
|
|
if (pos.y != this->Position.y)
|
|
{
|
|
SetRenderZOrder(pos.y); // 设置渲染顺序
|
|
}
|
|
this->Position = pos;
|
|
SetPos(Vec2{this->Position.x, this->Position.y - this->Position.z});
|
|
}
|
|
|
|
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); // 设置渲染顺序
|
|
}
|
|
this->Position.y = y;
|
|
SetPos({this->Position.x, this->Position.y - this->Position.z});
|
|
}
|
|
|
|
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});
|
|
}
|
|
|
|
int BaseObject::GetXpos()
|
|
{
|
|
return this->Position.x;
|
|
}
|
|
|
|
int BaseObject::GetYpos()
|
|
{
|
|
return this->Position.y;
|
|
}
|
|
|
|
int BaseObject::GetZpos()
|
|
{
|
|
return this->Position.z;
|
|
}
|
|
|
|
void BaseObject::MoveBy(VecFPos3 pos)
|
|
{
|
|
// 只有moveby移动时判断所在地图中是否能够这样移动
|
|
VecFPos3 RealPos = this->_AffMap->CheckIsItMovable(GetPosition(), pos);
|
|
if (RealPos == this->Position)
|
|
return;
|
|
if (RealPos.y != this->Position.y)
|
|
{
|
|
SetRenderZOrder(RealPos.y); // 设置渲染顺序
|
|
}
|
|
if (RealPos != this->Position){
|
|
this->Position = RealPos;
|
|
SetPos({this->Position.x, this->Position.y - this->Position.z});
|
|
}
|
|
}
|
|
|
|
void BaseObject::MoveBy(int x, int y, int z)
|
|
{
|
|
// 只有moveby移动时判断所在地图中是否能够这样移动
|
|
VecFPos3 RealPos = this->_AffMap->CheckIsItMovable(GetPosition(), VecFPos3({x, y, z}));
|
|
if (RealPos == this->Position)
|
|
return;
|
|
if (RealPos.y != this->Position.y)
|
|
{
|
|
SetRenderZOrder(RealPos.y); // 设置渲染顺序
|
|
}
|
|
if (RealPos != this->Position)
|
|
{
|
|
this->Position = RealPos;
|
|
SetPos({this->Position.x, this->Position.y - this->Position.z});
|
|
}
|
|
}
|
|
|
|
void BaseObject::SetDirection(int dir)
|
|
{
|
|
this->Direction = dir;
|
|
Vec2 sc = GetScale();
|
|
// 朝右
|
|
if (dir == 0)
|
|
{
|
|
SetScale(Vec2({SDL_fabsf(sc.x), sc.y}));
|
|
}
|
|
// 朝左
|
|
else if (dir == 1)
|
|
{
|
|
SetScale(Vec2({-SDL_fabsf(sc.x), sc.y}));
|
|
}
|
|
}
|
|
|
|
int BaseObject::GetDirection()
|
|
{
|
|
return this->Direction;
|
|
}
|
|
|
|
ObjectVars &BaseObject::GetObjectVars()
|
|
{
|
|
return _ObjectVars;
|
|
}
|