Class: Asteroids::ObjectPool
- Inherits:
-
Object
- Object
- Asteroids::ObjectPool
- Defined in:
- lib/asteroids/componenets/game_pool.rb
Instance Attribute Summary collapse
-
#objects ⇒ Object
Returns the value of attribute objects.
Instance Method Summary collapse
- #find_empty_space ⇒ Object
-
#initialize ⇒ ObjectPool
constructor
A new instance of ObjectPool.
- #is_not_empty(x, y) ⇒ Object
- #update_all ⇒ Object
Constructor Details
#initialize ⇒ ObjectPool
Returns a new instance of ObjectPool.
5 6 7 |
# File 'lib/asteroids/componenets/game_pool.rb', line 5 def initialize @objects = [] end |
Instance Attribute Details
#objects ⇒ Object
Returns the value of attribute objects.
3 4 5 |
# File 'lib/asteroids/componenets/game_pool.rb', line 3 def objects @objects end |
Instance Method Details
#find_empty_space ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/asteroids/componenets/game_pool.rb', line 14 def find_empty_space x = Gosu::random(0, 800) y = Gosu::random(0, 600) while is_not_empty(x, y) x = Gosu::random(0, 800) y = Gosu::random(0, 600) end {x: x, y: y} end |
#is_not_empty(x, y) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/asteroids/componenets/game_pool.rb', line 24 def is_not_empty(x, y) @objects.each do |object| if object.is_a? Asteroids::Asteroid and object.x == x and object.y == y return true end end false end |
#update_all ⇒ Object
9 10 11 12 |
# File 'lib/asteroids/componenets/game_pool.rb', line 9 def update_all @objects.map(&:update) @objects.delete_if { |object| object.removable?} end |