Class: SpaceInvaders::DrownedShipAnimator

Inherits:
Base
  • Object
show all
Defined in:
lib/space_invaders/ship/drowned_ship_animator.rb

Constant Summary collapse

ANIMATION_LENGTH_IN_SECONDS =
2

Instance Attribute Summary collapse

Attributes inherited from Base

#app

Instance Method Summary collapse

Methods inherited from Base

#game_status

Constructor Details

#initialize(app, ship) ⇒ DrownedShipAnimator

Returns a new instance of DrownedShipAnimator.



8
9
10
11
# File 'lib/space_invaders/ship/drowned_ship_animator.rb', line 8

def initialize(app, ship)
  super(app)
  @ship = ship
end

Instance Attribute Details

#shipObject

Returns the value of attribute ship.



6
7
8
# File 'lib/space_invaders/ship/drowned_ship_animator.rb', line 6

def ship
  @ship
end

Instance Method Details

#animation_time_is_over?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/space_invaders/ship/drowned_ship_animator.rb', line 17

def animation_time_is_over?
  passed_time > ANIMATION_LENGTH_IN_SECONDS
end

#reset!Object



21
22
23
# File 'lib/space_invaders/ship/drowned_ship_animator.rb', line 21

def reset!
  @start_time = nil
end

#start!Object



13
14
15
# File 'lib/space_invaders/ship/drowned_ship_animator.rb', line 13

def start!
  @start_time = Time.now
end

#updateObject



25
26
27
28
29
30
31
32
33
34
# File 'lib/space_invaders/ship/drowned_ship_animator.rb', line 25

def update
  ship.image = if animation_time_is_over?
    app.game_status.continue!
    app.images.ship
  elsif left_image_time?
    app.images.ship_crushed_left
  else
    app.images.ship_crushed_right
  end
end