完成攀爬状态-精细

This commit is contained in:
Ziyu
2025-06-16 14:44:47 +08:00
parent 7e7ad40ef9
commit 2e0edb950c
4 changed files with 29 additions and 2 deletions
+8
View File
@@ -7,6 +7,7 @@
#include "../../../engine/core/context.h"
#include "../../../engine/input/input_manager.h"
#include "../../../engine/component/physics_component.h"
#include "../../../engine/component/transform_component.h"
#include <spdlog/spdlog.h>
namespace game::component::state {
@@ -29,6 +30,13 @@ std::unique_ptr<PlayerState> IdleState::handleInput(engine::core::Context& conte
return std::make_unique<ClimbState>(player_component_);
}
// 如果按下“move_down”且在梯子顶层,则切换到 ClimbState
if (physics_component->isOnTopLadder() && input_manager.isActionDown("move_down")) {
// 需要向下移动一点,确保下一帧能与梯子碰撞(否则会切换回FallState)
player_component_->getTransformComponent()->translate(glm::vec2(0, 2.0f));
return std::make_unique<ClimbState>(player_component_);
}
// 如果按下了左右移动键,则切换到 WalkState
if (input_manager.isActionDown("move_left") || input_manager.isActionDown("move_right")) {
return std::make_unique<WalkState>(player_component_);