Class: SpaceInvaders::Ship
Instance Attribute Summary collapse
Attributes included from Mesurable
#x_position, #y_position
Attributes inherited from Base
#app
Instance Method Summary
collapse
#collides_with?, #got_hit_by?
Methods included from Fireable
#bullet_collection, #fire!
Methods included from Mesurable
#height, #width, #x_middle
Methods inherited from Base
#game_status
Constructor Details
#initialize(app) ⇒ Ship
Returns a new instance of Ship.
13
14
15
16
17
18
19
20
|
# File 'lib/space_invaders/ship/ship.rb', line 13
def initialize app
super
@image = app.images.ship
@x_position = app.width/2 - 40
@y_position = app.height - 50
@lives = 3
@drowned_ship_animator = DrownedShipAnimator.new app, self
end
|
Instance Attribute Details
#drowned_ship_animator ⇒ Object
Returns the value of attribute drowned_ship_animator.
11
12
13
|
# File 'lib/space_invaders/ship/ship.rb', line 11
def drowned_ship_animator
@drowned_ship_animator
end
|
#image ⇒ Object
Returns the value of attribute image.
11
12
13
|
# File 'lib/space_invaders/ship/ship.rb', line 11
def image
@image
end
|
#lives ⇒ Object
Returns the value of attribute lives.
11
12
13
|
# File 'lib/space_invaders/ship/ship.rb', line 11
def lives
@lives
end
|
Instance Method Details
#bullet_offset_speed ⇒ Object
51
52
53
|
# File 'lib/space_invaders/ship/ship.rb', line 51
def bullet_offset_speed
10
end
|
#bullets_going_down? ⇒ Boolean
47
48
49
|
# File 'lib/space_invaders/ship/ship.rb', line 47
def bullets_going_down?
false
end
|
#draw ⇒ Object
55
56
57
58
|
# File 'lib/space_invaders/ship/ship.rb', line 55
def draw
@image.draw @x_position, @y_position, 1
bullet_collection.draw
end
|
#no_more_lives? ⇒ Boolean
35
36
37
|
# File 'lib/space_invaders/ship/ship.rb', line 35
def no_more_lives?
lives == 0
end
|
#shooter ⇒ Object
39
40
41
|
# File 'lib/space_invaders/ship/ship.rb', line 39
def shooter
self
end
|
#sound ⇒ Object
43
44
45
|
# File 'lib/space_invaders/ship/ship.rb', line 43
def sound
app.sounds.ship_bullet_sound
end
|
#update ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/space_invaders/ship/ship.rb', line 22
def update
if game_status.drowned_ship?
drowned_ship_animator.update
else
if collides_with? rival_bullets
handle_collision
else
move_ship
bullet_collection.update
end
end
end
|