Class: SpaceInvaders::LivesTracker
- Defined in:
- lib/space_invaders/trackers/lives_tracker.rb
Instance Attribute Summary collapse
-
#lives ⇒ Object
readonly
Returns the value of attribute lives.
Attributes inherited from Base
Instance Method Summary collapse
- #decrease_lives! ⇒ Object
- #draw ⇒ Object
-
#initialize(app) ⇒ LivesTracker
constructor
A new instance of LivesTracker.
- #set_lives_number ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(app) ⇒ LivesTracker
Returns a new instance of LivesTracker.
6 7 8 9 10 11 |
# File 'lib/space_invaders/trackers/lives_tracker.rb', line 6 def initialize app @app = app @lives = app.ship.lives @lives_headline = Gosu::Image.from_text @app, "Lives:", App::DEFAULT_FONT, 30 set_lives_number end |
Instance Attribute Details
#lives ⇒ Object (readonly)
Returns the value of attribute lives.
4 5 6 |
# File 'lib/space_invaders/trackers/lives_tracker.rb', line 4 def lives @lives end |
Instance Method Details
#decrease_lives! ⇒ Object
13 14 15 16 |
# File 'lib/space_invaders/trackers/lives_tracker.rb', line 13 def decrease_lives! @lives -= 1 set_lives_number end |
#draw ⇒ Object
22 23 24 25 |
# File 'lib/space_invaders/trackers/lives_tracker.rb', line 22 def draw @lives_headline.draw app.width - 150, 10, 1 @lives_number.draw app.width - 50, 10, 1, 1, 1, Gosu::Color::GREEN end |
#set_lives_number ⇒ Object
18 19 20 |
# File 'lib/space_invaders/trackers/lives_tracker.rb', line 18 def set_lives_number @lives_number = Gosu::Image.from_text @app, @lives, App::DEFAULT_FONT, 30 end |