mirror of
https://github.com/cyberarm/i-mic-fps.git
synced 2025-12-15 15:42:35 +00:00
Moved collision/physics information into manifest, made real mouse cursor always invisible and use 'virtual' cursor when needed.
This commit is contained in:
@@ -2,3 +2,5 @@ name: "biped"
|
||||
model: "biped.obj"
|
||||
collision: "mesh"
|
||||
collision_mesh: null
|
||||
collision_resolution: "dynamic"
|
||||
physics: true
|
||||
@@ -1,2 +1,3 @@
|
||||
name: "randomish_terrain"
|
||||
model: "randomish_terrain.obj"
|
||||
collision: "mesh"
|
||||
@@ -1,2 +1,3 @@
|
||||
name: "river_terrain"
|
||||
model: "river_terrain.obj"
|
||||
collision: "mesh"
|
||||
|
||||
@@ -8,9 +8,6 @@ class IMICFPS
|
||||
|
||||
def setup
|
||||
bind_model
|
||||
@collision = :dynamic
|
||||
@physics = true
|
||||
|
||||
@speed = 2.5 # meter's per second
|
||||
@running_speed = 5.0 # meter's per second
|
||||
@turn_speed = 50.0
|
||||
|
||||
@@ -7,7 +7,7 @@ class IMICFPS
|
||||
|
||||
attr_accessor :scale, :visible, :renderable, :backface_culling
|
||||
attr_accessor :position, :orientation, :velocity
|
||||
attr_reader :name, :debug_color, :bounding_box, :collision, :physics, :mass, :drag, :camera
|
||||
attr_reader :name, :debug_color, :bounding_box, :drag, :camera, :manifest
|
||||
|
||||
def initialize(manifest:, map_entity: nil, spawnpoint: nil, backface_culling: true, auto_manage: true)
|
||||
@manifest = manifest
|
||||
@@ -27,14 +27,6 @@ class IMICFPS
|
||||
|
||||
@debug_color = Color.new(0.0, 1.0, 0.0)
|
||||
|
||||
@collidable = [:static, :dynamic]
|
||||
# :dynamic => moves in response,
|
||||
# :static => does not move ever,
|
||||
# :none => no collision check, entities can pass through
|
||||
@collision = :static
|
||||
@physics = @manifest.physics # Entity affected by gravity and what not
|
||||
@mass = 100 # kg
|
||||
|
||||
@last_position = Vector.new(@position.x, @position.y, @position.z)
|
||||
|
||||
@sandboxes = []
|
||||
@@ -61,7 +53,7 @@ class IMICFPS
|
||||
end
|
||||
|
||||
def collidable?
|
||||
@collidable.include?(@collision)
|
||||
@manifest.collision
|
||||
end
|
||||
|
||||
def bind_model
|
||||
|
||||
@@ -44,7 +44,7 @@ class IMICFPS
|
||||
|
||||
@map.entities.each do |entity|
|
||||
next unless entity.collidable?
|
||||
next if entity.collision == :static # Only dynamic entities can be resolved
|
||||
next if entity.manifest.collision_resolution == :static # Only dynamic entities can be resolved
|
||||
|
||||
search = @aabb_tree.search(entity.bounding_box)
|
||||
if search.size > 0
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
class IMICFPS
|
||||
module EntityManager # Get included into GameState context
|
||||
def add_entity(entity)
|
||||
@collision_manager.add(entity)# Add every entity to collision manager
|
||||
@collision_manager.add(entity) if entity.manifest.collision# Add every entity to collision manager
|
||||
Publisher.instance.publish(:create, nil, entity)
|
||||
@entities << entity
|
||||
end
|
||||
@@ -22,7 +22,7 @@ class IMICFPS
|
||||
def remove_entity(entity)
|
||||
ent = @entities.detect {|entity| entity == entity}
|
||||
if ent
|
||||
@collision_manager.remove(entity)
|
||||
@collision_manager.remove(entity) if entity.manifest.collision
|
||||
@publisher.publish(:destroy, nil, entity)
|
||||
@entities.delete(ent)
|
||||
end
|
||||
|
||||
@@ -31,7 +31,7 @@ class IMICFPS
|
||||
if on_ground
|
||||
entity.velocity.y = 0
|
||||
else
|
||||
entity.velocity.y -= @collision_manager.map.gravity * entity.delta_time if entity.physics
|
||||
entity.velocity.y -= @collision_manager.map.gravity * entity.delta_time if entity.manifest.physics
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
class IMICFPS
|
||||
class Manifest
|
||||
attr_reader :name, :model, :collision, :collision_mesh, :physics, :scripts, :uses
|
||||
attr_reader :name, :model, :collision, :collision_mesh, :collision_resolution, :physics, :scripts, :uses
|
||||
def initialize(manifest_file: nil, package: nil, name: nil)
|
||||
unless manifest_file
|
||||
raise "Entity package not specified!" unless package
|
||||
@@ -24,6 +24,7 @@ class IMICFPS
|
||||
# optional
|
||||
@collision = data["collision"] ? data["collision"] : nil
|
||||
@collision_mesh = data["collision_mesh"] ? data["collision_mesh"] : nil
|
||||
@collision_resolution = data["collision_resolution"] ? data["collision_resolution"].to_sym : :static
|
||||
@physics = data["physics"] ? data["physics"] : false
|
||||
@scripts = data["scripts"] ? parse_scripts(data["scripts"]) : []
|
||||
@uses = data["uses"] ? parse_dependencies(data["uses"]) : [] # List of entities that this Entity uses
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
class IMICFPS
|
||||
class LoadingState < Menu
|
||||
def setup
|
||||
window.needs_cursor = false
|
||||
@map_loader = MapLoader.new(map_file: @options[:map_file])
|
||||
|
||||
title "I-MIC FPS"
|
||||
|
||||
@@ -226,8 +226,8 @@ class IMICFPS
|
||||
@active_text_input = window.text_input
|
||||
window.text_input = @text_input
|
||||
|
||||
@showing_cursor = window.show_cursor
|
||||
window.show_cursor = true
|
||||
@showing_cursor = window.needs_cursor
|
||||
window.needs_cursor = true
|
||||
|
||||
@show_caret = true
|
||||
@caret_last_change = Gosu.milliseconds
|
||||
@@ -235,7 +235,7 @@ class IMICFPS
|
||||
|
||||
def blur
|
||||
window.text_input = @active_text_input
|
||||
window.show_cursor = @showing_cursor
|
||||
window.needs_cursor = @showing_cursor
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -6,6 +6,7 @@ class IMICFPS
|
||||
@slope = 250
|
||||
@color_step = 10
|
||||
@base_color = Gosu::Color.rgb(255, 127, 0)
|
||||
window.needs_cursor = true
|
||||
super(*args)
|
||||
end
|
||||
|
||||
@@ -55,13 +56,15 @@ class IMICFPS
|
||||
end
|
||||
|
||||
# Cursor
|
||||
fill_quad(
|
||||
mouse_x, mouse_y,
|
||||
mouse_x+16, mouse_y,
|
||||
mouse_x, mouse_y+16,
|
||||
mouse_x, mouse_y+16,
|
||||
Gosu::Color::WHITE, Float::INFINITY
|
||||
)
|
||||
if window.needs_cursor
|
||||
fill_quad(
|
||||
mouse_x, mouse_y,
|
||||
mouse_x+16, mouse_y,
|
||||
mouse_x, mouse_y+16,
|
||||
mouse_x, mouse_y+16,
|
||||
Gosu::Color::WHITE, Float::INFINITY
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
|
||||
@@ -26,6 +26,10 @@ class IMICFPS
|
||||
@delta_time = Gosu.milliseconds
|
||||
end
|
||||
|
||||
def needs_cursor?
|
||||
false
|
||||
end
|
||||
|
||||
def draw
|
||||
super
|
||||
|
||||
|
||||
Reference in New Issue
Block a user