Class: Lotu::CollisionSystem
- Inherits:
-
BaseSystem
- Object
- BaseSystem
- Lotu::CollisionSystem
- Defined in:
- lib/lotu/systems/collision_system.rb
Defined Under Namespace
Modules: UserMethods
Instance Method Summary collapse
- #add_entity(obj, tag) ⇒ Object
-
#initialize(user, opts = {}) ⇒ CollisionSystem
constructor
A new instance of CollisionSystem.
- #remove_entity(obj, tag) ⇒ Object
- #update ⇒ Object
- #when_colliding(type1, type2, &blk) ⇒ Object
Methods inherited from BaseSystem
Constructor Details
#initialize(user, opts = {}) ⇒ CollisionSystem
Returns a new instance of CollisionSystem.
4 5 6 7 8 9 |
# File 'lib/lotu/systems/collision_system.rb', line 4 def initialize(user, opts={}) super @user.extend UserMethods @entities = Hash.new{ |h,k| h[k] = [] } @actions = {} end |
Instance Method Details
#add_entity(obj, tag) ⇒ Object
11 12 13 |
# File 'lib/lotu/systems/collision_system.rb', line 11 def add_entity(obj, tag) @entities[tag] << obj end |
#remove_entity(obj, tag) ⇒ Object
15 16 17 |
# File 'lib/lotu/systems/collision_system.rb', line 15 def remove_entity(obj, tag) @entities[tag].delete(obj) end |
#update ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/lotu/systems/collision_system.rb', line 23 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, [0]) end end end end |
#when_colliding(type1, type2, &blk) ⇒ Object
19 20 21 |
# File 'lib/lotu/systems/collision_system.rb', line 19 def when_colliding(type1, type2, &blk) @actions[[type1, type2]] = blk end |