Class: Logic::GroundManager

Inherits:
Object
  • Object
show all
Defined in:
lib/games_and_rpg_paradise/games/flappy_bird/ruby2d/logic/ground.rb

Instance Method Summary collapse

Constructor Details

#initializeGroundManager

Returns a new instance of GroundManager.



19
20
21
22
# File 'lib/games_and_rpg_paradise/games/flappy_bird/ruby2d/logic/ground.rb', line 19

def initialize
  @grounds = { first: Ground.new, last: Ground.new }
  reset!
end

Instance Method Details

#grounds(*keys) ⇒ Object



30
31
32
33
# File 'lib/games_and_rpg_paradise/games/flappy_bird/ruby2d/logic/ground.rb', line 30

def grounds(*keys)
  return @grounds.values if keys.empty?
  @grounds.dig(*keys)
end

#move!Object

move!



36
37
38
39
40
41
# File 'lib/games_and_rpg_paradise/games/flappy_bird/ruby2d/logic/ground.rb', line 36

def move!
  grounds.each { |ground|
    ground.x -= 1
    ground.x = ground.width if ground.width + ground.x <= 0
  }
end

#reset!Object

reset!



25
26
27
28
# File 'lib/games_and_rpg_paradise/games/flappy_bird/ruby2d/logic/ground.rb', line 25

def reset!
  grounds(:first).x = 0
  grounds(:last).x = 288
end