From: Brendan Hansen Date: Tue, 22 Feb 2022 23:52:27 +0000 (-0600) Subject: random changes X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=795bf7b16b3926d15f8800a9890ce245f71a937f;p=voxel-shooter.git random changes --- diff --git a/src/main.onyx b/src/main.onyx index c530db1..cdf4fff 100644 --- a/src/main.onyx +++ b/src/main.onyx @@ -79,6 +79,7 @@ setup_opengl :: () { shaders_init(); fonts_init(); + immediate_init(); world_shader = shader_make("assets/shaders/world.glsl"); @@ -86,8 +87,6 @@ setup_opengl :: () { shader_set_uniform(world_shader, #cstr "u_fog_start", 50.0f); shader_set_uniform(world_shader, #cstr "u_fog_range", 10.0f); - immediate_init(); - font = font_lookup(.{"./assets/fonts/calibri.ttf", 32}); shader_use(world_shader); diff --git a/src/utils/input.onyx b/src/utils/input.onyx index 2a5f217..77bca19 100644 --- a/src/utils/input.onyx +++ b/src/utils/input.onyx @@ -2,38 +2,38 @@ use package core use package glfw3 #local { - keys_this_frame : [..] u32 // Keys currently being pressed this frame - keys_pulse_frame : [..] u32 // Keys pressed during this frame, only set once per keypress - keys_last_frame : [..] u32 // Keys being pressed in the last frame + keys_this_frame : [..] u32 // Keys currently being pressed this frame + keys_pulse_frame : [..] u32 // Keys pressed during this frame, only set once per keypress + keys_last_frame : [..] u32 // Keys being pressed in the last frame - buttons_this_frame: [8] bool // Mouse buttons being pressed this frame - buttons_last_frame: [8] bool // Mouse buttons being pressed last frame + buttons_this_frame: [8] bool // Mouse buttons being pressed this frame + buttons_last_frame: [8] bool // Mouse buttons being pressed last frame } input_update :: () { glfwGetCursorPos(window, ^mouse_x, ^mouse_y); - array.clear(^keys_pulse_frame); - for keys_this_frame { - if !array.contains(keys_last_frame, it) { - keys_pulse_frame << it; - } - } + array.clear(^keys_pulse_frame); + for keys_this_frame { + if !array.contains(keys_last_frame, it) { + keys_pulse_frame << it; + } + } } input_post_update :: () { - array.clear(^keys_pulse_frame); - array.clear(^keys_last_frame); - for keys_this_frame do keys_last_frame << it; + array.clear(^keys_pulse_frame); + array.clear(^keys_last_frame); + for keys_this_frame do keys_last_frame << it; - for 8 do buttons_last_frame[it] = buttons_this_frame[it]; + for 8 do buttons_last_frame[it] = buttons_this_frame[it]; - last_mouse_x = mouse_x; - last_mouse_y = mouse_y; + last_mouse_x = mouse_x; + last_mouse_y = mouse_y; } input_get_keys_this_frame :: () -> [] u32 { - return keys_pulse_frame; + return keys_pulse_frame; } is_key_down :: (key) => array.contains(keys_this_frame, key); @@ -45,57 +45,57 @@ is_button_just_down :: (button) => buttons_this_frame[button] && !buttons_last_f is_button_just_up :: (button) => !buttons_this_frame[button] && buttons_last_frame[button]; #local { - last_mouse_x: f64; - last_mouse_y: f64; + last_mouse_x: f64; + last_mouse_y: f64; - mouse_x: f64; - mouse_y: f64; + mouse_x: f64; + mouse_y: f64; } mouse_get_delta :: () -> (f64, f64) { - return mouse_x - last_mouse_x, mouse_y - last_mouse_y; + return mouse_x - last_mouse_x, mouse_y - last_mouse_y; } mouse_get_delta_vector :: () -> Vector2 { - dmx, dmy := mouse_get_delta(); - return .{ ~~dmx, ~~dmy }; + dmx, dmy := mouse_get_delta(); + return .{ ~~dmx, ~~dmy }; } mouse_get_position :: () -> (f64, f64) { - return mouse_x, mouse_y; + return mouse_x, mouse_y; } mouse_get_position_vector :: () -> Vector2 { - return .{ ~~mouse_x, ~~mouse_y }; + return .{ ~~mouse_x, ~~mouse_y }; } input_bind_glfw_events :: (window: GLFWwindow_p) { - glfwSetKeyCallback(window, INPUT_KEY_EVENT); - glfwSetMouseButtonCallback(window, INPUT_BUTTON_EVENT); + glfwSetKeyCallback(window, INPUT_KEY_EVENT); + glfwSetMouseButtonCallback(window, INPUT_BUTTON_EVENT); } #local { - INPUT_BUTTON_EVENT :: "__input_button_event" - INPUT_KEY_EVENT :: "__input_key_event" + INPUT_BUTTON_EVENT :: "__input_button_event" + INPUT_KEY_EVENT :: "__input_key_event" } #export INPUT_BUTTON_EVENT (window: GLFWwindow_p, button, action, mod: u32) { - if action == GLFW_PRESS { - buttons_this_frame[button] = true; - } + if action == GLFW_PRESS { + buttons_this_frame[button] = true; + } - if action == GLFW_RELEASE { - buttons_this_frame[button] = false; - } + if action == GLFW_RELEASE { + buttons_this_frame[button] = false; + } } #export INPUT_KEY_EVENT (window: GLFWwindow_p, key, scancode, action, mod: u32) { - if action == GLFW_PRESS { - keys_this_frame << key; - } + if action == GLFW_PRESS { + keys_this_frame << key; + } - if action == GLFW_RELEASE { - array.remove(^keys_this_frame, key); - } + if action == GLFW_RELEASE { + array.remove(^keys_this_frame, key); + } } diff --git a/src/world/player.onyx b/src/world/player.onyx index c10d6d1..1c42616 100644 --- a/src/world/player.onyx +++ b/src/world/player.onyx @@ -58,6 +58,11 @@ player_update :: (use player: ^Player, dt: f32) { body.acc.y = 500; } + if is_key_down(GLFW_KEY_B) && body.on_ground { + // Yeet yourself. + body.acc.y = 10000; + } + physics_simulate(^body, dt, world); // Fix falling off the world diff --git a/src/world/worldgen.onyx b/src/world/worldgen.onyx index 3e662e2..583887d 100644 --- a/src/world/worldgen.onyx +++ b/src/world/worldgen.onyx @@ -24,5 +24,7 @@ generate_chunk :: (world: ^World, chunk: ^Chunk) { } chunk_set(chunk, 0, 0, 0, block_make(1, 0, 1, 1)); + + debug_log(.Debug, "Generated chunk at {}.", chunk.position); }