Class: SpaceInvaders::InvaderRow
- Extended by:
- Forwardable
- Defined in:
- lib/space_invaders/invaders/invader_row.rb
Constant Summary collapse
- X_POSITIONS =
[40, 110, 180, 250, 320, 390, 460, 530]
Instance Attribute Summary collapse
-
#direction ⇒ Object
Returns the value of attribute direction.
-
#invader_clazz ⇒ Object
readonly
Returns the value of attribute invader_clazz.
Attributes inherited from Base
Instance Method Summary collapse
- #check_collision(bullets) ⇒ Object
- #draw ⇒ Object
- #farmost_left_position ⇒ Object
- #farmost_right_position ⇒ Object
-
#initialize(app, y_position, invader_clazz) ⇒ InvaderRow
constructor
A new instance of InvaderRow.
- #update(direction, y_offset) ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(app, y_position, invader_clazz) ⇒ InvaderRow
Returns a new instance of InvaderRow.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/space_invaders/invaders/invader_row.rb', line 13 def initialize app, y_position, invader_clazz super(app) @y_position = y_position @direction = :right @invader_clazz = invader_clazz @invaders = [] X_POSITIONS.each do |x_position| @invaders << invader_clazz.new(app, x_position, y_position) end end |
Instance Attribute Details
#direction ⇒ Object
Returns the value of attribute direction.
8 9 10 |
# File 'lib/space_invaders/invaders/invader_row.rb', line 8 def direction @direction end |
#invader_clazz ⇒ Object (readonly)
Returns the value of attribute invader_clazz.
9 10 11 |
# File 'lib/space_invaders/invaders/invader_row.rb', line 9 def invader_clazz @invader_clazz end |
Instance Method Details
#check_collision(bullets) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/space_invaders/invaders/invader_row.rb', line 42 def check_collision(bullets) @invaders.delete_if do |invader| if invader.collides_with? bullets app.score_tracker.increase_by(invader.points) app.sounds.play_invader_hit! end end end |
#draw ⇒ Object
30 31 32 |
# File 'lib/space_invaders/invaders/invader_row.rb', line 30 def draw @invaders.each {|invader| invader.draw } end |
#farmost_left_position ⇒ Object
38 39 40 |
# File 'lib/space_invaders/invaders/invader_row.rb', line 38 def farmost_left_position @invaders.min_by {|invader| invader.x_position }.x_position end |
#farmost_right_position ⇒ Object
34 35 36 |
# File 'lib/space_invaders/invaders/invader_row.rb', line 34 def farmost_right_position @invaders.max_by {|invader| invader.x_position }.x_position end |
#update(direction, y_offset) ⇒ Object
26 27 28 |
# File 'lib/space_invaders/invaders/invader_row.rb', line 26 def update direction, y_offset @invaders.each {|invader| invader.update direction, y_offset } end |