lib/traits/controllable.rb in gosu_extensions-0.1.21 vs lib/traits/controllable.rb in gosu_extensions-0.1.22
- old
+ new
@@ -1,42 +1,34 @@
+# 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
- # TODO alternate controls handling!
+ # 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
- hook = lambda do
- if self.controls_mapping
- # primary controls taken, use alternate controls
- self.controls_mapping = self.alternate_controls_mapping if self.respond_to? :alternate_controls_mapping
- else
- self.controls_mapping = mapping
- end
+ InitializerHooks.register self do
+ self.controls_mapping = mapping
self.window.add_controls_for self
end
- InitializerHooks.register self, &hook
- end
-
- def alternate_controls mapping
- attr_accessor :alternate_controls_mapping
- hook = lambda do
- if self.controls_mapping
- # primary controls taken, use alternate controls
- self.controls_mapping = self.alternate_controls_mapping if self.respond_to? :alternate_controls_mapping
- else
- self.controls_mapping = mapping
- end
- end
- InitializerHooks.register self, &hook
end
end
end
\ No newline at end of file