Refactored GameObject to Entity, replaced @x,@y,@z with @position, added @velocity vector to Entity, bricked Player terrain interaction while authoring Axis Aligned Bounding Box Tree for CollisionManager to handle all collision interaction. Added PhysicsManager stub.

This commit is contained in:
2019-02-20 10:49:56 -06:00
parent df05ec5150
commit 7b903fbdb9
27 changed files with 288 additions and 385 deletions

View File

@@ -2,25 +2,33 @@ class IMICFPS
class CollisionManager
def initialize(game_state:)
@game_state = game_state
# @aabb_tree = AABBTree.new
@aabb_tree = AABBTree.new
end
def add(entity)
@aabb_tree.add(entity.normalized_bounding_box, entity)
end
def remove(entity)
@aabb_tree.remove(entity)
end
def lazy_check_collisions
# Expensive AABB collision detection
@game_state.game_objects.each do |object|
@game_state.game_objects.each do |b|
next if object == b
next if object.is_a?(Terrain) || b.is_a?(Terrain)
@game_state.entities.each do |entity|
@game_state.entities.each do |other|
next if entity == other
next if entity.is_a?(Terrain) || other.is_a?(Terrain)
if object.intersect(object, b)
object.debug_color = Color.new(1.0,0.0,0.0)
b.debug_color = Color.new(1.0,0.0,0.0)
if entity.intersect(other)
entity.debug_color = Color.new(1.0,0.0,0.0)
other.debug_color = Color.new(1.0,0.0,0.0)
# @game_state.game_objects.delete(object) unless object.is_a?(Player)
# puts "#{object} is intersecting #{b}" if object.is_a?(Player)
# @game_state.entities.delete(entity) unless entity.is_a?(Player)
# puts "#{entity} is intersecting #{b}" if entity.is_a?(Player)
else
object.debug_color = Color.new(0,1,0)
b.debug_color = Color.new(0,1,0)
entity.debug_color = Color.new(0,1,0)
other.debug_color = Color.new(0,1,0)
end
end
end

View File

@@ -0,0 +1,28 @@
class IMICFPS
TextureCoordinate = Struct.new(:u, :v, :weight)
Point = Struct.new(:x, :y)
Color = Struct.new(:red, :green, :blue, :alpha)
module EntityManager # Get included into GameState context
def add_entity(entity)
@collision_manager.add(entity) if entity.collidable?
@entities << entity
end
def find_entity(entity)
@entities.detect {|entity| entity == entity}
end
def remove_entity(entity)
ent = @entities.detect {|entity| entity == entity}
if ent
@collision_manager.remove(entity)
@entities.delete(ent)
end
end
def entities
@entities
end
end
end

View File

@@ -1,22 +0,0 @@
class IMICFPS
TextureCoordinate = Struct.new(:u, :v, :weight)
Vertex = Struct.new(:x, :y, :z, :weight)
Point = Struct.new(:x, :y)
Color = Struct.new(:red, :green, :blue, :alpha)
module ObjectManager # Get included into GameState context
def add_object(model)
@game_objects << model
end
def find_object()
end
def remove_object()
end
def game_objects
@game_objects
end
end
end

View File

@@ -0,0 +1,4 @@
class IMICFPS
class PhysicsManager
end
end