Sha256: 413eabc32ba9eb099c5d13cf55831606a74f1f5bf2417a1996a2594a82b851ac

Contents?: true

Size: 1.18 KB

Versions: 9

Compression:

Stored size: 1.18 KB

Contents

# A moveable has a shape, speed etc.
#
module Moveable extend Trait
  
  Accelerate = :accelerate; def self.accelerate strength = 1.0; [Accelerate, strength] end
  Left       = :move_left;  def self.left       strength = 1.0; [Left,       strength] end
  Right      = :move_right; def self.right      strength = 1.0; [Right,      strength] end
  Up         = :move_up;    def self.up         strength = 1.0; [Up,         strength] end
  Down       = :move_down;  def self.down       strength = 1.0; [Down,       strength] end
  Backwards  = :backwards;  def self.backwards  strength = 1.0; [Backwards,  strength] end
  
  # Default methods for controls.
  #
  def accelerate strength = 1.0
    self.speed += self.rotation_vector * strength/SUBSTEPS
  end
  def move_left strength = 1.0
    self.speed += CP::Vec2.new(-strength.to_f/SUBSTEPS, 0)
  end
  def move_right strength = 1.0
    self.speed += CP::Vec2.new(strength.to_f/SUBSTEPS, 0)
  end
  def move_up strength = 1.0
    self.speed += CP::Vec2.new(0, -strength.to_f/SUBSTEPS)
  end
  def move_down strength = 1.0
    self.speed += CP::Vec2.new(0, strength.to_f/SUBSTEPS)
  end
  def backwards strength = 1.0
    accelerate -0.5*strength
  end
  
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
gosu_extensions-0.3.8 lib/traits/moveable.rb
gosu_extensions-0.3.7 lib/traits/moveable.rb
gosu_extensions-0.3.6 lib/traits/moveable.rb
gosu_extensions-0.3.5 lib/traits/moveable.rb
gosu_extensions-0.3.4 lib/traits/moveable.rb
gosu_extensions-0.3.3 lib/traits/moveable.rb
gosu_extensions-0.3.2 lib/traits/moveable.rb
gosu_extensions-0.3.1 lib/traits/moveable.rb
gosu_extensions-0.3.0 lib/traits/moveable.rb