Class: Logic::PipeManager
- Inherits:
-
Object
- Object
- Logic::PipeManager
- Defined in:
- lib/games_and_rpg_paradise/games/flappy_bird/ruby2d/logic/pipe.rb
Constant Summary collapse
- DEFAULTS =
DEFAULTS
{ top_y: 0, bottom_y: 370, distance: 117, acceleration: { easy: 2, normal: 2, hard: 3 }, offset_step: { easy: 20, normal: 30, hard: 60 } }.freeze
Instance Method Summary collapse
-
#initialize(window:, game:) ⇒ PipeManager
constructor
initialize.
- #move! ⇒ Object
- #pipes(*keys) ⇒ Object
- #reset! ⇒ Object
Constructor Details
#initialize(window:, game:) ⇒ PipeManager
initialize
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/games_and_rpg_paradise/games/flappy_bird/ruby2d/logic/pipe.rb', line 56 def initialize(window:, game:) @window = window @game = game @pipes = { first: { top: Pipe.new(position: :top), bottom: Pipe.new(position: :bottom) }, last: { top: Pipe.new(position: :top), bottom: Pipe.new(position: :bottom) } } reset! end |
Instance Method Details
#move! ⇒ Object
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/games_and_rpg_paradise/games/flappy_bird/ruby2d/logic/pipe.rb', line 88 def move! grouped_pipes do |_id, pipe, new_y| pipe.x -= DEFAULTS[:acceleration][difficulty] if gone?(pipe) pipe.x = initial_x pipe.y = new_y pipe.unscored! end end end |
#pipes(*keys) ⇒ Object
80 81 82 83 84 85 86 |
# File 'lib/games_and_rpg_paradise/games/flappy_bird/ruby2d/logic/pipe.rb', line 80 def pipes(*keys) if keys.empty? @pipes.values.flat_map(&:values) else @pipes.dig(*keys) end end |
#reset! ⇒ Object
72 73 74 75 76 77 78 |
# File 'lib/games_and_rpg_paradise/games/flappy_bird/ruby2d/logic/pipe.rb', line 72 def reset! grouped_pipes { |id, pipe, new_y| pipe.x = initial_x(id) pipe.y = new_y pipe.unscored! } end |