Class: Lotu::CollisionSystem

Inherits:
Object
  • Object
show all
Defined in:
lib/lotu/systems/collision_system.rb

Defined Under Namespace

Modules: UserMethods

Instance Method Summary collapse

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

#drawObject



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

#updateObject



22
23
24
25
26
27
28
29
30
# File 'lib/lotu/systems/collision_system.rb', line 22

def update
  @actions.each do |tags, blk|
    @entities[tags[0]].each do |ent1|
      @entities[tags[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