新增角色状态机框架,包含空闲、移动、跳跃、攻击等状态 添加输入路由组件,统一处理键盘和手柄输入 引入动作库管理角色动作定义,支持PVF脚本配置 重构角色对象,整合运动器、状态机和输入处理 修复Actor子节点排序时的迭代安全问题
78 lines
2.9 KiB
C++
78 lines
2.9 KiB
C++
#pragma once
|
|
|
|
#include "character/CharacterActionLibrary.h"
|
|
#include "character/CharacterAnimation.h"
|
|
#include "character/CharacterDataLoader.h"
|
|
#include "character/CharacterEquipmentManager.h"
|
|
#include "character/CharacterInputRouter.h"
|
|
#include "character/CharacterStateMachine.h"
|
|
#include <frostbite2D/2d/actor.h>
|
|
#include <frostbite2D/event/joystick_event.h>
|
|
#include <frostbite2D/event/key_event.h>
|
|
#include <optional>
|
|
#include <string>
|
|
|
|
namespace frostbite2D {
|
|
|
|
class CharacterObject : public Actor {
|
|
public:
|
|
CharacterObject() = default;
|
|
~CharacterObject() override = default;
|
|
|
|
bool Construction(int jobId);
|
|
|
|
void SetAction(const std::string& actionName);
|
|
void SetDirection(int direction);
|
|
void SetCharacterPosition(const Vec2& pos);
|
|
void SetWorldPosition(const CharacterWorldPosition& pos);
|
|
void PushCommand(const CharacterCommand& command);
|
|
void ApplyHit(const HitContext& hit);
|
|
|
|
void OnUpdate(float deltaTime) override;
|
|
bool OnKeyDown(const KeyEvent& event) override;
|
|
bool OnKeyUp(const KeyEvent& event) override;
|
|
bool OnJoystickAxis(const JoystickEvent& event) override;
|
|
bool OnJoystickButtonDown(const JoystickEvent& event) override;
|
|
bool OnJoystickButtonUp(const JoystickEvent& event) override;
|
|
|
|
int GetJobId() const { return jobId_; }
|
|
int GetGrowType() const { return growType_; }
|
|
int GetDirection() const { return direction_; }
|
|
const std::string& GetCurrentAction() const { return currentAction_; }
|
|
CharacterStateId GetState() const { return stateMachine_.GetState(); }
|
|
const CharacterIntent& GetCurrentIntent() const { return currentIntent_; }
|
|
const CharacterWorldPosition& GetWorldPosition() const { return motor_.position; }
|
|
const CharacterMotor& GetMotor() const { return motor_; }
|
|
CharacterMotor& GetMotorMutable() { return motor_; }
|
|
float GetLastDeltaTime() const { return lastDeltaTime_; }
|
|
const CharacterActionDefinition* FindAction(const std::string& actionId) const;
|
|
std::string ResolveAnimationTag(const std::string& preferred,
|
|
const std::string& fallback) const;
|
|
void PlayAnimationTag(const std::string& actionTag);
|
|
void SetFacing(int direction);
|
|
|
|
const character::CharacterConfig* GetConfig() const {
|
|
return config_ ? &config_.value() : nullptr;
|
|
}
|
|
const CharacterEquipmentManager& GetEquipmentManager() const { return equipmentManager_; }
|
|
|
|
private:
|
|
int jobId_ = -1;
|
|
int growType_ = -1;
|
|
int direction_ = 1;
|
|
std::string currentAction_;
|
|
std::optional<character::CharacterConfig> config_;
|
|
CharacterEquipmentManager equipmentManager_;
|
|
CharacterActionLibrary actionLibrary_;
|
|
CharacterInputRouter inputRouter_;
|
|
CharacterCommandBuffer commandBuffer_;
|
|
CharacterIntent currentIntent_;
|
|
CharacterStateMachine stateMachine_;
|
|
CharacterMotor motor_;
|
|
CharacterStatus status_;
|
|
RefPtr<CharacterAnimation> animationManager_ = nullptr;
|
|
float lastDeltaTime_ = 0.0f;
|
|
};
|
|
|
|
} // namespace frostbite2D
|