132 lines
2.8 KiB
C++
132 lines
2.8 KiB
C++
#include "BaseObject.h"
|
|
#include "Actor/Map/GameMap.h"
|
|
|
|
BaseObject::BaseObject()
|
|
{
|
|
// 对象要使用中心锚点
|
|
SetAnchor({0.5f, 0.5f});
|
|
}
|
|
|
|
BaseObject::~BaseObject()
|
|
{
|
|
}
|
|
|
|
void BaseObject::SetPosition(VecFPos3 pos)
|
|
{
|
|
if(pos == this->Position)
|
|
return;
|
|
if (pos.y != this->Position.y)
|
|
{
|
|
SetZOrder(pos.y); // 设置渲染顺序
|
|
}
|
|
this->Position = pos;
|
|
Actor::SetPosition(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;
|
|
Actor::SetPosition(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)
|
|
{
|
|
SetZOrder(y); // 设置渲染顺序
|
|
}
|
|
this->Position.y = y;
|
|
Actor::SetPosition(this->Position.x, this->Position.y - this->Position.z);
|
|
}
|
|
|
|
void BaseObject::SetZpos(int z)
|
|
{
|
|
if (z == this->Position.z)
|
|
return;
|
|
this->Position.z = z;
|
|
Actor::SetPosition(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)
|
|
{
|
|
SetZOrder(RealPos.y); // 设置渲染顺序
|
|
}
|
|
if (RealPos != this->Position){
|
|
this->Position = RealPos;
|
|
Actor::SetPosition({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)
|
|
{
|
|
SetZOrder(RealPos.y); // 设置渲染顺序
|
|
}
|
|
if (RealPos != this->Position)
|
|
{
|
|
this->Position = RealPos;
|
|
Actor::SetPosition({this->Position.x, this->Position.y - this->Position.z});
|
|
}
|
|
}
|
|
|
|
void BaseObject::SetDirection(int dir)
|
|
{
|
|
this->Direction = dir;
|
|
glm::vec2 sc = GetScale();
|
|
// 朝右
|
|
if (dir == 0)
|
|
{
|
|
SetScale(SDL_fabsf(sc.x), sc.y);
|
|
}
|
|
// 朝左
|
|
else if (dir == 1)
|
|
{
|
|
SetScale(-SDL_fabsf(sc.x), sc.y);
|
|
}
|
|
}
|
|
|
|
int BaseObject::GetDirection()
|
|
{
|
|
return this->Direction;
|
|
}
|
|
|
|
ObjectVars &BaseObject::GetObjectVars()
|
|
{
|
|
return _ObjectVars;
|
|
}
|