Sha256: f4badec406d27831fae0af00eddb4ba33ae0209020ae0ca664420e690d25a2e5
Contents?: true
Size: 824 Bytes
Versions: 1
Compression:
Stored size: 824 Bytes
Contents
module Lotu class CollisionSystem < BaseSystem def initialize(user, opts={}) super @user.extend UserMethods @entities = Hash.new{ |h,k| h[k] = [] } @actions = {} end def add_entity(obj, tag) @entities[tag] << obj end def remove_entity(obj, tag) @entities[tag].delete(obj) end def when_colliding(type1, type2, &blk) @actions[[type1, type2]] = blk end 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 module UserMethods def when_colliding(*args, &blk) systems[CollisionSystem].when_colliding(*args, &blk) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
lotu-0.1.16 | lib/lotu/systems/collision_system.rb |