Class: SpaceInvaders::InvadersContainer
- Inherits:
-
Base
- Object
- Base
- SpaceInvaders::InvadersContainer
show all
- Includes:
- Fireable
- Defined in:
- lib/space_invaders/invaders/invaders_container.rb
Instance Attribute Summary collapse
Attributes inherited from Base
#app
Instance Method Summary
collapse
Methods included from Fireable
#bullet_collection, #bullet_offset_speed, #bullets_going_down?, #fire!
Methods inherited from Base
#game_status
Constructor Details
Returns a new instance of InvadersContainer.
10
11
12
13
14
15
16
17
|
# File 'lib/space_invaders/invaders/invaders_container.rb', line 10
def initialize app
super
create_invader_rows
@change_time = Time.now
@can_fire = Time.now
@direction = :right
@y_offset = 0
end
|
Instance Attribute Details
#invader_rows ⇒ Object
Returns the value of attribute invader_rows.
8
9
10
|
# File 'lib/space_invaders/invaders/invaders_container.rb', line 8
def invader_rows
@invader_rows
end
|
Instance Method Details
#any_invaders? ⇒ Boolean
49
50
51
|
# File 'lib/space_invaders/invaders/invaders_container.rb', line 49
def any_invaders?
not count.zero?
end
|
#count ⇒ Object
45
46
47
|
# File 'lib/space_invaders/invaders/invaders_container.rb', line 45
def count
invader_rows.map {|invader_row| invader_row.count}.inject(:+) || 0
end
|
#draw ⇒ Object
40
41
42
43
|
# File 'lib/space_invaders/invaders/invaders_container.rb', line 40
def draw
invader_rows.each {|invader_row| invader_row.draw }
bullets.draw
end
|
#no_invaders? ⇒ Boolean
53
54
55
|
# File 'lib/space_invaders/invaders/invaders_container.rb', line 53
def no_invaders?
count.zero?
end
|
#reinitialize! ⇒ Object
57
58
59
60
61
62
63
|
# File 'lib/space_invaders/invaders/invaders_container.rb', line 57
def reinitialize!
create_invader_rows
bullets.clear
rival_bullets.clear
@change_time = Time.now
@can_fire = Time.now
end
|
#update ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/space_invaders/invaders/invaders_container.rb', line 19
def update
check_collision
if no_invaders?
app.next_level_screen.timer_start!
return game_status.next_level!
end
if can_change?
change_direction
@change_time = Time.now
end
if can_fire?
fire!
@can_fire = Time.now
end
bullets.update
end
|