Class: Lotu::CollisionSystem
- Inherits:
-
Object
- Object
- Lotu::CollisionSystem
- Defined in:
- lib/lotu/systems/collision_system.rb
Defined Under Namespace
Modules: UserMethods
Instance Method Summary collapse
- #add_entity(obj, tag) ⇒ Object
- #draw ⇒ Object
-
#initialize(user, opts = {}) ⇒ CollisionSystem
constructor
A new instance of CollisionSystem.
- #remove_entity(obj, tag) ⇒ Object
- #update ⇒ Object
- #when_colliding(type1, type2, &blk) ⇒ Object
Constructor Details
#initialize(user, opts = {}) ⇒ CollisionSystem
Returns a new instance of CollisionSystem.
4 5 6 7 8 |
# File 'lib/lotu/systems/collision_system.rb', line 4 def initialize(user, opts={}) user.extend UserMethods @entities = Hash.new{ |h,k| h[k] = [] } @actions = {} end |
Instance Method Details
#add_entity(obj, tag) ⇒ Object
10 11 12 |
# File 'lib/lotu/systems/collision_system.rb', line 10 def add_entity(obj, tag) @entities[tag] << obj end |
#draw ⇒ Object
32 |
# File 'lib/lotu/systems/collision_system.rb', line 32 def draw;end |
#remove_entity(obj, tag) ⇒ Object
14 15 16 |
# File 'lib/lotu/systems/collision_system.rb', line 14 def remove_entity(obj, tag) @entities[tag].delete(obj) end |
#update ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'lib/lotu/systems/collision_system.rb', line 22 def update @actions.each do |, blk| @entities[[0]].each do |ent1| @entities[[1]].each do |ent2| blk.call(ent1, ent2) if ent1.collides_with(ent2) end end end end |
#when_colliding(type1, type2, &blk) ⇒ Object
18 19 20 |
# File 'lib/lotu/systems/collision_system.rb', line 18 def when_colliding(type1, type2, &blk) @actions[[type1, type2]] = blk end |