Sha256: 3304e20f60e01eb6c846a9461abceedb7144c9ac261dac2eff786316f2d6a4d4

Contents?: true

Size: 530 Bytes

Versions: 2

Compression:

Stored size: 530 Bytes

Contents

module Lotu
  module Collidable

    def self.extended(instance)
      instance.init_behavior
    end

    def init_behavior
      @collision_tag = nil
    end

    def collides_as(tag)
      @collision_tag = tag
      @parent.systems[CollisionSystem].add_entity(self, tag)
    end

    def collides_with(other)
      Gosu.distance(@x, @y, other.x, other.y) < @collision_radius + other.collision_radius
    end

    def die
      super
      @parent.systems[CollisionSystem].remove_entity(self, @collision_tag)
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
lotu-0.1.10 lib/lotu/behaviors/collidable.rb
lotu-0.1.9 lib/lotu/behaviors/collidable.rb