Sha256: 56e7b28b957f9067c811b6698d345016a9f410d709e4d0c2c25018258a5947c0

Contents?: true

Size: 771 Bytes

Versions: 4

Compression:

Stored size: 771 Bytes

Contents

require 'behavior'

class Collidable < Behavior

  attr_accessor :shape, :radius, :width

  def setup
    @shape = opts[:shape]
    @radius = opts[:radius]
    @width = opts[:width]

    collidable_obj = self

    @actor.instance_eval do
      (class << self; self; end).class_eval do
        define_method :shape do |*args|
          collidable_obj.shape *args
        end
        define_method :radius do |*args|
          collidable_obj.radius *args
        end
      end
    end

    register_actor
  end

  def register_actor
    @actor.stage.register_collidable @actor
  end

  def bounding_box
    [ @actor.x-@width,@actor.y-@width,
      @actor.x+@width,@actor.y+@width ]
  end

  def bounding_circle
    [ @actor.x+@radius, @actor.y+@radius, @radius]
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
gamebox-0.1.1 lib/gamebox/behaviors/collidable.rb
gamebox-0.1.0 lib/gamebox/behaviors/collidable.rb
gamebox-0.0.9 lib/gamebox/behaviors/collidable.rb
gamebox-0.0.8 lib/gamebox/behaviors/collidable.rb