mirror of
https://github.com/cyberarm/i-mic-fps.git
synced 2025-12-15 15:42:35 +00:00
Add collision manager...
This commit is contained in:
34
lib/managers/collision_manager.rb
Normal file
34
lib/managers/collision_manager.rb
Normal file
@@ -0,0 +1,34 @@
|
||||
class IMICFPS
|
||||
class CollisionManager
|
||||
def initialize(game_state:)
|
||||
@game_state = game_state
|
||||
# @aabb_tree = AABBTree.new
|
||||
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)
|
||||
|
||||
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)
|
||||
|
||||
@game_state.game_objects.delete(object) unless object.is_a?(Player)
|
||||
puts "#{object} is intersecting #{b}" if object.is_a?(Player)
|
||||
else
|
||||
object.debug_color = Color.new(0,1,0)
|
||||
b.debug_color = Color.new(0,1,0)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
lazy_check_collisions
|
||||
# @aabb_tree.rebuild
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user