mirror of
https://github.com/cyberarm/i-mic-fps.git
synced 2025-12-15 15:42:35 +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/light"
|
||||
|
||||
require_relative "lib/objects/entities/camera"
|
||||
require_relative "lib/objects/camera"
|
||||
require_relative "lib/objects/entities/player"
|
||||
require_relative "lib/objects/entities/tree"
|
||||
require_relative "lib/objects/entities/skydome"
|
||||
|
||||
@@ -10,15 +10,15 @@ class IMICFPS
|
||||
def delta_time
|
||||
(Gosu.milliseconds-@delta_time)/1000.0
|
||||
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_y; $window.mouse_y; end
|
||||
def mouse_x=int; $window.mouse_x=int; end
|
||||
def mouse_y=int; $window.mouse_y=int; end
|
||||
def mouse_x; window.mouse_x; end
|
||||
def mouse_y; window.mouse_y; end
|
||||
def mouse_x=int; window.mouse_x=int; end
|
||||
def mouse_y=int; window.mouse_y=int; end
|
||||
|
||||
def gl(&block)
|
||||
$window.gl do
|
||||
window.gl do
|
||||
block.call
|
||||
end
|
||||
end
|
||||
@@ -32,13 +32,13 @@ class IMICFPS
|
||||
end
|
||||
|
||||
def draw_rect(*args)
|
||||
$window.draw_rect(*args)
|
||||
window.draw_rect(*args)
|
||||
end
|
||||
def draw_quad(*args)
|
||||
$window.draw_quad(*args)
|
||||
window.draw_quad(*args)
|
||||
end
|
||||
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
|
||||
|
||||
@@ -3,32 +3,57 @@ class IMICFPS
|
||||
@@keymap = {}
|
||||
@@keys = Hash.new(false)
|
||||
|
||||
def self.keydown(id)
|
||||
@@keys[id] = true
|
||||
def self.keydown(id_or_action)
|
||||
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
|
||||
|
||||
def self.keyup(id)
|
||||
@@keys[id] = false
|
||||
def self.keyup(id_or_action)
|
||||
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
|
||||
|
||||
def self.get(category, action)
|
||||
key = @@keymap.dig(category, action)
|
||||
def self.get(action)
|
||||
key = @@keymap.dig(action)
|
||||
end
|
||||
|
||||
def self.set(category, action, key)
|
||||
raise "category must be a symbol" unless category.is_a?(Symbol)
|
||||
def self.set(action, key)
|
||||
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(:#{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[category][action] = key
|
||||
@@keymap[action] = key
|
||||
end
|
||||
|
||||
def self.down?(category, action)
|
||||
keys = get(category, action)
|
||||
def self.down?(action)
|
||||
keys = get(action)
|
||||
|
||||
if keys.is_a?(Array)
|
||||
keys.detect do |key|
|
||||
@@ -39,16 +64,60 @@ class IMICFPS
|
||||
end
|
||||
end
|
||||
|
||||
def self.is?(category, action, query_key)
|
||||
keys = get(category, action)
|
||||
def self.is?(action, query_key)
|
||||
keys = @@keymap.dig(action)
|
||||
|
||||
if keys.is_a?(Array)
|
||||
keys.detect do |key|
|
||||
query_key == key
|
||||
end
|
||||
keys.include?(query_key)
|
||||
else
|
||||
query_key == keys
|
||||
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
|
||||
|
||||
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_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)
|
||||
@pitch = 0.0
|
||||
@yaw = 0.0
|
||||
@@ -19,26 +19,15 @@ class IMICFPS
|
||||
@distance = 4
|
||||
@origin_distance = @distance
|
||||
|
||||
self.mouse_x, self.mouse_y = $window.width/2, $window.height/2
|
||||
@true_mouse = Point.new($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)
|
||||
@mouse_sensitivity = 20.0 # Less is faster, more is slower
|
||||
@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, :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
|
||||
|
||||
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
|
||||
end
|
||||
|
||||
@@ -74,8 +63,7 @@ class IMICFPS
|
||||
@position.y = @entity.position.y + 2
|
||||
@position.z = @entity.position.z - z_offset
|
||||
|
||||
# @yaw = 180 - @entity.y_rotation
|
||||
@entity.rotation.y = -@yaw + 180
|
||||
@yaw = 180 - @entity.rotation.y
|
||||
end
|
||||
|
||||
def draw
|
||||
@@ -83,7 +71,7 @@ class IMICFPS
|
||||
glMatrixMode(GL_PROJECTION) # The projection matrix is responsible for adding perspective to our scene.
|
||||
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
|
||||
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)
|
||||
glRotatef(@pitch,1,0,0)
|
||||
glRotatef(@yaw,0,1,0)
|
||||
@@ -102,7 +90,6 @@ class IMICFPS
|
||||
|
||||
def update
|
||||
if @mouse_captured
|
||||
position_camera if @entity
|
||||
|
||||
delta = Float(@true_mouse.x-self.mouse_x)/(@mouse_sensitivity*@field_of_view)*70
|
||||
@yaw -= delta
|
||||
@@ -113,9 +100,10 @@ class IMICFPS
|
||||
|
||||
@entity.rotation.y += delta if @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_y = $window.height/2 if self.mouse_y <= 1 || $window.mouse_y >= $window.height-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
|
||||
@true_mouse.x, @true_mouse.y = self.mouse_x, self.mouse_y
|
||||
end
|
||||
end
|
||||
@@ -124,62 +112,59 @@ class IMICFPS
|
||||
relative_y_rotation = (@yaw + 180)
|
||||
relative_speed = 0.5
|
||||
|
||||
if InputMapper.down?(:character, :forward)
|
||||
if InputMapper.down?( :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 InputMapper.down?(:character, :backward)
|
||||
if InputMapper.down?(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 InputMapper.down?(:character, :strife_left)
|
||||
if InputMapper.down?(: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 InputMapper.down?(:character, :strife_right)
|
||||
if InputMapper.down?(: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 InputMapper.down?(:camera, :ascend)
|
||||
if InputMapper.down?(:ascend)
|
||||
@y+=relative_speed
|
||||
end
|
||||
if InputMapper.down?(:camera, :descend)
|
||||
if InputMapper.down?(:descend)
|
||||
@y-=relative_speed
|
||||
end
|
||||
end
|
||||
|
||||
def button_up(id)
|
||||
if InputMapper.is?(:camera, :release_mouse, id)
|
||||
if InputMapper.is?(:release_mouse, id)
|
||||
@mouse_captured = false
|
||||
$window.needs_cursor = true
|
||||
elsif InputMapper.is?(:camera, :capture_mouse, id)
|
||||
window.needs_cursor = true
|
||||
elsif InputMapper.is?(:capture_mouse, id)
|
||||
@mouse_captured = true
|
||||
$window.needs_cursor = false
|
||||
elsif InputMapper.is?(:camera, :increase_mouse_sensitivity, id)
|
||||
window.needs_cursor = false
|
||||
elsif InputMapper.is?(:increase_mouse_sensitivity, id)
|
||||
@mouse_sensitivity+=1
|
||||
@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 = @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
|
||||
elsif InputMapper.is?(:camera, :increase_view_distance, id)
|
||||
elsif InputMapper.is?(: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)
|
||||
elsif InputMapper.is?(:camera, :decrease_view_distance, id)
|
||||
elsif InputMapper.is?(:decrease_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)
|
||||
elsif InputMapper.is?(:camera, :turn_180, id)
|
||||
@rotation.y = @rotation.y+180
|
||||
@rotation.y %= 360
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -8,16 +8,6 @@ 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, :toggle_first_person_view, Gosu::KbF)
|
||||
|
||||
@speed = 2.5 # meter's per second
|
||||
@running_speed = 6.8 # meter's per second
|
||||
@@ -98,7 +88,7 @@ class IMICFPS
|
||||
|
||||
def update
|
||||
relative_speed = @speed
|
||||
if InputMapper.down?(:character, :sprint)
|
||||
if InputMapper.down?(:sprint)
|
||||
relative_speed = (@running_speed)*(delta_time)
|
||||
else
|
||||
relative_speed = @speed*(delta_time)
|
||||
@@ -106,27 +96,27 @@ class IMICFPS
|
||||
|
||||
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.x-=Math.sin(relative_y_rotation * Math::PI / 180)*relative_speed
|
||||
end
|
||||
if InputMapper.down?(:character, :backward)
|
||||
if InputMapper.down?(:backward)
|
||||
@position.z-=Math.cos(relative_y_rotation * Math::PI / 180)*relative_speed
|
||||
@position.x+=Math.sin(relative_y_rotation * Math::PI / 180)*relative_speed
|
||||
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.x+=Math.cos(relative_y_rotation * Math::PI / 180)*relative_speed
|
||||
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.x-=Math.cos(relative_y_rotation * Math::PI / 180)*relative_speed
|
||||
end
|
||||
|
||||
if InputMapper.down?(:character, :turn_left)
|
||||
if InputMapper.down?(:turn_left)
|
||||
@rotation.y+=(relative_speed*1000)*delta_time
|
||||
end
|
||||
if InputMapper.down?(:character, :turn_right)
|
||||
if InputMapper.down?(:turn_right)
|
||||
@rotation.y-=(relative_speed*1000)*delta_time
|
||||
end
|
||||
|
||||
@@ -135,7 +125,7 @@ class IMICFPS
|
||||
@velocity.y-=(IMICFPS::GRAVITY*air_time)*delta_time
|
||||
end
|
||||
|
||||
if InputMapper.down?(:character, :jump) && !@jumping
|
||||
if InputMapper.down?(:jump) && !@jumping
|
||||
@jumping = true
|
||||
@_time_in_air = Gosu.milliseconds
|
||||
elsif !@jumping && @position.y > @floor
|
||||
@@ -149,7 +139,7 @@ class IMICFPS
|
||||
end
|
||||
end
|
||||
if @jumping && !@falling
|
||||
if InputMapper.down?(:character, :jump)
|
||||
if InputMapper.down?(:jump)
|
||||
@velocity.y = 1.5
|
||||
@falling = true
|
||||
end
|
||||
@@ -161,9 +151,13 @@ class IMICFPS
|
||||
end
|
||||
|
||||
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
|
||||
@visible = !@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
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
class Text
|
||||
include IMICFPS::CommonMethods
|
||||
CACHE = {}
|
||||
|
||||
attr_accessor :text, :x, :y, :z, :size, :factor_x, :factor_y, :color, :shadow, :shadow_size, :options
|
||||
@@ -29,9 +30,9 @@ class Text
|
||||
when :left
|
||||
@x = 0+BUTTON_PADDING
|
||||
when :center
|
||||
@x = ($window.width/2)-(@textobject.text_width(@text)/2)
|
||||
@x = (window.width/2)-(@textobject.text_width(@text)/2)
|
||||
when :right
|
||||
@x = $window.width-BUTTON_PADDING-@textobject.text_width(@text)
|
||||
@x = window.width-BUTTON_PADDING-@textobject.text_width(@text)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
class IMICFPS
|
||||
class OpenGLRenderer
|
||||
include CommonMethods
|
||||
include OpenGL
|
||||
include GLU
|
||||
|
||||
@@ -76,7 +77,7 @@ class IMICFPS
|
||||
glLineWidth(3)
|
||||
|
||||
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)
|
||||
glPolygonOffset(0, 0)
|
||||
@@ -84,10 +85,10 @@ class IMICFPS
|
||||
glEnable(GL_LIGHTING)
|
||||
|
||||
glDrawArrays(GL_TRIANGLES, 0, o.flattened_vertices_size/4)
|
||||
$window.number_of_vertices+=model.vertices.size
|
||||
window.number_of_vertices+=model.vertices.size
|
||||
else
|
||||
glDrawArrays(GL_TRIANGLES, 0, o.flattened_vertices_size/4)
|
||||
$window.number_of_vertices+=model.vertices.size
|
||||
window.number_of_vertices+=model.vertices.size
|
||||
end
|
||||
|
||||
# glBindBuffer(GL_ARRAY_BUFFER, 0)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
class IMICFPS
|
||||
class Renderer
|
||||
include CommonMethods
|
||||
include OpenGL
|
||||
include GLU
|
||||
|
||||
@@ -23,7 +24,7 @@ class IMICFPS
|
||||
end
|
||||
|
||||
@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
|
||||
end
|
||||
|
||||
|
||||
@@ -77,8 +77,8 @@ class IMICFPS
|
||||
end
|
||||
|
||||
# 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_thickness/2, $window.height/2-(@crosshair_size*2), @crosshair_thickness, @crosshair_size*2, @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)
|
||||
|
||||
@text.draw
|
||||
end
|
||||
@@ -94,10 +94,6 @@ class IMICFPS
|
||||
|
||||
@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 @demo_data[@demo_index]&.start_with?("tick")
|
||||
if @demo_tick == @demo_data[@demo_index].split(" ").last.to_i
|
||||
@@ -108,12 +104,18 @@ class IMICFPS
|
||||
|
||||
data = @demo_data[@demo_index].split(" ")
|
||||
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"
|
||||
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"
|
||||
@camera.pitch = data[1].to_f
|
||||
@camera.yaw = data[2].to_f
|
||||
@player.rotation.y = (data[2].to_f * -1) - 180
|
||||
else
|
||||
# hmm
|
||||
end
|
||||
@@ -141,6 +143,10 @@ class IMICFPS
|
||||
end
|
||||
|
||||
@demo_tick += 1 if @demo_tick
|
||||
|
||||
window.close if window.button_down?(Gosu::KbEscape)
|
||||
window.number_of_vertices = 0
|
||||
@delta_time = Gosu.milliseconds
|
||||
end
|
||||
|
||||
def update_text
|
||||
@@ -158,8 +164,8 @@ Field Of View: #{@camera.field_of_view}
|
||||
Mouse Sesitivity: #{@camera.mouse_sensitivity}
|
||||
Last Frame: #{delta_time*1000.0}ms (#{Gosu.fps} fps)
|
||||
|
||||
Vertices: #{formatted_number($window.number_of_vertices)}
|
||||
Faces: #{formatted_number($window.number_of_vertices/3)}
|
||||
Vertices: #{formatted_number(window.number_of_vertices)}
|
||||
Faces: #{formatted_number(window.number_of_vertices/3)}
|
||||
|
||||
Draw Skydome: #{@draw_skydome}
|
||||
Debug mode: <c=992200>#{$debug}</c>
|
||||
@@ -175,8 +181,8 @@ Field Of View: #{@camera.field_of_view}
|
||||
Mouse Sesitivity: #{@camera.mouse_sensitivity}
|
||||
Last Frame: #{delta_time*1000.0}ms (#{Gosu.fps} fps)
|
||||
|
||||
Vertices: #{formatted_number($window.number_of_vertices)}
|
||||
Faces: #{formatted_number($window.number_of_vertices/3)}
|
||||
Vertices: #{formatted_number(window.number_of_vertices)}
|
||||
Faces: #{formatted_number(window.number_of_vertices/3)}
|
||||
|
||||
Draw Skydome: #{@draw_skydome}
|
||||
Debug mode: <c=992200>#{$debug}</c>
|
||||
@@ -195,7 +201,7 @@ eos
|
||||
@demo_last_written_index = @demo_index
|
||||
@demo_file.puts("tick #{@demo_index}")
|
||||
end
|
||||
@demo_file.puts("down #{id}")
|
||||
@demo_file.puts("down #{InputMapper.action(id)}")
|
||||
@demo_changed = true
|
||||
end
|
||||
InputMapper.keydown(id)
|
||||
@@ -211,7 +217,7 @@ eos
|
||||
@demo_last_written_index = @demo_index
|
||||
@demo_file.puts("tick #{@demo_index}")
|
||||
end
|
||||
@demo_file.puts("up #{id}")
|
||||
@demo_file.puts("up #{InputMapper.action(id)}")
|
||||
@demo_changed = true
|
||||
end
|
||||
InputMapper.keyup(id)
|
||||
|
||||
@@ -24,15 +24,15 @@ class IMICFPS
|
||||
fill_quad(
|
||||
0, i*@size,
|
||||
0, @slope+(i*@size),
|
||||
$window.width/2, (-@slope)+(i*@size),
|
||||
$window.width/2, i*@size,
|
||||
window.width/2, (-@slope)+(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)
|
||||
)
|
||||
fill_quad(
|
||||
$window.width, i*@size,
|
||||
$window.width, @slope+(i*@size),
|
||||
$window.width/2, (-@slope)+(i*@size),
|
||||
$window.width/2, i*@size,
|
||||
window.width, i*@size,
|
||||
window.width, @slope+(i*@size),
|
||||
window.width/2, (-@slope)+(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)
|
||||
)
|
||||
end
|
||||
@@ -42,8 +42,8 @@ class IMICFPS
|
||||
|
||||
# Box
|
||||
draw_rect(
|
||||
$window.width/4, 0,
|
||||
$window.width/2, $window.height,
|
||||
window.width/4, 0,
|
||||
window.width/2, window.height,
|
||||
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)
|
||||
)
|
||||
@@ -80,7 +80,7 @@ class IMICFPS
|
||||
end
|
||||
|
||||
def button_up(id)
|
||||
$window.close if id == Gosu::KbEscape
|
||||
window.close if id == Gosu::KbEscape
|
||||
if Gosu::MsLeft
|
||||
@elements.each do |e|
|
||||
next unless e.is_a?(Link)
|
||||
|
||||
@@ -6,7 +6,7 @@ class IMICFPS
|
||||
class Wavefront
|
||||
class Model
|
||||
include OpenGL
|
||||
# include GLU
|
||||
include CommonMethods
|
||||
|
||||
include Parser
|
||||
|
||||
@@ -50,7 +50,7 @@ class IMICFPS
|
||||
@objects.each_with_index do |o, i|
|
||||
puts " Model::Object Name: #{o.name}, Vertices: #{o.vertices.size}" if $debug
|
||||
end
|
||||
$window.number_of_vertices+=@vertex_count
|
||||
window.number_of_vertices+=@vertex_count
|
||||
@model_has_texture = false
|
||||
@materials.each do |key, material|
|
||||
if material.texture_id
|
||||
|
||||
Reference in New Issue
Block a user