-
Notifications
You must be signed in to change notification settings - Fork 1
Trait: UserInterface
Lives is about a thing having lives. If it has lives, it can be killed. If it has been killed more times than it has lives, it will be destroyed.
The UserInterface trait can be applied as usual:
class Skier < Thing
it_has UserInterface # Yeah, I know, sounds a bit russian ;)
or
class Skier < Thing
it_has UserInterface do
# …
end
The UserInterface has just one property: ui
. Use this if there should be the same UI for all these objects. Or if there is only one.
It defines a user interface (no way, get out here!):
ui x, y, gosu_color, &block_in_which_you_return_a_string_with_what_is_displayed
class Skier < Thing
# left upper corner, black, speed uses the speed method on skier.
#
ui 10, 10, Gosu::Color::BLACK do "skier has a speed of #{speed}" end
UserInterface installs one methods, ui
, which, if called, installs another one, draw_ui
.
The ui
method has the same parameters as the ui
class method, but only installs the UI on the instance.
@player_one.ui 10, 10, Gosu::Color::BLACK do ammo_low? ? "ammo low!" : "fire, fire, fire!" end
@player_two.ui 800, 10, Gosu::Color::RED do lives < 3 ? "cough, cough wheeze" : "you look great!" end
If you want to make it all yourself, then define a draw_ui
method, and register yourself with the window.
def draw_ui
# do something spectacular
end
# somewhere:
window.register_ui @my_thing