mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-04-10 06:14:07 +08:00
feat: add run and walk gait
This commit is contained in:
13
src/app.cpp
13
src/app.cpp
@@ -138,7 +138,7 @@ void App::run() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
static Gait player_gait = Gait::WALK;
|
||||
void App::update() {
|
||||
glfwPollEvents();
|
||||
current_time = glfwGetTime();
|
||||
@@ -155,7 +155,16 @@ void App::update() {
|
||||
}
|
||||
m_world.update(delta_time);
|
||||
m_camera.update_move_camera();
|
||||
|
||||
const auto& player= m_world.get_player("TestPlayer");
|
||||
if (player_gait != player.get_gait()) {
|
||||
player_gait = player.get_gait();
|
||||
if (player_gait == Gait::WALK) {
|
||||
m_renderer.update_fov(NORMAL_FOV);
|
||||
}
|
||||
if (player_gait == Gait::RUN) {
|
||||
m_renderer.update_fov(NORMAL_FOV + 3.0f);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -40,6 +40,10 @@ const glm::vec3& Player::get_front() const {
|
||||
return m_front;
|
||||
}
|
||||
|
||||
const Gait& Player::get_gait() const {
|
||||
return m_gait;
|
||||
}
|
||||
|
||||
const std::optional<LookBlock>& Player::get_look_block_pos() const {
|
||||
return m_look_block;
|
||||
}
|
||||
@@ -143,6 +147,7 @@ void Player::update_player_move_state(int key, int action) {
|
||||
}
|
||||
if (action == GLFW_RELEASE) {
|
||||
m_move_state.forward = false;
|
||||
m_gait = Gait::WALK;
|
||||
}
|
||||
break;
|
||||
case GLFW_KEY_S:
|
||||
@@ -193,7 +198,11 @@ void Player::update_player_move_state(int key, int action) {
|
||||
m_move_state.down = false;
|
||||
}
|
||||
break;
|
||||
|
||||
case GLFW_KEY_LEFT_CONTROL:
|
||||
if (action == GLFW_PRESS) {
|
||||
m_gait = Gait::RUN;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -282,6 +291,13 @@ void Player::update_lookup_block() {
|
||||
}
|
||||
|
||||
void Player::update_move(float delta_time) {
|
||||
if (m_gait == Gait::RUN) {
|
||||
max_speed = RUN_SPEED;
|
||||
}
|
||||
if (m_gait == Gait::WALK) {
|
||||
max_speed = WALK_SPEED;
|
||||
}
|
||||
|
||||
if (space_on) {
|
||||
space_on_time += delta_time;
|
||||
if (space_on_time >= MAX_SPACE_ON_TIME) {
|
||||
@@ -368,7 +384,7 @@ void Player::update_x_move() {
|
||||
glm::vec3{static_cast<float>(x + 1), static_cast<float>(y + 1), static_cast<float>(z + 1)}
|
||||
};
|
||||
if (player_box.intersects(block_box)) {
|
||||
|
||||
m_gait = Gait::WALK;
|
||||
m_player_pos.x -= move_distance.x;
|
||||
return;
|
||||
}
|
||||
@@ -430,6 +446,7 @@ void Player::update_z_move() {
|
||||
glm::vec3{static_cast<float>(x + 1), static_cast<float>(y + 1), static_cast<float>(z + 1)}
|
||||
};
|
||||
if (player_box.intersects(block_box)) {
|
||||
m_gait = Gait::WALK;
|
||||
m_player_pos.z -= move_distance.z;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -237,8 +237,14 @@ void Renderer::render_ui() {
|
||||
|
||||
}
|
||||
|
||||
void Renderer::update_fov(float fov) {
|
||||
m_fov = fov;
|
||||
m_p_mat = glm::perspective(glm::radians(fov), m_aspect, 0.1f, 1000.0f);
|
||||
}
|
||||
|
||||
void Renderer::update_proj_matrix(float aspect, float width, float height) {
|
||||
m_p_mat = glm::perspective(glm::radians(FOV), aspect, 0.1f, 1000.0f);
|
||||
m_aspect = aspect;
|
||||
m_p_mat = glm::perspective(glm::radians(m_fov), aspect, 0.1f, 1000.0f);
|
||||
m_ui_proj = glm::ortho(0.0f, width, height, 0.0f, -1.0f, 1.0f);
|
||||
// scale and then translate
|
||||
m_ui_m_matrix = glm::translate(glm::mat4(1.0f), glm::vec3(width / 2.0f, height / 2.0f, 0.0)) *
|
||||
|
||||
Reference in New Issue
Block a user