Class: SpaceInvaders::LivesTracker

Inherits:
Base
  • Object
show all
Defined in:
lib/space_invaders/trackers/lives_tracker.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#app

Instance Method Summary collapse

Methods inherited from Base

#game_status

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

#livesObject (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

#drawObject



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_numberObject



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