Sha256: f4a9706a0733ecd16babde8cee97749ae9b44037c59be11adf2ea81a5e18b4d0

Contents?: true

Size: 991 Bytes

Versions: 12

Compression:

Stored size: 991 Bytes

Contents

# This is a convenience trait.
#
# Instead of calling
#   @controls << Control.new(self, @player1, :some_key_code => :action)
# you can define the controls in the object itself.
#
module Controllable extend Trait
  
  def self.included controllable
    controllable.extend ClassMethods
  end
  
  module ClassMethods
    
    # Enables to define the controls in the object itself, as in the Example:
    # 
    # class Spaceship < Thing
    #   it_is Controllable
    #   controls Gosu::Button::KbA     => Turnable::Left,
    #            Gosu::Button::KbD     => Turnable::Right,
    #            Gosu::Button::KbW     => Moveable::Accelerate,
    #            Gosu::Button::KbS     => Moveable::Backwards,
    #            Gosu::Button::KbSpace => Shooter::Shoot
    #
    def controls mapping
      attr_accessor :controls_mapping
      InitializerHooks.register self do
        self.controls_mapping = mapping
        self.window.add_controls_for self
      end
    end
    
  end
  
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
gosu_extensions-0.2.4 lib/traits/controllable.rb
gosu_extensions-0.2.3 lib/traits/controllable.rb
gosu_extensions-0.2.2 lib/traits/controllable.rb
gosu_extensions-0.2.1 lib/traits/controllable.rb
gosu_extensions-0.2.0 lib/traits/controllable.rb
gosu_extensions-0.1.28 lib/traits/controllable.rb
gosu_extensions-0.1.27 lib/traits/controllable.rb
gosu_extensions-0.1.26 lib/traits/controllable.rb
gosu_extensions-0.1.25 lib/traits/controllable.rb
gosu_extensions-0.1.24 lib/traits/controllable.rb
gosu_extensions-0.1.23 lib/traits/controllable.rb
gosu_extensions-0.1.22 lib/traits/controllable.rb