Class: SpaceInvaders::UBlock

Inherits:
Base
  • Object
show all
Defined in:
lib/space_invaders/blocks/u_block.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#app

Instance Method Summary collapse

Methods inherited from Base

#game_status

Constructor Details

#initialize(app, x_position, y_position) ⇒ UBlock

Returns a new instance of UBlock.



9
10
11
12
13
14
15
# File 'lib/space_invaders/blocks/u_block.rb', line 9

def initialize app, x_position, y_position
  super app
  @x_position = x_position
  @y_position = y_position
  @blocks = []
  initialize_blocks
end

Instance Attribute Details

#blocksObject (readonly)

Returns the value of attribute blocks.



7
8
9
# File 'lib/space_invaders/blocks/u_block.rb', line 7

def blocks
  @blocks
end

#x_positionObject (readonly)

Returns the value of attribute x_position.



7
8
9
# File 'lib/space_invaders/blocks/u_block.rb', line 7

def x_position
  @x_position
end

#y_positionObject (readonly)

Returns the value of attribute y_position.



7
8
9
# File 'lib/space_invaders/blocks/u_block.rb', line 7

def y_position
  @y_position
end

Instance Method Details

#delete(block) ⇒ Object



33
34
35
# File 'lib/space_invaders/blocks/u_block.rb', line 33

def delete(block)
  blocks.delete(block)
end

#drawObject



21
22
23
# File 'lib/space_invaders/blocks/u_block.rb', line 21

def draw
  blocks.each {|block| block.draw }
end

#initialize_blocksObject



25
26
27
28
29
30
31
# File 'lib/space_invaders/blocks/u_block.rb', line 25

def initialize_blocks
  x = [10, 10, 10, 40, 70, 70, 70]
  y = [10, 30, 50, 10, 10, 30, 50]
  7.times do |i|
    @blocks << Block.new(self, x[i] + x_position, y[i] + y_position)
  end
end

#updateObject



17
18
19
# File 'lib/space_invaders/blocks/u_block.rb', line 17

def update
  blocks.each {|block| block.update }
end