mirror of
https://github.com/cyberarm/i-mic-fps.git
synced 2025-12-15 23:52:35 +00:00
remove glu from gemfile, added InputMapper, using InputMapper for Camera and Player.
This commit is contained in:
2
Gemfile
2
Gemfile
@@ -1,5 +1,3 @@
|
|||||||
source "https://rubygems.org"
|
source "https://rubygems.org"
|
||||||
gem "opengl-bindings"
|
gem "opengl-bindings"
|
||||||
gem "glu"
|
|
||||||
# gem "glut"
|
|
||||||
gem "gosu"
|
gem "gosu"
|
||||||
@@ -1,8 +1,6 @@
|
|||||||
GEM
|
GEM
|
||||||
remote: https://rubygems.org/
|
remote: https://rubygems.org/
|
||||||
specs:
|
specs:
|
||||||
glu (8.2.2)
|
|
||||||
glu (8.2.2-x86-mingw32)
|
|
||||||
gosu (0.14.5)
|
gosu (0.14.5)
|
||||||
gosu (0.14.5-x86-mingw32)
|
gosu (0.14.5-x86-mingw32)
|
||||||
opengl-bindings (1.6.7)
|
opengl-bindings (1.6.7)
|
||||||
@@ -12,7 +10,6 @@ PLATFORMS
|
|||||||
x86-mingw32
|
x86-mingw32
|
||||||
|
|
||||||
DEPENDENCIES
|
DEPENDENCIES
|
||||||
glu
|
|
||||||
gosu
|
gosu
|
||||||
opengl-bindings
|
opengl-bindings
|
||||||
|
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ end
|
|||||||
$debug = ARGV.join.include?("--debug") ? true : false
|
$debug = ARGV.join.include?("--debug") ? true : false
|
||||||
|
|
||||||
require_relative "lib/common_methods"
|
require_relative "lib/common_methods"
|
||||||
|
require_relative "lib/managers/input_mapper"
|
||||||
require_relative "lib/managers/shader_manager"
|
require_relative "lib/managers/shader_manager"
|
||||||
require_relative "lib/managers/object_manager"
|
require_relative "lib/managers/object_manager"
|
||||||
require_relative "lib/managers/light_manager"
|
require_relative "lib/managers/light_manager"
|
||||||
@@ -95,7 +96,7 @@ require_relative "lib/wavefront/model"
|
|||||||
|
|
||||||
require_relative "lib/window"
|
require_relative "lib/window"
|
||||||
|
|
||||||
MODEL_METER_SCALE = 1.0 # Objects exported from blender using the millimeter object scale will be close to 1 GL unit
|
MODEL_METER_SCALE = 1.0 # Objects exported from blender using the default or meter object scale will be close to 1 GL unit
|
||||||
|
|
||||||
|
|
||||||
if ARGV.join.include?("--profile")
|
if ARGV.join.include?("--profile")
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ class IMICFPS
|
|||||||
b.debug_color = Color.new(1.0,0.0,0.0)
|
b.debug_color = Color.new(1.0,0.0,0.0)
|
||||||
|
|
||||||
# @game_state.game_objects.delete(object) unless object.is_a?(Player)
|
# @game_state.game_objects.delete(object) unless object.is_a?(Player)
|
||||||
puts "#{object} is intersecting #{b}" if object.is_a?(Player)
|
# puts "#{object} is intersecting #{b}" if object.is_a?(Player)
|
||||||
else
|
else
|
||||||
object.debug_color = Color.new(0,1,0)
|
object.debug_color = Color.new(0,1,0)
|
||||||
b.debug_color = Color.new(0,1,0)
|
b.debug_color = Color.new(0,1,0)
|
||||||
|
|||||||
45
lib/managers/input_mapper.rb
Normal file
45
lib/managers/input_mapper.rb
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
class IMICFPS
|
||||||
|
class InputMapper
|
||||||
|
@@keymap = {}
|
||||||
|
|
||||||
|
def self.get(category, action)
|
||||||
|
key = @@keymap.dig(category, action)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.set(category, action, key)
|
||||||
|
raise "category must be a symbol" unless category.is_a?(Symbol)
|
||||||
|
raise "action must be a symbol" unless action.is_a?(Symbol)
|
||||||
|
raise "key must be a whole number or Array of whole numbers, got #{key}" unless key.is_a?(Integer) || key.is_a?(Array)
|
||||||
|
|
||||||
|
@@keymap[category] ||= {}
|
||||||
|
|
||||||
|
warn "InputMapper.set(:#{category}, :#{action}) is already defined as #{@@keymap[category][action]}" if @@keymap[category][action]
|
||||||
|
|
||||||
|
@@keymap[category][action] = key
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.down?(category, action)
|
||||||
|
keys = get(category, action)
|
||||||
|
|
||||||
|
if keys.is_a?(Array)
|
||||||
|
keys.detect do |key|
|
||||||
|
Gosu.button_down?(key)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
Gosu.button_down?(keys)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.is?(category, action, query_key)
|
||||||
|
keys = get(category, action)
|
||||||
|
|
||||||
|
if keys.is_a?(Array)
|
||||||
|
keys.detect do |key|
|
||||||
|
query_key == key
|
||||||
|
end
|
||||||
|
else
|
||||||
|
query_key == keys
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -23,6 +23,16 @@ class IMICFPS
|
|||||||
@mouse_sensitivity = 20.0
|
@mouse_sensitivity = 20.0
|
||||||
@mouse_captured = true
|
@mouse_captured = true
|
||||||
@mouse_checked = 0
|
@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
|
end
|
||||||
|
|
||||||
def attach_to(game_object)
|
def attach_to(game_object)
|
||||||
@@ -111,56 +121,55 @@ class IMICFPS
|
|||||||
relative_y_rotation = (@yaw + 180)
|
relative_y_rotation = (@yaw + 180)
|
||||||
relative_speed = 0.5
|
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
|
@z+=Math.cos(relative_y_rotation * Math::PI / 180)*relative_speed
|
||||||
@x-=Math.sin(relative_y_rotation * Math::PI / 180)*relative_speed
|
@x-=Math.sin(relative_y_rotation * Math::PI / 180)*relative_speed
|
||||||
end
|
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
|
@z-=Math.cos(relative_y_rotation * Math::PI / 180)*relative_speed
|
||||||
@x+=Math.sin(relative_y_rotation * Math::PI / 180)*relative_speed
|
@x+=Math.sin(relative_y_rotation * Math::PI / 180)*relative_speed
|
||||||
end
|
end
|
||||||
|
|
||||||
if button_down?(Gosu::KbA)
|
if InputMapper.down?(:character, :strife_left)
|
||||||
@z+=Math.sin(relative_y_rotation * Math::PI / 180)*relative_speed
|
@z+=Math.sin(relative_y_rotation * Math::PI / 180)*relative_speed
|
||||||
@x+=Math.cos(relative_y_rotation * Math::PI / 180)*relative_speed
|
@x+=Math.cos(relative_y_rotation * Math::PI / 180)*relative_speed
|
||||||
end
|
end
|
||||||
|
|
||||||
if button_down?(Gosu::KbD)
|
if InputMapper.down?(:character, :strife_right)
|
||||||
@z-=Math.sin(relative_y_rotation * Math::PI / 180)*relative_speed
|
@z-=Math.sin(relative_y_rotation * Math::PI / 180)*relative_speed
|
||||||
@x-=Math.cos(relative_y_rotation * Math::PI / 180)*relative_speed
|
@x-=Math.cos(relative_y_rotation * Math::PI / 180)*relative_speed
|
||||||
end
|
end
|
||||||
|
|
||||||
if button_down?(Gosu::KbSpace)
|
if InputMapper.down?(:camera, :ascend)
|
||||||
@y+=relative_speed
|
@y+=relative_speed
|
||||||
end
|
end
|
||||||
if button_down?(Gosu::KbLeftShift) || button_down?(Gosu::KbRightShift)
|
if InputMapper.down?(:camera, :descend)
|
||||||
@y-=relative_speed
|
@y-=relative_speed
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def button_up(id)
|
def button_up(id)
|
||||||
case id
|
if InputMapper.is?(:camera, :release_mouse, id)
|
||||||
when Gosu::KbLeftAlt, Gosu::KbRightAlt
|
|
||||||
@mouse_captured = false
|
@mouse_captured = false
|
||||||
$window.needs_cursor = true
|
$window.needs_cursor = true
|
||||||
when Gosu::MsLeft
|
elsif InputMapper.is?(:camera, :capture_mouse, id)
|
||||||
@mouse_captured = true
|
@mouse_captured = true
|
||||||
$window.needs_cursor = false
|
$window.needs_cursor = false
|
||||||
when Gosu::KB_NUMPAD_PLUS
|
elsif InputMapper.is?(:camera, :increase_mouse_sensitivity, id)
|
||||||
@mouse_sensitivity+=1
|
@mouse_sensitivity+=1
|
||||||
@mouse_sensitivity = @mouse_sensitivity.clamp(1.0, 100.0)
|
@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-=1
|
||||||
@mouse_sensitivity = @mouse_sensitivity.clamp(1.0, 100.0)
|
@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
|
@mouse_sensitivity = 20.0
|
||||||
when Gosu::MsWheelUp
|
elsif InputMapper.is?(:camera, :increase_view_distance, id)
|
||||||
# @field_of_view += 1
|
# @field_of_view += 1
|
||||||
# @field_of_view = @field_of_view.clamp(1, 100)
|
# @field_of_view = @field_of_view.clamp(1, 100)
|
||||||
@view_distance += 1
|
@view_distance += 1
|
||||||
@view_distance = @view_distance.clamp(1, 1000)
|
@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 -= 1
|
||||||
# @field_of_view = @field_of_view.clamp(1, 100)
|
# @field_of_view = @field_of_view.clamp(1, 100)
|
||||||
@view_distance -= 1
|
@view_distance -= 1
|
||||||
|
|||||||
@@ -8,6 +8,18 @@ class IMICFPS
|
|||||||
|
|
||||||
def setup
|
def setup
|
||||||
bind_model("base", "biped")
|
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
|
@speed = 2.5 # meter's per second
|
||||||
@running_speed = 6.8 # meter's per second
|
@running_speed = 6.8 # meter's per second
|
||||||
@old_speed = @speed
|
@old_speed = @speed
|
||||||
@@ -90,7 +102,7 @@ class IMICFPS
|
|||||||
@floor = @terrain.height_at(self, 4.5)
|
@floor = @terrain.height_at(self, 4.5)
|
||||||
|
|
||||||
relative_speed = @speed
|
relative_speed = @speed
|
||||||
if button_down?(Gosu::KbLeftControl)
|
if InputMapper.down?(:character, :sprint)
|
||||||
relative_speed = (@running_speed)*(delta_time)
|
relative_speed = (@running_speed)*(delta_time)
|
||||||
else
|
else
|
||||||
relative_speed = @speed*(delta_time)
|
relative_speed = @speed*(delta_time)
|
||||||
@@ -98,27 +110,27 @@ class IMICFPS
|
|||||||
|
|
||||||
relative_y_rotation = @y_rotation*-1
|
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
|
@z+=Math.cos(relative_y_rotation * Math::PI / 180)*relative_speed
|
||||||
@x-=Math.sin(relative_y_rotation * Math::PI / 180)*relative_speed
|
@x-=Math.sin(relative_y_rotation * Math::PI / 180)*relative_speed
|
||||||
end
|
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
|
@z-=Math.cos(relative_y_rotation * Math::PI / 180)*relative_speed
|
||||||
@x+=Math.sin(relative_y_rotation * Math::PI / 180)*relative_speed
|
@x+=Math.sin(relative_y_rotation * Math::PI / 180)*relative_speed
|
||||||
end
|
end
|
||||||
if button_down?(Gosu::KbA)
|
if InputMapper.down?(:character, :strife_left)
|
||||||
@z+=Math.sin(relative_y_rotation * Math::PI / 180)*relative_speed
|
@z+=Math.sin(relative_y_rotation * Math::PI / 180)*relative_speed
|
||||||
@x+=Math.cos(relative_y_rotation * Math::PI / 180)*relative_speed
|
@x+=Math.cos(relative_y_rotation * Math::PI / 180)*relative_speed
|
||||||
end
|
end
|
||||||
if button_down?(Gosu::KbD)
|
if InputMapper.down?(:character, :strife_right)
|
||||||
@z-=Math.sin(relative_y_rotation * Math::PI / 180)*relative_speed
|
@z-=Math.sin(relative_y_rotation * Math::PI / 180)*relative_speed
|
||||||
@x-=Math.cos(relative_y_rotation * Math::PI / 180)*relative_speed
|
@x-=Math.cos(relative_y_rotation * Math::PI / 180)*relative_speed
|
||||||
end
|
end
|
||||||
|
|
||||||
if button_down?(Gosu::KbLeft)
|
if InputMapper.down?(:character, :turn_left)
|
||||||
@y_rotation+=(relative_speed*1000)*delta_time
|
@y_rotation+=(relative_speed*1000)*delta_time
|
||||||
end
|
end
|
||||||
if button_down?(Gosu::KbRight)
|
if InputMapper.down?(:character, :turn_right)
|
||||||
@y_rotation-=(relative_speed*1000)*delta_time
|
@y_rotation-=(relative_speed*1000)*delta_time
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -127,7 +139,7 @@ class IMICFPS
|
|||||||
@y_velocity-=(IMICFPS::GRAVITY*air_time)*delta_time
|
@y_velocity-=(IMICFPS::GRAVITY*air_time)*delta_time
|
||||||
end
|
end
|
||||||
|
|
||||||
if button_down?(Gosu::KbSpace) && !@jumping
|
if InputMapper.down?(:character, :jump) && !@jumping
|
||||||
@jumping = true
|
@jumping = true
|
||||||
@_time_in_air = Gosu.milliseconds
|
@_time_in_air = Gosu.milliseconds
|
||||||
elsif !@jumping && @y > @floor
|
elsif !@jumping && @y > @floor
|
||||||
@@ -141,7 +153,7 @@ class IMICFPS
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
if @jumping && !@falling
|
if @jumping && !@falling
|
||||||
if button_down?(Gosu::KbSpace)
|
if InputMapper.down?(:character, :jump)
|
||||||
@y_velocity = 1.5
|
@y_velocity = 1.5
|
||||||
@falling = true
|
@falling = true
|
||||||
end
|
end
|
||||||
@@ -158,11 +170,11 @@ class IMICFPS
|
|||||||
end
|
end
|
||||||
|
|
||||||
def button_up(id)
|
def button_up(id)
|
||||||
case id
|
if InputMapper.is?(:character, :turn_180, id)
|
||||||
when Gosu::KbX
|
|
||||||
@y_rotation = @y_rotation+180
|
@y_rotation = @y_rotation+180
|
||||||
@y_rotation %= 360
|
@y_rotation %= 360
|
||||||
when Gosu::KbF
|
|
||||||
|
elsif InputMapper.is?(:character, :toggle_first_person_view, id)
|
||||||
@first_person_view = !@first_person_view
|
@first_person_view = !@first_person_view
|
||||||
puts "First Person? #{@first_person_view}"
|
puts "First Person? #{@first_person_view}"
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ class IMICFPS
|
|||||||
|
|
||||||
def initialize(manifest_file:, game_object: nil)
|
def initialize(manifest_file:, game_object: nil)
|
||||||
@manifest = YAML.load(File.read(manifest_file))
|
@manifest = YAML.load(File.read(manifest_file))
|
||||||
pp @manifest
|
# pp @manifest
|
||||||
@file_path = File.expand_path("./../model/", manifest_file) + "/#{@manifest["model"]}"
|
@file_path = File.expand_path("./../model/", manifest_file) + "/#{@manifest["model"]}"
|
||||||
@name = @manifest["name"]
|
@name = @manifest["name"]
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ class IMICFPS
|
|||||||
@crosshair_color = Gosu::Color.rgb(255,127,0)
|
@crosshair_color = Gosu::Color.rgb(255,127,0)
|
||||||
|
|
||||||
# @font = Gosu::Font.new(18, name: "DejaVu Sans")
|
# @font = Gosu::Font.new(18, name: "DejaVu Sans")
|
||||||
@text = MultiLineText.new("Pending...", x: 10, y: 10, z: 1, size: 18, font: "DejaVu Sans")
|
@text = Text.new("Pending...", x: 10, y: 10, z: 1, size: 18, font: "DejaVu Sans")
|
||||||
|
|
||||||
Light.new(x: 3, y: -6, z: 6, game_state: self)
|
Light.new(x: 3, y: -6, z: 6, game_state: self)
|
||||||
Light.new(x: 0, y: 100, z: 0, diffuse: Color.new(1.0, 0.5, 0.1), game_state: self)
|
Light.new(x: 0, y: 100, z: 0, diffuse: Color.new(1.0, 0.5, 0.1), game_state: self)
|
||||||
@@ -76,7 +76,6 @@ 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 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)}
|
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}
|
#{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}
|
Field Of View: #{@camera.field_of_view}
|
||||||
Mouse Sesitivity: #{@camera.mouse_sensitivity}
|
Mouse Sesitivity: #{@camera.mouse_sensitivity}
|
||||||
@@ -106,7 +105,11 @@ Draw Skydome: #{@draw_skydome}
|
|||||||
Debug mode: <c=992200>#{$debug}</c>
|
Debug mode: <c=992200>#{$debug}</c>
|
||||||
eos
|
eos
|
||||||
end
|
end
|
||||||
@text.text = string
|
if $debug
|
||||||
|
@text.text = string
|
||||||
|
else
|
||||||
|
@text.text = "FPS: #{Gosu.fps}"
|
||||||
|
end
|
||||||
|
|
||||||
@collision_manager.update
|
@collision_manager.update
|
||||||
@game_objects.each(&:update)
|
@game_objects.each(&:update)
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ class IMICFPS
|
|||||||
end
|
end
|
||||||
|
|
||||||
def set_texture(texture_path)
|
def set_texture(texture_path)
|
||||||
puts "#{name} texture #{texture_path}"
|
# puts "#{name} texture #{texture_path}"
|
||||||
@texture = Gosu::Image.new(texture_path, retro: false)
|
@texture = Gosu::Image.new(texture_path, retro: false)
|
||||||
array_of_pixels = @texture.to_blob
|
array_of_pixels = @texture.to_blob
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user