Skip to content
floere edited this page Sep 14, 2010 · 10 revisions

Turnable concerns itself with everything turning. Use this if you want to make a thing turnable.

Including Turnable

The Turnable trait can be applied as usual:

class Spaceship < Thing
  it_is Turnable

or

class Spaceship < Thing
  it_is Turnable do
    # …
  end

Properties

Turnable has just one property: turn_speed

It is defined in turns per second. The default is half a turn per second.

class Spaceship < Thing
  turn_speed 2 # turns per second

Or you could override the Method turn_speed, to make it more dynamic:

def turn_speed
  lives/2 # Turns slower if wounded
end

Methods

Turnable installs two methods, turn_left and turn_right that will turn the thing depending on turn_speed.

If you use Controllable, you can define turn controls as follows

controls Gosu::Button::KbA => Turnable::Left,
         Gosu::Button::KbD => Turnable::Right