Class: Logic::Game
- Inherits:
-
Object
- Object
- Logic::Game
- Defined in:
- lib/games_paradise/flappy_bird/ruby2d/logic/game.rb
Instance Attribute Summary collapse
-
#difficulty ⇒ Object
readonly
Returns the value of attribute difficulty.
-
#gravity ⇒ Object
readonly
Returns the value of attribute gravity.
-
#over ⇒ Object
(also: #over?)
readonly
Returns the value of attribute over.
-
#over_at ⇒ Object
readonly
Returns the value of attribute over_at.
-
#paused ⇒ Object
(also: #paused?)
readonly
Returns the value of attribute paused.
-
#score ⇒ Object
readonly
Returns the value of attribute score.
-
#started ⇒ Object
(also: #started?)
readonly
Returns the value of attribute started.
Instance Method Summary collapse
-
#check_if_scored!(bird, pipes) ⇒ Object
# === check_if_scored! ========================================================================= #.
-
#initialize(attrs = {}) ⇒ Game
constructor
# === initialize ========================================================================= #.
-
#over! ⇒ Object
# === over! ========================================================================= #.
-
#pause! ⇒ Object
# === pause! ========================================================================= #.
-
#reset! ⇒ Object
# === reset! ========================================================================= #.
-
#score! ⇒ Object
# === score! ========================================================================= #.
-
#start! ⇒ Object
# === start! ========================================================================= #.
Constructor Details
#initialize(attrs = {}) ⇒ Game
#
initialize
#
22 23 24 25 |
# File 'lib/games_paradise/flappy_bird/ruby2d/logic/game.rb', line 22 def initialize(attrs = {}) @attrs = attrs reset! end |
Instance Attribute Details
#difficulty ⇒ Object (readonly)
Returns the value of attribute difficulty.
15 16 17 |
# File 'lib/games_paradise/flappy_bird/ruby2d/logic/game.rb', line 15 def difficulty @difficulty end |
#gravity ⇒ Object (readonly)
Returns the value of attribute gravity.
16 17 18 |
# File 'lib/games_paradise/flappy_bird/ruby2d/logic/game.rb', line 16 def gravity @gravity end |
#over ⇒ Object (readonly) Also known as: over?
Returns the value of attribute over.
12 13 14 |
# File 'lib/games_paradise/flappy_bird/ruby2d/logic/game.rb', line 12 def over @over end |
#over_at ⇒ Object (readonly)
Returns the value of attribute over_at.
13 14 15 |
# File 'lib/games_paradise/flappy_bird/ruby2d/logic/game.rb', line 13 def over_at @over_at end |
#paused ⇒ Object (readonly) Also known as: paused?
Returns the value of attribute paused.
14 15 16 |
# File 'lib/games_paradise/flappy_bird/ruby2d/logic/game.rb', line 14 def paused @paused end |
#score ⇒ Object (readonly)
Returns the value of attribute score.
17 18 19 |
# File 'lib/games_paradise/flappy_bird/ruby2d/logic/game.rb', line 17 def score @score end |
#started ⇒ Object (readonly) Also known as: started?
Returns the value of attribute started.
11 12 13 |
# File 'lib/games_paradise/flappy_bird/ruby2d/logic/game.rb', line 11 def started @started end |
Instance Method Details
#check_if_scored!(bird, pipes) ⇒ Object
#
check_if_scored!
#
78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/games_paradise/flappy_bird/ruby2d/logic/game.rb', line 78 def check_if_scored!(bird, pipes) pipe_result = pipes .lazy .select(&:top?) .select(&:unscored?) .find { |pipe| bird.x >= pipe.x && bird.x <= pipe.x + pipe.width } return unless pipe_result score! pipe_result.scored! end |
#over! ⇒ Object
#
over!
#
52 53 54 55 |
# File 'lib/games_paradise/flappy_bird/ruby2d/logic/game.rb', line 52 def over! @over = true @over_at = Time.now end |
#pause! ⇒ Object
#
pause!
#
62 63 64 |
# File 'lib/games_paradise/flappy_bird/ruby2d/logic/game.rb', line 62 def pause! @paused = !paused? end |
#reset! ⇒ Object
#
reset!
#
30 31 32 33 34 35 36 37 38 |
# File 'lib/games_paradise/flappy_bird/ruby2d/logic/game.rb', line 30 def reset! @started = false @over = false @over_at = nil @paused = false @difficulty = @attrs[:difficulty] || :normal @gravity = @attrs[:gravity] || 0.7 @score = 0 end |
#score! ⇒ Object
#
score!
#
71 72 73 |
# File 'lib/games_paradise/flappy_bird/ruby2d/logic/game.rb', line 71 def score! @score += 1 end |
#start! ⇒ Object
#
start!
#
43 44 45 |
# File 'lib/games_paradise/flappy_bird/ruby2d/logic/game.rb', line 43 def start! @started ||= true end |