Class: Ground

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

Overview

#

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(window) ⇒ Ground

#

initialize

#


23
24
25
26
27
28
29
30
# File 'lib/games_and_rpg_paradise/games/flappy_bird/gosu/ground.rb', line 23

def initialize(window)
  @ground_image = load_image(window)

  @window = window
  @x = 0
  @y = @window.height - @ground_image.height
  reset
end

Instance Attribute Details

#xObject

Returns the value of attribute x.



9
10
11
# File 'lib/games_and_rpg_paradise/games/flappy_bird/gosu/ground.rb', line 9

def x
  @x
end

#yObject

Returns the value of attribute y.



9
10
11
# File 'lib/games_and_rpg_paradise/games/flappy_bird/gosu/ground.rb', line 9

def y
  @y
end

Instance Method Details

#drawObject



37
38
39
# File 'lib/games_and_rpg_paradise/games/flappy_bird/gosu/ground.rb', line 37

def draw
  @ground_image.draw(@x, @y, 5)
end

#heightObject

#

height

#


57
58
59
# File 'lib/games_and_rpg_paradise/games/flappy_bird/gosu/ground.rb', line 57

def height
  @ground_image.height
end

#hide?Boolean

Returns:

  • (Boolean)


46
47
48
49
50
51
52
# File 'lib/games_and_rpg_paradise/games/flappy_bird/gosu/ground.rb', line 46

def hide?
  if @x + (@ground_image.width / 2) < 0
    true
  else
    false
  end
end

#load_image(window) ⇒ Object

#

load_image

#


14
15
16
17
18
# File 'lib/games_and_rpg_paradise/games/flappy_bird/gosu/ground.rb', line 14

def load_image(window)
  @ground_image ||= Gosu::Image.new(
    GamesAndRpgParadise.image_directory?+'flappy_bird/ground.png'
  )
end

#resetObject



32
33
34
35
# File 'lib/games_and_rpg_paradise/games/flappy_bird/gosu/ground.rb', line 32

def reset
  @x = 0
  @y = @window.height - @ground_image.height
end

#updateObject



41
42
43
44
# File 'lib/games_and_rpg_paradise/games/flappy_bird/gosu/ground.rb', line 41

def update
  @x -= 2
  reset if hide?
end