refactor(character): 重构角色动作处理逻辑 feat(swordman): 实现剑士基础攻击和技能1处理 refactor(state): 优化状态机与动作上下文管理 feat(input): 改进输入系统支持动作请求队列 refactor(movement): 重构移动系统支持行走/奔跑模式
56 lines
1.6 KiB
C++
56 lines
1.6 KiB
C++
#pragma once
|
|
|
|
#include "character/CharacterActionTypes.h"
|
|
#include <frostbite2D/event/joystick_event.h>
|
|
#include <frostbite2D/event/key_event.h>
|
|
#include <cstdint>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace frostbite2D {
|
|
|
|
/// 将 SDL 键盘/手柄事件统一转换为角色命令,避免状态机直接依赖设备细节。
|
|
class CharacterInputRouter {
|
|
public:
|
|
bool OnKeyDown(const KeyEvent& event);
|
|
bool OnKeyUp(const KeyUpEvent& event);
|
|
bool OnJoystickAxis(const JoystickAxisEvent& event);
|
|
bool OnJoystickButtonDown(const JoystickButtonDownEvent& event);
|
|
bool OnJoystickButtonUp(const JoystickButtonUpEvent& event);
|
|
|
|
void EmitCommands(CharacterCommandBuffer& commandBuffer);
|
|
void ClearFrameState();
|
|
|
|
private:
|
|
enum class KeyboardMoveDirection {
|
|
None,
|
|
Left,
|
|
Right,
|
|
Up,
|
|
Down,
|
|
};
|
|
|
|
void QueueAction(const std::string& actionId);
|
|
bool IsDirectionPressed(KeyboardMoveDirection direction) const;
|
|
bool HasDirectionalInput() const;
|
|
void RefreshKeyboardMoveMode();
|
|
|
|
bool left_ = false;
|
|
bool right_ = false;
|
|
bool up_ = false;
|
|
bool down_ = false;
|
|
bool jumpPressed_ = false;
|
|
std::vector<std::string> actionRequests_;
|
|
CharacterMoveMode keyboardMoveMode_ = CharacterMoveMode::None;
|
|
KeyboardMoveDirection runDirection_ = KeyboardMoveDirection::None;
|
|
std::uint32_t leftLastTapTimestamp_ = 0;
|
|
std::uint32_t rightLastTapTimestamp_ = 0;
|
|
std::uint32_t upLastTapTimestamp_ = 0;
|
|
std::uint32_t downLastTapTimestamp_ = 0;
|
|
float leftStickX_ = 0.0f;
|
|
float leftStickY_ = 0.0f;
|
|
float joystickDeadZone_ = 0.2f;
|
|
};
|
|
|
|
} // namespace frostbite2D
|