mirror of
https://github.com/cyberarm/i-mic-fps.git
synced 2025-12-16 08:02:36 +00:00
remove glu from gemfile, added InputMapper, using InputMapper for Camera and Player.
This commit is contained in:
@@ -23,6 +23,16 @@ class IMICFPS
|
||||
@mouse_sensitivity = 20.0
|
||||
@mouse_captured = true
|
||||
@mouse_checked = 0
|
||||
|
||||
InputMapper.set(:camera, :ascend, Gosu::KbSpace)
|
||||
InputMapper.set(:camera, :descend, [Gosu::KbLeftControl, Gosu::KbRightControl])
|
||||
InputMapper.set(:camera, :release_mouse, [Gosu::KbLeftAlt, Gosu::KbRightAlt])
|
||||
InputMapper.set(:camera, :capture_mouse, Gosu::MsLeft)
|
||||
InputMapper.set(:camera, :increase_mouse_sensitivity, Gosu::KB_NUMPAD_PLUS)
|
||||
InputMapper.set(:camera, :decrease_mouse_sensitivity, Gosu::KB_NUMPAD_MINUS)
|
||||
InputMapper.set(:camera, :reset_mouse_sensitivity, Gosu::KB_NUMPAD_MULTIPLY)
|
||||
InputMapper.set(:camera, :increase_view_distance, Gosu::MsWheelUp)
|
||||
InputMapper.set(:camera, :decrease_view_distance, Gosu::MsWheelDown)
|
||||
end
|
||||
|
||||
def attach_to(game_object)
|
||||
@@ -111,56 +121,55 @@ class IMICFPS
|
||||
relative_y_rotation = (@yaw + 180)
|
||||
relative_speed = 0.5
|
||||
|
||||
if button_down?(Gosu::KbUp) || button_down?(Gosu::KbW)
|
||||
if InputMapper.down?(:character, :forward)
|
||||
@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)
|
||||
if InputMapper.down?(:character, :backward)
|
||||
@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)
|
||||
if InputMapper.down?(:character, :strife_left)
|
||||
@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)
|
||||
if InputMapper.down?(:character, :strife_right)
|
||||
@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)
|
||||
if InputMapper.down?(:camera, :ascend)
|
||||
@y+=relative_speed
|
||||
end
|
||||
if button_down?(Gosu::KbLeftShift) || button_down?(Gosu::KbRightShift)
|
||||
if InputMapper.down?(:camera, :descend)
|
||||
@y-=relative_speed
|
||||
end
|
||||
end
|
||||
|
||||
def button_up(id)
|
||||
case id
|
||||
when Gosu::KbLeftAlt, Gosu::KbRightAlt
|
||||
if InputMapper.is?(:camera, :release_mouse, id)
|
||||
@mouse_captured = false
|
||||
$window.needs_cursor = true
|
||||
when Gosu::MsLeft
|
||||
elsif InputMapper.is?(:camera, :capture_mouse, id)
|
||||
@mouse_captured = true
|
||||
$window.needs_cursor = false
|
||||
when Gosu::KB_NUMPAD_PLUS
|
||||
elsif InputMapper.is?(:camera, :increase_mouse_sensitivity, id)
|
||||
@mouse_sensitivity+=1
|
||||
@mouse_sensitivity = @mouse_sensitivity.clamp(1.0, 100.0)
|
||||
when Gosu::KbMinus, Gosu::KB_NUMPAD_MINUS
|
||||
elsif InputMapper.is?(:camera, :decrease_mouse_sensitivity, id)
|
||||
@mouse_sensitivity-=1
|
||||
@mouse_sensitivity = @mouse_sensitivity.clamp(1.0, 100.0)
|
||||
when Gosu::KB_NUMPAD_MULTIPLY
|
||||
elsif InputMapper.is?(:camera, :reset_mouse_sensitivity, id)
|
||||
@mouse_sensitivity = 20.0
|
||||
when Gosu::MsWheelUp
|
||||
elsif InputMapper.is?(:camera, :increase_view_distance, id)
|
||||
# @field_of_view += 1
|
||||
# @field_of_view = @field_of_view.clamp(1, 100)
|
||||
@view_distance += 1
|
||||
@view_distance = @view_distance.clamp(1, 1000)
|
||||
when Gosu::MsWheelDown
|
||||
elsif InputMapper.is?(:camera, :decrease_view_distance, id)
|
||||
# @field_of_view -= 1
|
||||
# @field_of_view = @field_of_view.clamp(1, 100)
|
||||
@view_distance -= 1
|
||||
|
||||
@@ -8,6 +8,18 @@ class IMICFPS
|
||||
|
||||
def setup
|
||||
bind_model("base", "biped")
|
||||
InputMapper.set(:character, :forward, [Gosu::KbUp, Gosu::KbW])
|
||||
InputMapper.set(:character, :backward, [Gosu::KbDown, Gosu::KbS])
|
||||
InputMapper.set(:character, :strife_left, Gosu::KbA)
|
||||
InputMapper.set(:character, :strife_right, Gosu::KbD)
|
||||
InputMapper.set(:character, :turn_left, Gosu::KbLeft)
|
||||
InputMapper.set(:character, :turn_right, Gosu::KbRight)
|
||||
InputMapper.set(:character, :jump, Gosu::KbSpace)
|
||||
InputMapper.set(:character, :sprint, [Gosu::KbLeftControl])
|
||||
|
||||
InputMapper.set(:character, :turn_180, Gosu::KbX)
|
||||
InputMapper.set(:character, :toggle_first_person_view, Gosu::KbF)
|
||||
|
||||
@speed = 2.5 # meter's per second
|
||||
@running_speed = 6.8 # meter's per second
|
||||
@old_speed = @speed
|
||||
@@ -90,7 +102,7 @@ class IMICFPS
|
||||
@floor = @terrain.height_at(self, 4.5)
|
||||
|
||||
relative_speed = @speed
|
||||
if button_down?(Gosu::KbLeftControl)
|
||||
if InputMapper.down?(:character, :sprint)
|
||||
relative_speed = (@running_speed)*(delta_time)
|
||||
else
|
||||
relative_speed = @speed*(delta_time)
|
||||
@@ -98,27 +110,27 @@ class IMICFPS
|
||||
|
||||
relative_y_rotation = @y_rotation*-1
|
||||
|
||||
if button_down?(Gosu::KbUp) || button_down?(Gosu::KbW)
|
||||
if InputMapper.down?(:character, :forward)
|
||||
@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)
|
||||
if InputMapper.down?(:character, :backward)
|
||||
@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)
|
||||
if InputMapper.down?(:character, :strife_left)
|
||||
@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)
|
||||
if InputMapper.down?(:character, :strife_right)
|
||||
@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::KbLeft)
|
||||
if InputMapper.down?(:character, :turn_left)
|
||||
@y_rotation+=(relative_speed*1000)*delta_time
|
||||
end
|
||||
if button_down?(Gosu::KbRight)
|
||||
if InputMapper.down?(:character, :turn_right)
|
||||
@y_rotation-=(relative_speed*1000)*delta_time
|
||||
end
|
||||
|
||||
@@ -127,7 +139,7 @@ class IMICFPS
|
||||
@y_velocity-=(IMICFPS::GRAVITY*air_time)*delta_time
|
||||
end
|
||||
|
||||
if button_down?(Gosu::KbSpace) && !@jumping
|
||||
if InputMapper.down?(:character, :jump) && !@jumping
|
||||
@jumping = true
|
||||
@_time_in_air = Gosu.milliseconds
|
||||
elsif !@jumping && @y > @floor
|
||||
@@ -141,7 +153,7 @@ class IMICFPS
|
||||
end
|
||||
end
|
||||
if @jumping && !@falling
|
||||
if button_down?(Gosu::KbSpace)
|
||||
if InputMapper.down?(:character, :jump)
|
||||
@y_velocity = 1.5
|
||||
@falling = true
|
||||
end
|
||||
@@ -158,11 +170,11 @@ class IMICFPS
|
||||
end
|
||||
|
||||
def button_up(id)
|
||||
case id
|
||||
when Gosu::KbX
|
||||
if InputMapper.is?(:character, :turn_180, id)
|
||||
@y_rotation = @y_rotation+180
|
||||
@y_rotation %= 360
|
||||
when Gosu::KbF
|
||||
|
||||
elsif InputMapper.is?(:character, :toggle_first_person_view, id)
|
||||
@first_person_view = !@first_person_view
|
||||
puts "First Person? #{@first_person_view}"
|
||||
end
|
||||
|
||||
@@ -10,7 +10,7 @@ class IMICFPS
|
||||
|
||||
def initialize(manifest_file:, game_object: nil)
|
||||
@manifest = YAML.load(File.read(manifest_file))
|
||||
pp @manifest
|
||||
# pp @manifest
|
||||
@file_path = File.expand_path("./../model/", manifest_file) + "/#{@manifest["model"]}"
|
||||
@name = @manifest["name"]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user