Sha256: 07b9be19596ae248186abb077502fe64b9ba31f87e1c1bd038dfabce34f19260

Contents?: true

Size: 809 Bytes

Versions: 12

Compression:

Stored size: 809 Bytes

Contents

#
#
module Turnable extend Trait
  
  Left  = :turn_left
  Right = :turn_right
  
  def self.included base
    base.extend ClassMethods
  end
  
  # Defines a turn_speed method on the class.
  #
  # Calling it will define a turn_speed method on the instance
  # that lets the thing rotate with the given frequency.
  #
  module ClassMethods
    def turn_speed amount
      amount = amount.to_f / 2
      define_method :turn_speed do
        amount
      end
    end
  end
  
  #
  #
  def turn_speed
    0.5 # Default turn speed
  end
  
  # Turns the thing left, depending on turn speed.
  #
  def turn_left
    self.rotation -= self.turn_speed / (SUBSTEPS**2)
  end
  
  # Turns the thing right, depending on turn speed.
  #
  def turn_right
    self.rotation += self.turn_speed / (SUBSTEPS**2)
  end
  
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
gosu_extensions-0.1.26 lib/traits/turnable.rb
gosu_extensions-0.1.25 lib/traits/turnable.rb
gosu_extensions-0.1.24 lib/traits/turnable.rb
gosu_extensions-0.1.23 lib/traits/turnable.rb
gosu_extensions-0.1.22 lib/traits/turnable.rb
gosu_extensions-0.1.21 lib/traits/turnable.rb
gosu_extensions-0.1.20 lib/traits/turnable.rb
gosu_extensions-0.1.19 lib/traits/turnable.rb
gosu_extensions-0.1.18 lib/traits/turnable.rb
gosu_extensions-0.1.17 lib/traits/turnable.rb
gosu_extensions-0.1.16 lib/traits/turnable.rb
gosu_extensions-0.1.15 lib/traits/turnable.rb