Sha256: 0d885cf55ab5be85dc20cc9f40ea286bdee6cc99ea7935cd9391816da2c7bd1f
Contents?: true
Size: 820 Bytes
Versions: 1
Compression:
Stored size: 820 Bytes
Contents
module Lotu class CollisionSystem < System 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.15 | lib/lotu/systems/collision_system.rb |