class SpaceInvaders::Invader
Attributes
original_x_position[R]
Public Class Methods
new(app, x_position, y_position)
click to toggle source
Calls superclass method
SpaceInvaders::Base::new
# File lib/space_invaders/invaders/invader.rb, line 10 def initialize app, x_position, y_position super app @was_first_image = true @x_position = x_position @original_x_position = x_position @y_position = y_position @image = @first_image end
Public Instance Methods
draw()
click to toggle source
# File lib/space_invaders/invaders/invader.rb, line 29 def draw @image.draw x_position, y_position, 1 end
points()
click to toggle source
# File lib/space_invaders/invaders/invader.rb, line 33 def points raise NotImplementedError.new("You must implement the inherited points method") end
update(direction, y_offset=0)
click to toggle source
# File lib/space_invaders/invaders/invader.rb, line 20 def update(direction, y_offset=0) x_offset = direction == :right ? 10 : -10 @x_position += x_offset @y_position += y_offset @was_first_image = !@was_first_image @image = @was_first_image ? @first_image : @second_image end