Class: Ground

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

Overview

#

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(window) ⇒ Ground

Returns a new instance of Ground.



16
17
18
19
20
21
22
23
# File 'lib/games_paradise/flappy_bird/gosu/ground.rb', line 16

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_paradise/flappy_bird/gosu/ground.rb', line 9

def x
  @x
end

#yObject

Returns the value of attribute y.



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

def y
  @y
end

Instance Method Details

#drawObject



30
31
32
# File 'lib/games_paradise/flappy_bird/gosu/ground.rb', line 30

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

#heightObject



47
48
49
# File 'lib/games_paradise/flappy_bird/gosu/ground.rb', line 47

def height
  @ground_image.height
end

#hide?Boolean

Returns:

  • (Boolean)


39
40
41
42
43
44
45
# File 'lib/games_paradise/flappy_bird/gosu/ground.rb', line 39

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

#load_image(window) ⇒ Object

load_image



12
13
14
# File 'lib/games_paradise/flappy_bird/gosu/ground.rb', line 12

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

#resetObject



25
26
27
28
# File 'lib/games_paradise/flappy_bird/gosu/ground.rb', line 25

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

#updateObject



34
35
36
37
# File 'lib/games_paradise/flappy_bird/gosu/ground.rb', line 34

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