Class: Wall

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

Overview

#

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(window, type) ⇒ Wall

Returns a new instance of Wall.



20
21
22
23
24
25
26
27
28
# File 'lib/games_paradise/flappy_bird/gosu/wall.rb', line 20

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

def active
  @active
end

#xObject

Returns the value of attribute x.



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

def x
  @x
end

#yObject

Returns the value of attribute y.



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

def y
  @y
end

Instance Method Details

#drawObject



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

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

#heightObject



55
56
57
# File 'lib/games_paradise/flappy_bird/gosu/wall.rb', line 55

def height
  @wall_image.height
end

#hide?Boolean

Returns:

  • (Boolean)


47
48
49
50
51
52
53
# File 'lib/games_paradise/flappy_bird/gosu/wall.rb', line 47

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

#load_image(window, type) ⇒ Object

load_image



12
13
14
15
16
17
18
# File 'lib/games_paradise/flappy_bird/gosu/wall.rb', line 12

def load_image(window,type)
  if type == 'up'
    @wall_image = Gosu::Image.new(GamesParadise.image_directory?+'flappy_bird/wall_up.png')
  elsif type == 'down'
    @wall_image = Gosu::Image.new(GamesParadise.image_directory?+'flappy_bird/wall_down.png')
  end
end

#score?(other) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#updateObject



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

def update
  @x -= 2
end

#widthObject



59
60
61
# File 'lib/games_paradise/flappy_bird/gosu/wall.rb', line 59

def width
  @wall_image.width
end