Class: Logic::Game

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ Game

#

initialize

#


22
23
24
25
# File 'lib/games_and_rpg_paradise/games/flappy_bird/ruby2d/logic/game.rb', line 22

def initialize(attrs = {})
  @attrs = attrs
  reset!
end

Instance Attribute Details

#difficultyObject (readonly)

Returns the value of attribute difficulty.



15
16
17
# File 'lib/games_and_rpg_paradise/games/flappy_bird/ruby2d/logic/game.rb', line 15

def difficulty
  @difficulty
end

#gravityObject (readonly)

Returns the value of attribute gravity.



16
17
18
# File 'lib/games_and_rpg_paradise/games/flappy_bird/ruby2d/logic/game.rb', line 16

def gravity
  @gravity
end

#overObject (readonly) Also known as: over?

Returns the value of attribute over.



12
13
14
# File 'lib/games_and_rpg_paradise/games/flappy_bird/ruby2d/logic/game.rb', line 12

def over
  @over
end

#over_atObject (readonly)

Returns the value of attribute over_at.



13
14
15
# File 'lib/games_and_rpg_paradise/games/flappy_bird/ruby2d/logic/game.rb', line 13

def over_at
  @over_at
end

#pausedObject (readonly) Also known as: paused?

Returns the value of attribute paused.



14
15
16
# File 'lib/games_and_rpg_paradise/games/flappy_bird/ruby2d/logic/game.rb', line 14

def paused
  @paused
end

#scoreObject (readonly)

Returns the value of attribute score.



17
18
19
# File 'lib/games_and_rpg_paradise/games/flappy_bird/ruby2d/logic/game.rb', line 17

def score
  @score
end

#startedObject (readonly) Also known as: started?

Returns the value of attribute started.



11
12
13
# File 'lib/games_and_rpg_paradise/games/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_and_rpg_paradise/games/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_and_rpg_paradise/games/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_and_rpg_paradise/games/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_and_rpg_paradise/games/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_and_rpg_paradise/games/flappy_bird/ruby2d/logic/game.rb', line 71

def score!
  @score += 1
end

#start!Object

#

start!

#


43
44
45
# File 'lib/games_and_rpg_paradise/games/flappy_bird/ruby2d/logic/game.rb', line 43

def start!
  @started ||= true
end