Class: SpaceInvaders::Invader

Inherits:
Base
  • Object
show all
Includes:
Collideable, Mesurable
Defined in:
lib/space_invaders/invaders/invader.rb

Direct Known Subclasses

RedInvader

Instance Attribute Summary collapse

Attributes included from Mesurable

#x_position, #y_position

Attributes inherited from Base

#app

Instance Method Summary collapse

Methods included from Collideable

#collides_with?, #got_hit_by?

Methods included from Mesurable

#height, #width, #x_middle

Methods inherited from Base

#game_status

Constructor Details

#initialize(app, x_position, y_position) ⇒ Invader



10
11
12
13
14
15
16
17
18
# 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

Instance Attribute Details

#original_x_positionObject (readonly)

Returns the value of attribute original_x_position.



8
9
10
# File 'lib/space_invaders/invaders/invader.rb', line 8

def original_x_position
  @original_x_position
end

Instance Method Details

#drawObject



29
30
31
# File 'lib/space_invaders/invaders/invader.rb', line 29

def draw
  @image.draw x_position, y_position, 1
end

#pointsObject

Raises:

  • (NotImplementedError)


33
34
35
# 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) ⇒ Object



20
21
22
23
24
25
26
27
# 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