diff --git a/assets/base/biped/manifest.yaml b/assets/base/biped/manifest.yaml index 673f41e..2623f9a 100644 --- a/assets/base/biped/manifest.yaml +++ b/assets/base/biped/manifest.yaml @@ -1,4 +1,6 @@ name: "biped" model: "biped.obj" collision: "mesh" -collision_mesh: null \ No newline at end of file +collision_mesh: null +collision_resolution: "dynamic" +physics: true \ No newline at end of file diff --git a/assets/base/randomish_terrain/manifest.yaml b/assets/base/randomish_terrain/manifest.yaml index 295387d..c01154d 100644 --- a/assets/base/randomish_terrain/manifest.yaml +++ b/assets/base/randomish_terrain/manifest.yaml @@ -1,2 +1,3 @@ name: "randomish_terrain" -model: "randomish_terrain.obj" \ No newline at end of file +model: "randomish_terrain.obj" +collision: "mesh" \ No newline at end of file diff --git a/assets/base/river_terrain/manifest.yaml b/assets/base/river_terrain/manifest.yaml index 978b531..8c9d359 100644 --- a/assets/base/river_terrain/manifest.yaml +++ b/assets/base/river_terrain/manifest.yaml @@ -1,2 +1,3 @@ name: "river_terrain" model: "river_terrain.obj" +collision: "mesh" diff --git a/lib/game_objects/entities/player.rb b/lib/game_objects/entities/player.rb index aed9ba5..7984924 100644 --- a/lib/game_objects/entities/player.rb +++ b/lib/game_objects/entities/player.rb @@ -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 diff --git a/lib/game_objects/entity.rb b/lib/game_objects/entity.rb index fadcf3e..0e25911 100644 --- a/lib/game_objects/entity.rb +++ b/lib/game_objects/entity.rb @@ -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 diff --git a/lib/managers/collision_manager.rb b/lib/managers/collision_manager.rb index 58dc43d..1359953 100644 --- a/lib/managers/collision_manager.rb +++ b/lib/managers/collision_manager.rb @@ -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 diff --git a/lib/managers/entity_manager.rb b/lib/managers/entity_manager.rb index aefbbe4..d7fc47b 100644 --- a/lib/managers/entity_manager.rb +++ b/lib/managers/entity_manager.rb @@ -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 diff --git a/lib/managers/physics_manager.rb b/lib/managers/physics_manager.rb index 671783b..4a244a8 100644 --- a/lib/managers/physics_manager.rb +++ b/lib/managers/physics_manager.rb @@ -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 diff --git a/lib/manifest.rb b/lib/manifest.rb index a78780e..224f279 100644 --- a/lib/manifest.rb +++ b/lib/manifest.rb @@ -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 diff --git a/lib/states/game_states/loading_state.rb b/lib/states/game_states/loading_state.rb index af7226f..d493ed2 100644 --- a/lib/states/game_states/loading_state.rb +++ b/lib/states/game_states/loading_state.rb @@ -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" diff --git a/lib/ui/console.rb b/lib/ui/console.rb index c82c518..c38a3d0 100644 --- a/lib/ui/console.rb +++ b/lib/ui/console.rb @@ -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 \ No newline at end of file diff --git a/lib/ui/menu.rb b/lib/ui/menu.rb index 9e26fe8..822d7be 100644 --- a/lib/ui/menu.rb +++ b/lib/ui/menu.rb @@ -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 diff --git a/lib/window.rb b/lib/window.rb index dfcf3fb..3894871 100644 --- a/lib/window.rb +++ b/lib/window.rb @@ -26,6 +26,10 @@ class IMICFPS @delta_time = Gosu.milliseconds end + def needs_cursor? + false + end + def draw super