Files
DNF_DEV/source_game/Actor/Object/CharacterObject.cpp

70 lines
1.8 KiB
C++

#include "CharacterObject.h"
#include "Asset/Squirrel/SquirrelManager.h"
CharacterObject::~CharacterObject()
{
}
void CharacterObject::Construction(int job)
{
m_objecttype = ObjectType::CHARACTER;
this->Job = job;
// 创建装备管理器
_EquipmentManager = new Chr_Equipment();
_EquipmentManager->Init(this);
// // 创建阴影对象
// _Shadow = new Chr_Shadow();
// _Shadow->Init(this);
// 创建动画管理器(一定要先创建装备管理器再创建动画管理器 因为需要读取身上的装备)
_AnimationManager = new Chr_Animation();
_AnimationManager->Init(this);
// 创建状态机
_StateMachine = new Chr_StateMachine();
_StateMachine->Init(this);
// 开启控制器
EnableController();
}
void CharacterObject::EnableController()
{
this->_Controller = new Chr_Controller();
_Controller->Init(this);
AddChild(_Controller);
}
void CharacterObject::DisableController()
{
this->RemoveChild(_Controller);
this->_Controller = nullptr;
}
void CharacterObject::ControllerMsg(CONTROLLER_MSG_TYPE msgType, void *msgData)
{
// 摇杆移动(左)
if (msgType == CONTROLLER_MSG_TYPE::CONTROLLER_MSG_TYPE_LEFT_JOYSTICK_MOVE)
{
Vec2 *pos = (Vec2 *)msgData;
std::vector<float> movedata = {pos->x, pos->y};
this->GetObjectVars().SetArray("_move_data_", movedata);
this->_StateMachine->ChangeState(BASE_STATE::MOVE);
}
}
void CharacterObject::Update(float deltaTime)
{
ActiveObject::Update(deltaTime);
}
void CharacterObject::SetPos(Vec2 pos)
{
BaseObject::SetPos(pos);
if(_Shadow)_Shadow->SetPos(this->GetPos());
}
void CharacterObject::SetDirection(int dir)
{
BaseObject::SetDirection(dir);
if(_Shadow)_Shadow->SetDirection(this->GetDirection());
}