Class: Rubygoal::Ball

Inherits:
Object
  • Object
show all
Includes:
Moveable
Defined in:
lib/rubygoal/ball.rb

Constant Summary

Constants included from Moveable

Moveable::MIN_DISTANCE

Instance Attribute Summary

Attributes included from Moveable

#position, #velocity

Instance Method Summary collapse

Methods included from Moveable

#distance, #move_to, #moving?

Constructor Details

#initialize(window, position) ⇒ Ball



10
11
12
13
14
# File 'lib/rubygoal/ball.rb', line 10

def initialize(window, position)
  super()
  @position = position
  @image = Gosu::Image.new(window, Config.ball.image_file, false)
end

Instance Method Details

#drawObject



20
21
22
# File 'lib/rubygoal/ball.rb', line 20

def draw
  image.draw(position.x - Config.ball.width / 2, position.y - Config.ball.height / 2, 1)
end

#goal?Boolean



16
17
18
# File 'lib/rubygoal/ball.rb', line 16

def goal?
  FieldMetrics.goal?(position)
end

#updateObject



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rubygoal/ball.rb', line 24

def update
  super
  if FieldMetrics.out_of_bounds_width?(position)
    velocity.x *= -1
  end
  if FieldMetrics.out_of_bounds_height?(position)
    velocity.y *= -1
  end

  velocity.x *= 0.95
  velocity.y *= 0.95
end