mirror of
https://github.com/zhenyan121/Cubed.git
synced 2026-04-09 21:54:09 +08:00
fix: jump fails in certain cases
This commit is contained in:
@@ -20,7 +20,7 @@ private:
|
||||
|
||||
float m_speed = 10.0f;
|
||||
// player is tow block tall, the pos is the lower pos
|
||||
glm::vec3 m_player_pos = glm::vec3(0.0f, 5.0f, 0.0f);
|
||||
glm::vec3 m_player_pos = glm::vec3(0.0f, 15.0f, 0.0f);
|
||||
glm::vec3 m_front = glm::vec3(0, 0, -1);
|
||||
glm::vec3 m_right;
|
||||
MoveState m_move_state;
|
||||
|
||||
@@ -75,7 +75,7 @@ const std::vector<Vertex>& Chunk::get_vertex_data() const{
|
||||
void Chunk::init_chunk() {
|
||||
m_blocks.assign(CHUCK_SIZE * CHUCK_SIZE * CHUCK_SIZE, 0);
|
||||
for (int x = 0; x < CHUCK_SIZE; x++) {
|
||||
for (int y = 0; y < 2; y++) {
|
||||
for (int y = 0; y < 5; y++) {
|
||||
for (int z = 0; z < CHUCK_SIZE; z++) {
|
||||
m_blocks[get_index(x, y, z)] = 1;
|
||||
}
|
||||
|
||||
@@ -147,7 +147,7 @@ void Player::update(float delta_time) {
|
||||
if (m_move_state.up) {
|
||||
auto new_pos = m_player_pos + glm::vec3(0.0f, 1.0f, 0.0f) * speed * 2.0f;
|
||||
new_pos.y += 2.0f;
|
||||
if (!m_world.is_block(new_pos)) {
|
||||
if (!m_world.is_block(glm::floor(new_pos))) {
|
||||
new_pos.y -= 2.0f;
|
||||
m_player_pos = new_pos;
|
||||
}
|
||||
@@ -185,7 +185,7 @@ void Player::update(float delta_time) {
|
||||
|
||||
|
||||
static bool should_ceil = true;
|
||||
if (!m_world.is_block(glm::floor(m_player_pos))) {
|
||||
if (!m_world.is_block(glm::floor(m_player_pos)) && !m_move_state.up) {
|
||||
|
||||
m_player_pos -= glm::vec3(0.0f, 1.0f, 0.0f) * speed * 0.7f;
|
||||
} else if (should_ceil) {
|
||||
|
||||
@@ -244,8 +244,9 @@ int main() {
|
||||
glfwSwapInterval(1);
|
||||
glfwSetWindowSizeCallback(window, window_reshape_callback);
|
||||
glfwSetKeyCallback(window, key_callback);
|
||||
glfwSetMouseButtonCallback(window, mouse_button_callback);
|
||||
|
||||
glfwSetCursorPosCallback(window, cursor_position_callback);
|
||||
glfwSetMouseButtonCallback(window, mouse_button_callback);
|
||||
MapTable::init_map();
|
||||
texture_manager.init_texture();
|
||||
world.init_world();
|
||||
|
||||
Reference in New Issue
Block a user