From e3d6919f872708ac0e0b97361895924d182a33b1 Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Sat, 25 Dec 2021 22:26:35 -0600 Subject: [PATCH] changed up the controls to be like minecrafts --- src/main.onyx | 20 +++++++++++++++----- src/shader.onyx | 6 ++++-- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/main.onyx b/src/main.onyx index 86ccd1d..825eed6 100644 --- a/src/main.onyx +++ b/src/main.onyx @@ -126,12 +126,15 @@ update :: (dt: f32) { while camera.y_rot < 0 do camera.y_rot += 2 * math.PI; camera.x_rot = math.clamp(camera.x_rot, -math.PI / 2 + 0.1, math.PI / 2 - 0.1); - speed := 5 * dt; - if glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS { + speed := 7 * dt; + if glfwGetKey(window, GLFW_KEY_LEFT_CONTROL) == GLFW_PRESS { speed = 15 * dt; } - facing := camera_get_forward(^camera); + forward := camera_get_forward(^camera); + facing := forward; + facing.y = 0; + facing = Vector3.norm(facing); if glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS { camera.position += facing * speed; } @@ -146,13 +149,20 @@ update :: (dt: f32) { } dir: Vector3i; - if !world_ray_cast(.{ camera.position, facing }, 40, null, (_, p) => { + if !world_ray_cast(.{ camera.position, forward }, 40, null, (_, p) => { return world_get_block(world, p.x, p.y, p.z) != Block_Empty; }, ^selected_block, ^dir) { selected_block = .{0,0,0}; } if glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS { + camera.position.y += 7 * dt; + } + if glfwGetKey(window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS { + camera.position.y -= 7 * dt; + } + + if glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_LEFT) == GLFW_PRESS { world_set_block(world, selected_block.x, selected_block.y, selected_block.z, Block_Empty); } @@ -184,7 +194,7 @@ draw :: () { if debug_screen { ww, wh: i32; glfwGetWindowSize(window, ^ww, ^wh); - font_print(font, ~~(ww / 2), ~~(wh / 2), "X"); + font_print(font, ~~(ww / 2), ~~(wh / 2), "."); font_print(font, 0, 32, "FPS: {}", game_fps); font_print(font, 0, 64, "Position: {}", camera.position); diff --git a/src/shader.onyx b/src/shader.onyx index a75242d..b7118e4 100644 --- a/src/shader.onyx +++ b/src/shader.onyx @@ -41,8 +41,10 @@ shader_use :: (shader: Shader) { glUseProgram(shader.prog); } -WINDOW_MATRIX_BLOCK :: 0; -WORLD_MATRIX_BLOCK :: 1; +#local { + WINDOW_MATRIX_BLOCK :: 0; + WORLD_MATRIX_BLOCK :: 1; +} shader_link_window_matrix_block :: (use shader: Shader) { matrix_block_index := glGetUniformBlockIndex(prog, #cstr "u_window_matrix_block"); -- 2.25.1