This commit is contained in:
2025-10-06 04:18:49 +08:00
commit df2cacdb92
2784 changed files with 1280840 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
#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);
}

View File

@@ -0,0 +1,19 @@
#pragma once
#include "Actor/Object/BaseObject.h"
class ActiveObject : public BaseObject
{
public:
VecSpeed3 Speed;
public:
void SetPosition(VecFPos3 pos) override;
void SetYpos(float y) override;
void SetSpeed(VecSpeed3 speed);
VecSpeed3 GetSpeed();
public:
void Update(float deltaTime) override;
};

View File

@@ -0,0 +1,97 @@
#include "BaseObject.h"
BaseObject::BaseObject()
{
Init(); // 调用了RenderBase的Init函数 对象才会被执行回调
SetAnchor({0.5f, 0.5f});
}
BaseObject::~BaseObject()
{
}
void BaseObject::SetPosition(VecFPos3 pos)
{
this->Position = pos;
Actor::SetPos(VecFPos{this->Position.x, this->Position.y - this->Position.z});
}
VecFPos3 BaseObject::GetPosition()
{
return this->Position;
}
void BaseObject::SetXpos(float x)
{
this->Position.x = x;
Actor::SetPos({this->Position.x, this->Position.y - this->Position.z});
}
void BaseObject::SetYpos(float y)
{
this->Position.y = y;
Actor::SetPos({this->Position.x, this->Position.y - this->Position.z});
}
void BaseObject::SetZpos(float z)
{
this->Position.z = z;
Actor::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)
{
this->Position.x += pos.x;
this->Position.y += pos.y;
this->Position.z += pos.z;
Actor::SetPos({this->Position.x, this->Position.y - this->Position.z});
}
void BaseObject::MoveBy(float x, float y, float z)
{
this->Position.x += x;
this->Position.y += y;
this->Position.z += z;
Actor::SetPos({this->Position.x, this->Position.y - this->Position.z});
}
void BaseObject::SetDirection(int dir)
{
this->Direction = dir;
VecFPos sc = GetScale();
// 朝右
if (dir == 0)
{
SetScale(VecFPos({SDL_fabsf(sc.x), sc.y}));
}
// 朝左
else if (dir == 1)
{
SetScale(VecFPos({-SDL_fabsf(sc.x), sc.y}));
}
}
int BaseObject::GetDirection()
{
return this->Direction;
}
ObjectVars &BaseObject::GetObjectVars()
{
return _ObjectVars;
}

View File

@@ -0,0 +1,37 @@
#pragma once
#include "EngineFrame/Actor/Actor.h"
#include "Asset/Common/ObjectVars.h"
class BaseObject : public Actor
{
private:
/* data */
public:
VecFPos3 Position; // 位置
int Direction = 0; // 方向
public:
BaseObject(/* args */);
~BaseObject();
// 数据储存器
ObjectVars _ObjectVars;
public:
virtual void SetPosition(VecFPos3 pos);
virtual void SetXpos(float x);
virtual void SetYpos(float y);
virtual void SetZpos(float z);
VecFPos3 GetPosition();
int GetXpos();
int GetYpos();
int GetZpos();
void MoveBy(VecFPos3 pos);
void MoveBy(float x, float y, float z);
void SetDirection(int dir);
int GetDirection();
ObjectVars &GetObjectVars();
};

View File

@@ -0,0 +1,57 @@
#include "CharacterObject.h"
#include "Asset/Squirrel/SquirrelManager.h"
CharacterObject::~CharacterObject()
{
}
void CharacterObject::Update(float deltaTime)
{
ActiveObject::Update(deltaTime);
}
void CharacterObject::Render()
{
ActiveObject::Render();
}
void CharacterObject::Construction(int job)
{
// 创建装备管理器
_EquipmentManager = new Chr_Equipment();
_EquipmentManager->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)
{
VecFPos *pos = (VecFPos *)msgData;
std::vector<float> movedata = {pos->x, pos->y};
this->GetObjectVars().SetArray("_move_data_", movedata);
this->_StateMachine->ChangeState(BASE_STATE::MOVE);
}
}

View File

@@ -0,0 +1,39 @@
#pragma once
#include "Actor/Object/ActiveObject.h"
#include "Asset/Character/Chr_Animation.h"
#include "Asset/Character/Chr_Equipment.h"
#include "Asset/Character/Chr_Controller.h"
#include "Asset/Character/Chr_StateMachine.h"
#include "Global/Global_Enum.h"
class CharacterObject : public ActiveObject
{
public:
// 角色动画管理器
RefPtr<Chr_Animation> _AnimationManager = nullptr;
// 装备管理器
RefPtr<Chr_Equipment> _EquipmentManager = nullptr;
// 角色控制器
RefPtr<Chr_Controller> _Controller = nullptr;
// 角色状态机
RefPtr<Chr_StateMachine> _StateMachine = nullptr;
// 职业
int Job = 0;
// 转职职业 如果是-1则没有转职
int GrowType = -1;
public:
~CharacterObject();
public:
void Update(float deltaTime) override;
void Render() override;
// 通过职业创建角色
void Construction(int job);
// 开启控制器
void EnableController();
// 关闭控制器
void DisableController();
// 控制器信息
void ControllerMsg(CONTROLLER_MSG_TYPE msgType, void* msgData);
};