Class: Wall

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

Overview

#

Constant Summary collapse

IMAGE_DIRECTORY =
GamesParadise.image_directory?

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(window, type) ⇒ Wall

#

initialize

#


28
29
30
31
32
33
34
35
36
# File 'lib/games_and_rpg_paradise/games/flappy_bird/gosu/wall.rb', line 28

def initialize(window, type)
  @active = true
  @offset_y = 25
  @wall_image = load_image(window, type)
  @type = type
  @window = window
  @x = @window.width
  @y = @window.height - @window.ground_height - Random.new.rand(@offset_y..@wall_image.height )
end

Instance Attribute Details

#activeObject

Returns the value of attribute active.



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

def active
  @active
end

#xObject

Returns the value of attribute x.



9
10
11
# File 'lib/games_and_rpg_paradise/games/flappy_bird/gosu/wall.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/wall.rb', line 9

def y
  @y
end

Instance Method Details

#drawObject



38
39
40
# File 'lib/games_and_rpg_paradise/games/flappy_bird/gosu/wall.rb', line 38

def draw
  @wall_image.draw(@x, @y, 1)
end

#heightObject



69
70
71
# File 'lib/games_and_rpg_paradise/games/flappy_bird/gosu/wall.rb', line 69

def height
  @wall_image.height
end

#hide?Boolean

Returns:

  • (Boolean)


61
62
63
64
65
66
67
# File 'lib/games_and_rpg_paradise/games/flappy_bird/gosu/wall.rb', line 61

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

#load_image(window, type) ⇒ Object

#

load_image

#


16
17
18
19
20
21
22
23
# File 'lib/games_and_rpg_paradise/games/flappy_bird/gosu/wall.rb', line 16

def load_image(window,type)
  case type
  when 'up'
    @wall_image = Gosu::Image.new(IMAGE_DIRECTORY+'flappy_bird/wall_up.png')
  when 'down'
    @wall_image = Gosu::Image.new(IMAGE_DIRECTORY+'flappy_bird/wall_down.png')
  end
end

#score?(other) ⇒ Boolean

#

score?

#

Returns:

  • (Boolean)


52
53
54
55
56
57
58
59
# File 'lib/games_and_rpg_paradise/games/flappy_bird/gosu/wall.rb', line 52

def score?(other)
  if @x + @wall_image.width  < other.x
    @active = false
    true
  else
    false
  end
end

#updateObject

#

update

#


45
46
47
# File 'lib/games_and_rpg_paradise/games/flappy_bird/gosu/wall.rb', line 45

def update
  @x -= 2
end

#widthObject



73
74
75
# File 'lib/games_and_rpg_paradise/games/flappy_bird/gosu/wall.rb', line 73

def width
  @wall_image.width
end