class SpaceInvaders::Ship
Attributes
drowned_ship_animator[RW]
image[RW]
lives[RW]
Public Class Methods
new(app)
click to toggle source
Calls superclass method
SpaceInvaders::Base::new
# 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
Public Instance Methods
bullet_offset_speed()
click to toggle source
# File lib/space_invaders/ship/ship.rb, line 51 def bullet_offset_speed 10 end
bullets_going_down?()
click to toggle source
# File lib/space_invaders/ship/ship.rb, line 47 def bullets_going_down? false end
draw()
click to toggle source
# 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?()
click to toggle source
# File lib/space_invaders/ship/ship.rb, line 35 def no_more_lives? lives == 0 end
shooter()
click to toggle source
# File lib/space_invaders/ship/ship.rb, line 39 def shooter self end
sound()
click to toggle source
# File lib/space_invaders/ship/ship.rb, line 43 def sound app.sounds.ship_bullet_sound end
update()
click to toggle source
# 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
Private Instance Methods
animate_drowned_ship!()
click to toggle source
# File lib/space_invaders/ship/ship.rb, line 71 def animate_drowned_ship! if @image == app.images.ship_crushed_left @image = app.images.ship_crushed_right else @image = app.images.ship_crushed_left end end
decrease_lives!()
click to toggle source
# File lib/space_invaders/ship/ship.rb, line 66 def decrease_lives! @lives -= 1 app.lives_tracker.decrease_lives! end
handle_collision()
click to toggle source
# File lib/space_invaders/ship/ship.rb, line 79 def handle_collision app.sounds.play_ship_hit! decrease_lives! if no_more_lives? game_status.finished! else drowned_ship_animator.start! game_status.drowned_ship! end end
move_ship()
click to toggle source
# File lib/space_invaders/ship/ship.rb, line 90 def move_ship if app.button_down? Gosu::KbLeft and x_position > 20 @x_position += -5 elsif app.button_down? Gosu::KbRight and x_position < app.width - 90 @x_position += 5 end end
rival_bullets()
click to toggle source
# File lib/space_invaders/ship/ship.rb, line 62 def rival_bullets app.invaders_container.bullets end