mirror of
https://github.com/cyberarm/i-mic-fps.git
synced 2025-12-16 08:02:36 +00:00
Replaced usage of with CommonMethods.window (which uses ), refactored InputMapper to match actions to keys and visa-versa, removed categories from InputMapper, moved input mappings from Camera and Player into InputMapper (for now.)
This commit is contained in:
@@ -89,7 +89,7 @@ require_relative "lib/objects/entity"
|
|||||||
require_relative "lib/objects/model_loader"
|
require_relative "lib/objects/model_loader"
|
||||||
require_relative "lib/objects/light"
|
require_relative "lib/objects/light"
|
||||||
|
|
||||||
require_relative "lib/objects/entities/camera"
|
require_relative "lib/objects/camera"
|
||||||
require_relative "lib/objects/entities/player"
|
require_relative "lib/objects/entities/player"
|
||||||
require_relative "lib/objects/entities/tree"
|
require_relative "lib/objects/entities/tree"
|
||||||
require_relative "lib/objects/entities/skydome"
|
require_relative "lib/objects/entities/skydome"
|
||||||
|
|||||||
@@ -10,15 +10,15 @@ class IMICFPS
|
|||||||
def delta_time
|
def delta_time
|
||||||
(Gosu.milliseconds-@delta_time)/1000.0
|
(Gosu.milliseconds-@delta_time)/1000.0
|
||||||
end
|
end
|
||||||
def button_down?(id); $window.button_down?(id); end
|
def button_down?(id); window.button_down?(id); end
|
||||||
|
|
||||||
def mouse_x; $window.mouse_x; end
|
def mouse_x; window.mouse_x; end
|
||||||
def mouse_y; $window.mouse_y; end
|
def mouse_y; window.mouse_y; end
|
||||||
def mouse_x=int; $window.mouse_x=int; end
|
def mouse_x=int; window.mouse_x=int; end
|
||||||
def mouse_y=int; $window.mouse_y=int; end
|
def mouse_y=int; window.mouse_y=int; end
|
||||||
|
|
||||||
def gl(&block)
|
def gl(&block)
|
||||||
$window.gl do
|
window.gl do
|
||||||
block.call
|
block.call
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -32,13 +32,13 @@ class IMICFPS
|
|||||||
end
|
end
|
||||||
|
|
||||||
def draw_rect(*args)
|
def draw_rect(*args)
|
||||||
$window.draw_rect(*args)
|
window.draw_rect(*args)
|
||||||
end
|
end
|
||||||
def draw_quad(*args)
|
def draw_quad(*args)
|
||||||
$window.draw_quad(*args)
|
window.draw_quad(*args)
|
||||||
end
|
end
|
||||||
def fill(color = Gosu::Color::WHITE)
|
def fill(color = Gosu::Color::WHITE)
|
||||||
draw_rect(0, 0, $window.width, $window.height, color)
|
draw_rect(0, 0, window.width, window.height, color)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -3,32 +3,57 @@ class IMICFPS
|
|||||||
@@keymap = {}
|
@@keymap = {}
|
||||||
@@keys = Hash.new(false)
|
@@keys = Hash.new(false)
|
||||||
|
|
||||||
def self.keydown(id)
|
def self.keydown(id_or_action)
|
||||||
@@keys[id] = true
|
if id_or_action.is_a?(Integer)
|
||||||
|
@@keys[id_or_action] = true
|
||||||
|
else
|
||||||
|
query = @@keymap.dig(id_or_action)
|
||||||
|
|
||||||
|
if query.is_a?(Integer)
|
||||||
|
id = query
|
||||||
|
elsif query.is_a?(Array)
|
||||||
|
query.each do |key|
|
||||||
|
@@keys[key] = true
|
||||||
|
end
|
||||||
|
else
|
||||||
|
raise "Something unexpected happened."
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.keyup(id)
|
def self.keyup(id_or_action)
|
||||||
@@keys[id] = false
|
if id_or_action.is_a?(Integer)
|
||||||
|
@@keys[id_or_action] = false
|
||||||
|
else
|
||||||
|
query = @@keymap.dig(id_or_action)
|
||||||
|
|
||||||
|
if query.is_a?(Integer)
|
||||||
|
id = query
|
||||||
|
elsif query.is_a?(Array)
|
||||||
|
query.each do |key|
|
||||||
|
@@keys[key] = false
|
||||||
|
end
|
||||||
|
else
|
||||||
|
raise "Something unexpected happened."
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.get(category, action)
|
def self.get(action)
|
||||||
key = @@keymap.dig(category, action)
|
key = @@keymap.dig(action)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.set(category, action, key)
|
def self.set(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 "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)
|
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(:#{action}) is already defined as #{@@keymap[action]}" if @@keymap[action]
|
||||||
|
|
||||||
warn "InputMapper.set(:#{category}, :#{action}) is already defined as #{@@keymap[category][action]}" if @@keymap[category][action]
|
@@keymap[action] = key
|
||||||
|
|
||||||
@@keymap[category][action] = key
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.down?(category, action)
|
def self.down?(action)
|
||||||
keys = get(category, action)
|
keys = get(action)
|
||||||
|
|
||||||
if keys.is_a?(Array)
|
if keys.is_a?(Array)
|
||||||
keys.detect do |key|
|
keys.detect do |key|
|
||||||
@@ -39,16 +64,60 @@ class IMICFPS
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.is?(category, action, query_key)
|
def self.is?(action, query_key)
|
||||||
keys = get(category, action)
|
keys = @@keymap.dig(action)
|
||||||
|
|
||||||
if keys.is_a?(Array)
|
if keys.is_a?(Array)
|
||||||
keys.detect do |key|
|
keys.include?(query_key)
|
||||||
query_key == key
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
query_key == keys
|
query_key == keys
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.action(key)
|
||||||
|
answer = nil
|
||||||
|
@@keymap.each do |action, value|
|
||||||
|
p action, value
|
||||||
|
|
||||||
|
if value.is_a?(Array)
|
||||||
|
if value.include?(key)
|
||||||
|
answer = action
|
||||||
|
break
|
||||||
|
end
|
||||||
|
|
||||||
|
else
|
||||||
|
if value == key
|
||||||
|
answer = action
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
raise "InputMapper.action(#{key}) is nil!" unless answer
|
||||||
|
answer
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
IMICFPS::InputMapper.set(:forward, [Gosu::KbUp, Gosu::KbW])
|
||||||
|
IMICFPS::InputMapper.set(:backward, [Gosu::KbDown, Gosu::KbS])
|
||||||
|
IMICFPS::InputMapper.set(:strife_left, Gosu::KbA)
|
||||||
|
IMICFPS::InputMapper.set(:strife_right, Gosu::KbD)
|
||||||
|
IMICFPS::InputMapper.set(:turn_left, Gosu::KbLeft)
|
||||||
|
IMICFPS::InputMapper.set(:turn_right, Gosu::KbRight)
|
||||||
|
IMICFPS::InputMapper.set(:jump, Gosu::KbSpace)
|
||||||
|
IMICFPS::InputMapper.set(:sprint, [Gosu::KbLeftControl])
|
||||||
|
IMICFPS::InputMapper.set(:turn_180, Gosu::KbX)
|
||||||
|
|
||||||
|
IMICFPS::InputMapper.set(:ascend, Gosu::KbSpace)
|
||||||
|
IMICFPS::InputMapper.set(:descend, [Gosu::KbLeftControl, Gosu::KbRightControl])
|
||||||
|
IMICFPS::InputMapper.set(:toggle_first_person_view, Gosu::KbF)
|
||||||
|
|
||||||
|
IMICFPS::InputMapper.set(:release_mouse, [Gosu::KbLeftAlt, Gosu::KbRightAlt])
|
||||||
|
IMICFPS::InputMapper.set(:capture_mouse, Gosu::MsLeft)
|
||||||
|
IMICFPS::InputMapper.set(:increase_mouse_sensitivity, Gosu::KB_NUMPAD_PLUS)
|
||||||
|
IMICFPS::InputMapper.set(:decrease_mouse_sensitivity, Gosu::KB_NUMPAD_MINUS)
|
||||||
|
IMICFPS::InputMapper.set(:reset_mouse_sensitivity, Gosu::KB_NUMPAD_MULTIPLY)
|
||||||
|
|
||||||
|
IMICFPS::InputMapper.set(:decrease_view_distance, Gosu::MsWheelDown)
|
||||||
|
IMICFPS::InputMapper.set(:increase_view_distance, Gosu::MsWheelUp)
|
||||||
@@ -6,7 +6,7 @@ class IMICFPS
|
|||||||
|
|
||||||
attr_accessor :field_of_view, :pitch, :yaw, :roll, :mouse_sensitivity
|
attr_accessor :field_of_view, :pitch, :yaw, :roll, :mouse_sensitivity
|
||||||
attr_reader :entity, :position
|
attr_reader :entity, :position
|
||||||
def initialize(x: 0, y: 0, z: 0, fov: 70.0, view_distance: 100.0)
|
def initialize(x: 0, y: 0, z: 0, fov: 70.0, view_distance: 155.0)
|
||||||
@position = Vector.new(x,y,z)
|
@position = Vector.new(x,y,z)
|
||||||
@pitch = 0.0
|
@pitch = 0.0
|
||||||
@yaw = 0.0
|
@yaw = 0.0
|
||||||
@@ -19,26 +19,15 @@ class IMICFPS
|
|||||||
@distance = 4
|
@distance = 4
|
||||||
@origin_distance = @distance
|
@origin_distance = @distance
|
||||||
|
|
||||||
self.mouse_x, self.mouse_y = $window.width/2, $window.height/2
|
self.mouse_x, self.mouse_y = window.width/2, window.height/2
|
||||||
@true_mouse = Point.new($window.width/2, $window.height/2)
|
@true_mouse = Point.new(window.width/2, window.height/2)
|
||||||
@mouse_sensitivity = 20.0 # Less is faster, more is slower
|
@mouse_sensitivity = 20.0 # Less is faster, more is slower
|
||||||
@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, :turn_180, Gosu::KbX)
|
|
||||||
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(entity)
|
def attach_to(entity)
|
||||||
raise "Not a game object!" unless entity.is_a?(Entity)
|
raise "Not an Entity!" unless entity.is_a?(Entity)
|
||||||
@entity = entity
|
@entity = entity
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -74,8 +63,7 @@ class IMICFPS
|
|||||||
@position.y = @entity.position.y + 2
|
@position.y = @entity.position.y + 2
|
||||||
@position.z = @entity.position.z - z_offset
|
@position.z = @entity.position.z - z_offset
|
||||||
|
|
||||||
# @yaw = 180 - @entity.y_rotation
|
@yaw = 180 - @entity.rotation.y
|
||||||
@entity.rotation.y = -@yaw + 180
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def draw
|
def draw
|
||||||
@@ -83,7 +71,7 @@ class IMICFPS
|
|||||||
glMatrixMode(GL_PROJECTION) # The projection matrix is responsible for adding perspective to our scene.
|
glMatrixMode(GL_PROJECTION) # The projection matrix is responsible for adding perspective to our scene.
|
||||||
glLoadIdentity # Resets current modelview matrix
|
glLoadIdentity # Resets current modelview matrix
|
||||||
# Calculates aspect ratio of the window. Gets perspective view. 45 is degree viewing angle, (0.1, 100) are ranges how deep can we draw into the screen
|
# Calculates aspect ratio of the window. Gets perspective view. 45 is degree viewing angle, (0.1, 100) are ranges how deep can we draw into the screen
|
||||||
gluPerspective(@field_of_view, $window.width / $window.height, 0.1, @view_distance)
|
gluPerspective(@field_of_view, window.width / window.height, 0.1, @view_distance)
|
||||||
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
|
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
|
||||||
glRotatef(@pitch,1,0,0)
|
glRotatef(@pitch,1,0,0)
|
||||||
glRotatef(@yaw,0,1,0)
|
glRotatef(@yaw,0,1,0)
|
||||||
@@ -102,7 +90,6 @@ class IMICFPS
|
|||||||
|
|
||||||
def update
|
def update
|
||||||
if @mouse_captured
|
if @mouse_captured
|
||||||
position_camera if @entity
|
|
||||||
|
|
||||||
delta = Float(@true_mouse.x-self.mouse_x)/(@mouse_sensitivity*@field_of_view)*70
|
delta = Float(@true_mouse.x-self.mouse_x)/(@mouse_sensitivity*@field_of_view)*70
|
||||||
@yaw -= delta
|
@yaw -= delta
|
||||||
@@ -113,9 +100,10 @@ class IMICFPS
|
|||||||
|
|
||||||
@entity.rotation.y += delta if @entity
|
@entity.rotation.y += delta if @entity
|
||||||
free_move unless @entity
|
free_move unless @entity
|
||||||
|
position_camera if @entity
|
||||||
|
|
||||||
self.mouse_x = $window.width/2 if self.mouse_x <= 1 || $window.mouse_x >= $window.width-1
|
self.mouse_x = window.width/2 if self.mouse_x <= 1 || window.mouse_x >= window.width-1
|
||||||
self.mouse_y = $window.height/2 if self.mouse_y <= 1 || $window.mouse_y >= $window.height-1
|
self.mouse_y = window.height/2 if self.mouse_y <= 1 || window.mouse_y >= window.height-1
|
||||||
@true_mouse.x, @true_mouse.y = self.mouse_x, self.mouse_y
|
@true_mouse.x, @true_mouse.y = self.mouse_x, self.mouse_y
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -124,62 +112,59 @@ class IMICFPS
|
|||||||
relative_y_rotation = (@yaw + 180)
|
relative_y_rotation = (@yaw + 180)
|
||||||
relative_speed = 0.5
|
relative_speed = 0.5
|
||||||
|
|
||||||
if InputMapper.down?(:character, :forward)
|
if InputMapper.down?( :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 InputMapper.down?(:character, :backward)
|
if InputMapper.down?(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 InputMapper.down?(:character, :strife_left)
|
if InputMapper.down?(: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 InputMapper.down?(:character, :strife_right)
|
if InputMapper.down?(: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 InputMapper.down?(:camera, :ascend)
|
if InputMapper.down?(:ascend)
|
||||||
@y+=relative_speed
|
@y+=relative_speed
|
||||||
end
|
end
|
||||||
if InputMapper.down?(:camera, :descend)
|
if InputMapper.down?(:descend)
|
||||||
@y-=relative_speed
|
@y-=relative_speed
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def button_up(id)
|
def button_up(id)
|
||||||
if InputMapper.is?(:camera, :release_mouse, id)
|
if InputMapper.is?(:release_mouse, id)
|
||||||
@mouse_captured = false
|
@mouse_captured = false
|
||||||
$window.needs_cursor = true
|
window.needs_cursor = true
|
||||||
elsif InputMapper.is?(:camera, :capture_mouse, id)
|
elsif InputMapper.is?(:capture_mouse, id)
|
||||||
@mouse_captured = true
|
@mouse_captured = true
|
||||||
$window.needs_cursor = false
|
window.needs_cursor = false
|
||||||
elsif InputMapper.is?(:camera, :increase_mouse_sensitivity, id)
|
elsif InputMapper.is?(: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)
|
||||||
elsif InputMapper.is?(:camera, :decrease_mouse_sensitivity, id)
|
elsif InputMapper.is?(: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)
|
||||||
elsif InputMapper.is?(:camera, :reset_mouse_sensitivity, id)
|
elsif InputMapper.is?(:reset_mouse_sensitivity, id)
|
||||||
@mouse_sensitivity = 20.0
|
@mouse_sensitivity = 20.0
|
||||||
elsif InputMapper.is?(:camera, :increase_view_distance, id)
|
elsif InputMapper.is?(: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)
|
||||||
elsif InputMapper.is?(:camera, :decrease_view_distance, id)
|
elsif InputMapper.is?(: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
|
||||||
@view_distance = @view_distance.clamp(1, 1000)
|
@view_distance = @view_distance.clamp(1, 1000)
|
||||||
elsif InputMapper.is?(:camera, :turn_180, id)
|
|
||||||
@rotation.y = @rotation.y+180
|
|
||||||
@rotation.y %= 360
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -8,16 +8,6 @@ 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, :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
|
||||||
@@ -98,7 +88,7 @@ class IMICFPS
|
|||||||
|
|
||||||
def update
|
def update
|
||||||
relative_speed = @speed
|
relative_speed = @speed
|
||||||
if InputMapper.down?(:character, :sprint)
|
if InputMapper.down?(: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)
|
||||||
@@ -106,27 +96,27 @@ class IMICFPS
|
|||||||
|
|
||||||
relative_y_rotation = @rotation.y*-1
|
relative_y_rotation = @rotation.y*-1
|
||||||
|
|
||||||
if InputMapper.down?(:character, :forward)
|
if InputMapper.down?(:forward)
|
||||||
@position.z+=Math.cos(relative_y_rotation * Math::PI / 180)*relative_speed
|
@position.z+=Math.cos(relative_y_rotation * Math::PI / 180)*relative_speed
|
||||||
@position.x-=Math.sin(relative_y_rotation * Math::PI / 180)*relative_speed
|
@position.x-=Math.sin(relative_y_rotation * Math::PI / 180)*relative_speed
|
||||||
end
|
end
|
||||||
if InputMapper.down?(:character, :backward)
|
if InputMapper.down?(:backward)
|
||||||
@position.z-=Math.cos(relative_y_rotation * Math::PI / 180)*relative_speed
|
@position.z-=Math.cos(relative_y_rotation * Math::PI / 180)*relative_speed
|
||||||
@position.x+=Math.sin(relative_y_rotation * Math::PI / 180)*relative_speed
|
@position.x+=Math.sin(relative_y_rotation * Math::PI / 180)*relative_speed
|
||||||
end
|
end
|
||||||
if InputMapper.down?(:character, :strife_left)
|
if InputMapper.down?(:strife_left)
|
||||||
@position.z+=Math.sin(relative_y_rotation * Math::PI / 180)*relative_speed
|
@position.z+=Math.sin(relative_y_rotation * Math::PI / 180)*relative_speed
|
||||||
@position.x+=Math.cos(relative_y_rotation * Math::PI / 180)*relative_speed
|
@position.x+=Math.cos(relative_y_rotation * Math::PI / 180)*relative_speed
|
||||||
end
|
end
|
||||||
if InputMapper.down?(:character, :strife_right)
|
if InputMapper.down?(:strife_right)
|
||||||
@position.z-=Math.sin(relative_y_rotation * Math::PI / 180)*relative_speed
|
@position.z-=Math.sin(relative_y_rotation * Math::PI / 180)*relative_speed
|
||||||
@position.x-=Math.cos(relative_y_rotation * Math::PI / 180)*relative_speed
|
@position.x-=Math.cos(relative_y_rotation * Math::PI / 180)*relative_speed
|
||||||
end
|
end
|
||||||
|
|
||||||
if InputMapper.down?(:character, :turn_left)
|
if InputMapper.down?(:turn_left)
|
||||||
@rotation.y+=(relative_speed*1000)*delta_time
|
@rotation.y+=(relative_speed*1000)*delta_time
|
||||||
end
|
end
|
||||||
if InputMapper.down?(:character, :turn_right)
|
if InputMapper.down?(:turn_right)
|
||||||
@rotation.y-=(relative_speed*1000)*delta_time
|
@rotation.y-=(relative_speed*1000)*delta_time
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -135,7 +125,7 @@ class IMICFPS
|
|||||||
@velocity.y-=(IMICFPS::GRAVITY*air_time)*delta_time
|
@velocity.y-=(IMICFPS::GRAVITY*air_time)*delta_time
|
||||||
end
|
end
|
||||||
|
|
||||||
if InputMapper.down?(:character, :jump) && !@jumping
|
if InputMapper.down?(:jump) && !@jumping
|
||||||
@jumping = true
|
@jumping = true
|
||||||
@_time_in_air = Gosu.milliseconds
|
@_time_in_air = Gosu.milliseconds
|
||||||
elsif !@jumping && @position.y > @floor
|
elsif !@jumping && @position.y > @floor
|
||||||
@@ -149,7 +139,7 @@ class IMICFPS
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
if @jumping && !@falling
|
if @jumping && !@falling
|
||||||
if InputMapper.down?(:character, :jump)
|
if InputMapper.down?(:jump)
|
||||||
@velocity.y = 1.5
|
@velocity.y = 1.5
|
||||||
@falling = true
|
@falling = true
|
||||||
end
|
end
|
||||||
@@ -161,9 +151,13 @@ class IMICFPS
|
|||||||
end
|
end
|
||||||
|
|
||||||
def button_up(id)
|
def button_up(id)
|
||||||
if InputMapper.is?(:character, :toggle_first_person_view, id)
|
if InputMapper.is?(:toggle_first_person_view, id)
|
||||||
@first_person_view = !@first_person_view
|
@first_person_view = !@first_person_view
|
||||||
|
@visible = !@first_person_view
|
||||||
puts "First Person? #{@first_person_view}"
|
puts "First Person? #{@first_person_view}"
|
||||||
|
elsif InputMapper.is?(:turn_180, id)
|
||||||
|
@rotation.y = @rotation.y+180
|
||||||
|
@rotation.y %= 360
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
class Text
|
class Text
|
||||||
|
include IMICFPS::CommonMethods
|
||||||
CACHE = {}
|
CACHE = {}
|
||||||
|
|
||||||
attr_accessor :text, :x, :y, :z, :size, :factor_x, :factor_y, :color, :shadow, :shadow_size, :options
|
attr_accessor :text, :x, :y, :z, :size, :factor_x, :factor_y, :color, :shadow, :shadow_size, :options
|
||||||
@@ -29,9 +30,9 @@ class Text
|
|||||||
when :left
|
when :left
|
||||||
@x = 0+BUTTON_PADDING
|
@x = 0+BUTTON_PADDING
|
||||||
when :center
|
when :center
|
||||||
@x = ($window.width/2)-(@textobject.text_width(@text)/2)
|
@x = (window.width/2)-(@textobject.text_width(@text)/2)
|
||||||
when :right
|
when :right
|
||||||
@x = $window.width-BUTTON_PADDING-@textobject.text_width(@text)
|
@x = window.width-BUTTON_PADDING-@textobject.text_width(@text)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
class IMICFPS
|
class IMICFPS
|
||||||
class OpenGLRenderer
|
class OpenGLRenderer
|
||||||
|
include CommonMethods
|
||||||
include OpenGL
|
include OpenGL
|
||||||
include GLU
|
include GLU
|
||||||
|
|
||||||
@@ -76,7 +77,7 @@ class IMICFPS
|
|||||||
glLineWidth(3)
|
glLineWidth(3)
|
||||||
|
|
||||||
glDrawArrays(GL_TRIANGLES, 0, o.flattened_vertices_size/4)
|
glDrawArrays(GL_TRIANGLES, 0, o.flattened_vertices_size/4)
|
||||||
$window.number_of_vertices+=model.vertices.size
|
window.number_of_vertices+=model.vertices.size
|
||||||
|
|
||||||
glLineWidth(1)
|
glLineWidth(1)
|
||||||
glPolygonOffset(0, 0)
|
glPolygonOffset(0, 0)
|
||||||
@@ -84,10 +85,10 @@ class IMICFPS
|
|||||||
glEnable(GL_LIGHTING)
|
glEnable(GL_LIGHTING)
|
||||||
|
|
||||||
glDrawArrays(GL_TRIANGLES, 0, o.flattened_vertices_size/4)
|
glDrawArrays(GL_TRIANGLES, 0, o.flattened_vertices_size/4)
|
||||||
$window.number_of_vertices+=model.vertices.size
|
window.number_of_vertices+=model.vertices.size
|
||||||
else
|
else
|
||||||
glDrawArrays(GL_TRIANGLES, 0, o.flattened_vertices_size/4)
|
glDrawArrays(GL_TRIANGLES, 0, o.flattened_vertices_size/4)
|
||||||
$window.number_of_vertices+=model.vertices.size
|
window.number_of_vertices+=model.vertices.size
|
||||||
end
|
end
|
||||||
|
|
||||||
# glBindBuffer(GL_ARRAY_BUFFER, 0)
|
# glBindBuffer(GL_ARRAY_BUFFER, 0)
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
class IMICFPS
|
class IMICFPS
|
||||||
class Renderer
|
class Renderer
|
||||||
|
include CommonMethods
|
||||||
include OpenGL
|
include OpenGL
|
||||||
include GLU
|
include GLU
|
||||||
|
|
||||||
@@ -23,7 +24,7 @@ class IMICFPS
|
|||||||
end
|
end
|
||||||
|
|
||||||
@bounding_box_renderer.draw_bounding_boxes if $debug
|
@bounding_box_renderer.draw_bounding_boxes if $debug
|
||||||
$window.number_of_vertices+=@bounding_box_renderer.vertex_count if $debug
|
window.number_of_vertices+=@bounding_box_renderer.vertex_count if $debug
|
||||||
# @bounding_box_renderer.bounding_boxes.clear
|
# @bounding_box_renderer.bounding_boxes.clear
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -77,8 +77,8 @@ class IMICFPS
|
|||||||
end
|
end
|
||||||
|
|
||||||
# Draw crosshair
|
# Draw crosshair
|
||||||
draw_rect($window.width/2-@crosshair_size, ($window.height/2-@crosshair_size)-@crosshair_thickness/2, @crosshair_size*2, @crosshair_thickness, @crosshair_color, 0, :default)
|
draw_rect(window.width/2-@crosshair_size, (window.height/2-@crosshair_size)-@crosshair_thickness/2, @crosshair_size*2, @crosshair_thickness, @crosshair_color, 0, :default)
|
||||||
draw_rect(($window.width/2)-@crosshair_thickness/2, $window.height/2-(@crosshair_size*2), @crosshair_thickness, @crosshair_size*2, @crosshair_color, 0, :default)
|
draw_rect((window.width/2)-@crosshair_thickness/2, window.height/2-(@crosshair_size*2), @crosshair_thickness, @crosshair_size*2, @crosshair_color, 0, :default)
|
||||||
|
|
||||||
@text.draw
|
@text.draw
|
||||||
end
|
end
|
||||||
@@ -94,10 +94,6 @@ class IMICFPS
|
|||||||
|
|
||||||
@camera.update
|
@camera.update
|
||||||
|
|
||||||
$window.close if $window.button_down?(Gosu::KbEscape)
|
|
||||||
$window.number_of_vertices = 0
|
|
||||||
@delta_time = Gosu.milliseconds
|
|
||||||
|
|
||||||
if ARGV.join.include?("--playdemo")
|
if ARGV.join.include?("--playdemo")
|
||||||
if @demo_data[@demo_index]&.start_with?("tick")
|
if @demo_data[@demo_index]&.start_with?("tick")
|
||||||
if @demo_tick == @demo_data[@demo_index].split(" ").last.to_i
|
if @demo_tick == @demo_data[@demo_index].split(" ").last.to_i
|
||||||
@@ -108,12 +104,18 @@ class IMICFPS
|
|||||||
|
|
||||||
data = @demo_data[@demo_index].split(" ")
|
data = @demo_data[@demo_index].split(" ")
|
||||||
if data.first == "up"
|
if data.first == "up"
|
||||||
self.button_up(data.last.to_i)
|
input = InputMapper.get(data.last.to_sym)
|
||||||
|
key = input.is_a?(Array) ? input.first : input
|
||||||
|
self.button_up(key)
|
||||||
|
|
||||||
elsif data.first == "down"
|
elsif data.first == "down"
|
||||||
self.button_down(data.last.to_i)
|
input = InputMapper.get(data.last.to_sym)
|
||||||
|
key = input.is_a?(Array) ? input.first : input
|
||||||
|
self.button_down(key)
|
||||||
|
|
||||||
elsif data.first == "mouse"
|
elsif data.first == "mouse"
|
||||||
@camera.pitch = data[1].to_f
|
@camera.pitch = data[1].to_f
|
||||||
@camera.yaw = data[2].to_f
|
@player.rotation.y = (data[2].to_f * -1) - 180
|
||||||
else
|
else
|
||||||
# hmm
|
# hmm
|
||||||
end
|
end
|
||||||
@@ -141,6 +143,10 @@ class IMICFPS
|
|||||||
end
|
end
|
||||||
|
|
||||||
@demo_tick += 1 if @demo_tick
|
@demo_tick += 1 if @demo_tick
|
||||||
|
|
||||||
|
window.close if window.button_down?(Gosu::KbEscape)
|
||||||
|
window.number_of_vertices = 0
|
||||||
|
@delta_time = Gosu.milliseconds
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_text
|
def update_text
|
||||||
@@ -158,8 +164,8 @@ Field Of View: #{@camera.field_of_view}
|
|||||||
Mouse Sesitivity: #{@camera.mouse_sensitivity}
|
Mouse Sesitivity: #{@camera.mouse_sensitivity}
|
||||||
Last Frame: #{delta_time*1000.0}ms (#{Gosu.fps} fps)
|
Last Frame: #{delta_time*1000.0}ms (#{Gosu.fps} fps)
|
||||||
|
|
||||||
Vertices: #{formatted_number($window.number_of_vertices)}
|
Vertices: #{formatted_number(window.number_of_vertices)}
|
||||||
Faces: #{formatted_number($window.number_of_vertices/3)}
|
Faces: #{formatted_number(window.number_of_vertices/3)}
|
||||||
|
|
||||||
Draw Skydome: #{@draw_skydome}
|
Draw Skydome: #{@draw_skydome}
|
||||||
Debug mode: <c=992200>#{$debug}</c>
|
Debug mode: <c=992200>#{$debug}</c>
|
||||||
@@ -175,8 +181,8 @@ Field Of View: #{@camera.field_of_view}
|
|||||||
Mouse Sesitivity: #{@camera.mouse_sensitivity}
|
Mouse Sesitivity: #{@camera.mouse_sensitivity}
|
||||||
Last Frame: #{delta_time*1000.0}ms (#{Gosu.fps} fps)
|
Last Frame: #{delta_time*1000.0}ms (#{Gosu.fps} fps)
|
||||||
|
|
||||||
Vertices: #{formatted_number($window.number_of_vertices)}
|
Vertices: #{formatted_number(window.number_of_vertices)}
|
||||||
Faces: #{formatted_number($window.number_of_vertices/3)}
|
Faces: #{formatted_number(window.number_of_vertices/3)}
|
||||||
|
|
||||||
Draw Skydome: #{@draw_skydome}
|
Draw Skydome: #{@draw_skydome}
|
||||||
Debug mode: <c=992200>#{$debug}</c>
|
Debug mode: <c=992200>#{$debug}</c>
|
||||||
@@ -195,7 +201,7 @@ eos
|
|||||||
@demo_last_written_index = @demo_index
|
@demo_last_written_index = @demo_index
|
||||||
@demo_file.puts("tick #{@demo_index}")
|
@demo_file.puts("tick #{@demo_index}")
|
||||||
end
|
end
|
||||||
@demo_file.puts("down #{id}")
|
@demo_file.puts("down #{InputMapper.action(id)}")
|
||||||
@demo_changed = true
|
@demo_changed = true
|
||||||
end
|
end
|
||||||
InputMapper.keydown(id)
|
InputMapper.keydown(id)
|
||||||
@@ -211,7 +217,7 @@ eos
|
|||||||
@demo_last_written_index = @demo_index
|
@demo_last_written_index = @demo_index
|
||||||
@demo_file.puts("tick #{@demo_index}")
|
@demo_file.puts("tick #{@demo_index}")
|
||||||
end
|
end
|
||||||
@demo_file.puts("up #{id}")
|
@demo_file.puts("up #{InputMapper.action(id)}")
|
||||||
@demo_changed = true
|
@demo_changed = true
|
||||||
end
|
end
|
||||||
InputMapper.keyup(id)
|
InputMapper.keyup(id)
|
||||||
|
|||||||
@@ -24,15 +24,15 @@ class IMICFPS
|
|||||||
fill_quad(
|
fill_quad(
|
||||||
0, i*@size,
|
0, i*@size,
|
||||||
0, @slope+(i*@size),
|
0, @slope+(i*@size),
|
||||||
$window.width/2, (-@slope)+(i*@size),
|
window.width/2, (-@slope)+(i*@size),
|
||||||
$window.width/2, i*@size,
|
window.width/2, i*@size,
|
||||||
Gosu::Color.rgba(@base_color.red-i*@color_step, @base_color.green-i*@color_step, @base_color.blue-i*@color_step, 200)
|
Gosu::Color.rgba(@base_color.red-i*@color_step, @base_color.green-i*@color_step, @base_color.blue-i*@color_step, 200)
|
||||||
)
|
)
|
||||||
fill_quad(
|
fill_quad(
|
||||||
$window.width, i*@size,
|
window.width, i*@size,
|
||||||
$window.width, @slope+(i*@size),
|
window.width, @slope+(i*@size),
|
||||||
$window.width/2, (-@slope)+(i*@size),
|
window.width/2, (-@slope)+(i*@size),
|
||||||
$window.width/2, i*@size,
|
window.width/2, i*@size,
|
||||||
Gosu::Color.rgba(@base_color.red-i*@color_step, @base_color.green-i*@color_step, @base_color.blue-i*@color_step, 200)
|
Gosu::Color.rgba(@base_color.red-i*@color_step, @base_color.green-i*@color_step, @base_color.blue-i*@color_step, 200)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
@@ -42,8 +42,8 @@ class IMICFPS
|
|||||||
|
|
||||||
# Box
|
# Box
|
||||||
draw_rect(
|
draw_rect(
|
||||||
$window.width/4, 0,
|
window.width/4, 0,
|
||||||
$window.width/2, $window.height,
|
window.width/2, window.height,
|
||||||
Gosu::Color.rgba(0, 0, 0, 150)
|
Gosu::Color.rgba(0, 0, 0, 150)
|
||||||
# Gosu::Color.rgba(@base_color.red+@color_step, @base_color.green+@color_step, @base_color.blue+@color_step, 200)
|
# Gosu::Color.rgba(@base_color.red+@color_step, @base_color.green+@color_step, @base_color.blue+@color_step, 200)
|
||||||
)
|
)
|
||||||
@@ -80,7 +80,7 @@ class IMICFPS
|
|||||||
end
|
end
|
||||||
|
|
||||||
def button_up(id)
|
def button_up(id)
|
||||||
$window.close if id == Gosu::KbEscape
|
window.close if id == Gosu::KbEscape
|
||||||
if Gosu::MsLeft
|
if Gosu::MsLeft
|
||||||
@elements.each do |e|
|
@elements.each do |e|
|
||||||
next unless e.is_a?(Link)
|
next unless e.is_a?(Link)
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ class IMICFPS
|
|||||||
class Wavefront
|
class Wavefront
|
||||||
class Model
|
class Model
|
||||||
include OpenGL
|
include OpenGL
|
||||||
# include GLU
|
include CommonMethods
|
||||||
|
|
||||||
include Parser
|
include Parser
|
||||||
|
|
||||||
@@ -50,7 +50,7 @@ class IMICFPS
|
|||||||
@objects.each_with_index do |o, i|
|
@objects.each_with_index do |o, i|
|
||||||
puts " Model::Object Name: #{o.name}, Vertices: #{o.vertices.size}" if $debug
|
puts " Model::Object Name: #{o.name}, Vertices: #{o.vertices.size}" if $debug
|
||||||
end
|
end
|
||||||
$window.number_of_vertices+=@vertex_count
|
window.number_of_vertices+=@vertex_count
|
||||||
@model_has_texture = false
|
@model_has_texture = false
|
||||||
@materials.each do |key, material|
|
@materials.each do |key, material|
|
||||||
if material.texture_id
|
if material.texture_id
|
||||||
|
|||||||
Reference in New Issue
Block a user