From 6341c3b817a604516c4911d12d13f36c442056f5 Mon Sep 17 00:00:00 2001 From: Cyberarm Date: Mon, 10 Dec 2018 22:22:01 -0600 Subject: [PATCH] Re-added mousefix :(, camera can now be flown around if it's not attached to a game object, tweaked Player initial jump velocity. --- Gemfile.lock | 2 +- lib/objects/game_objects/camera.rb | 47 +++++++++++++++++++++++++++++- lib/objects/game_objects/player.rb | 5 ++-- lib/states/game_states/game.rb | 1 + 4 files changed, 51 insertions(+), 4 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 2f1a19f..c389f9c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -17,4 +17,4 @@ DEPENDENCIES opengl-bindings BUNDLED WITH - 1.16.6 + 1.17.1 diff --git a/lib/objects/game_objects/camera.rb b/lib/objects/game_objects/camera.rb index 421dc92..9a0cca7 100644 --- a/lib/objects/game_objects/camera.rb +++ b/lib/objects/game_objects/camera.rb @@ -5,7 +5,7 @@ class IMICFPS include GLU attr_accessor :x,:y,:z, :field_of_view, :pitch, :yaw, :roll, :mouse_sensitivity - attr_reader :game_object + attr_reader :game_object, :broken_mouse_centering def initialize(x: 0, y: 0, z: 0, fov: 70.0, distance: 100.0) @x,@y,@z = x,y,z @render_pitch = 20.0 @@ -22,6 +22,9 @@ class IMICFPS @true_mouse = Point.new(Gosu.screen_width/2, Gosu.screen_height/2) @mouse_sensitivity = 20.0 @mouse_captured = true + @mouse_checked = 0 + + @broken_mouse_centering = ARGV.join.include?("--disable-mousefix") ? false : true end def attach_to(game_object) @@ -90,6 +93,14 @@ class IMICFPS if @mouse_captured position_camera if @game_object + if @broken_mouse_centering + if @mouse_checked < 3 + @mouse_checked+=1 + @true_mouse.x, @true_mouse.y = self.mouse_x, self.mouse_y + end + return unless @mouse_checked > 2 + end + @yaw-=Float(@true_mouse.x-self.mouse_x)/(@mouse_sensitivity*@field_of_view)*70 unless @game_object @game_object.y_rotation+=Float(@true_mouse.x-self.mouse_x)/(@mouse_sensitivity*@field_of_view)*70 if @game_object @@ -98,10 +109,44 @@ class IMICFPS @render_pitch = @render_pitch.clamp(-90.0, 90.0) @pitch = @pitch.clamp(-90.0, 90.0) + free_move unless @game_object + self.mouse_x, self.mouse_y = Gosu.screen_width/2.0, Gosu.screen_height/2.0 end end + def free_move + relative_y_rotation = (@yaw + 180) + relative_speed = 0.5 + + if button_down?(Gosu::KbUp) || button_down?(Gosu::KbW) + @z+=Math.cos(relative_y_rotation * Math::PI / 180)*relative_speed + @x-=Math.sin(relative_y_rotation * Math::PI / 180)*relative_speed + end + + if button_down?(Gosu::KbDown) || button_down?(Gosu::KbS) + @z-=Math.cos(relative_y_rotation * Math::PI / 180)*relative_speed + @x+=Math.sin(relative_y_rotation * Math::PI / 180)*relative_speed + end + + if button_down?(Gosu::KbA) + @z+=Math.sin(relative_y_rotation * Math::PI / 180)*relative_speed + @x+=Math.cos(relative_y_rotation * Math::PI / 180)*relative_speed + end + + if button_down?(Gosu::KbD) + @z-=Math.sin(relative_y_rotation * Math::PI / 180)*relative_speed + @x-=Math.cos(relative_y_rotation * Math::PI / 180)*relative_speed + end + + if button_down?(Gosu::KbSpace) + @y+=relative_speed + end + if button_down?(Gosu::KbLeftShift) || button_down?(Gosu::KbRightShift) + @y-=relative_speed + end + end + def button_up(id) case id when Gosu::KbLeftAlt diff --git a/lib/objects/game_objects/player.rb b/lib/objects/game_objects/player.rb index abae428..ef972d9 100644 --- a/lib/objects/game_objects/player.rb +++ b/lib/objects/game_objects/player.rb @@ -142,10 +142,11 @@ class IMICFPS end if @jumping && !@falling if button_down?(Gosu::KbSpace) - @y_velocity+=(2*15)*delta_time - @falling = true if @y_velocity >= 2 + @y_velocity = 1.5 + @falling = true end end + @y+=@y_velocity*delta_time @y = @floor if @y < @floor diff --git a/lib/states/game_states/game.rb b/lib/states/game_states/game.rb index d79a961..0eed24c 100644 --- a/lib/states/game_states/game.rb +++ b/lib/states/game_states/game.rb @@ -73,6 +73,7 @@ OpenGL Shader Language Version: #{glGetString(GL_SHADING_LANGUAGE_VERSION)} Camera pitch: #{@camera.pitch.round(2)} Yaw: #{@camera.yaw.round(2)} Roll #{@camera.roll.round(2)} Camera X:#{@camera.x.round(2)} Y:#{@camera.y.round(2)} Z:#{@camera.z.round(2)} +Compensating faulty mouse centering? #{@camera.broken_mouse_centering} #{if @camera.game_object then "Actor X:#{@camera.game_object.x.round(2)} Y:#{@camera.game_object.y.round(2)} Z:#{@camera.game_object.z.round(2)}";end} Field Of View: #{@camera.field_of_view} Mouse Sesitivity: #{@camera.mouse_sensitivity}