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 collapse

Attributes included from Moveable

#destination, #position, #rotation, #velocity

Instance Method Summary collapse

Methods included from Moveable

#distance, #move_to, #moving?, #position_after_update, #stop

Constructor Details

#initializeBall

Returns a new instance of Ball.



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

def initialize
  super
  reinitialize_position
end

Instance Attribute Details

#last_kickerObject

Returns the value of attribute last_kicker.



8
9
10
# File 'lib/rubygoal/ball.rb', line 8

def last_kicker
  @last_kicker
end

Instance Method Details

#goal?Boolean

Returns:

  • (Boolean)


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

def goal?
  Field.goal?(position)
end

#move(direction, speed, kicker) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/rubygoal/ball.rb', line 19

def move(direction, speed, kicker)
  self.velocity = Velocity.new(
    Util.offset_x(direction, speed),
    Util.offset_y(direction, speed)
  )
  self.last_kicker = kicker
end

#reinitialize_positionObject



27
28
29
30
# File 'lib/rubygoal/ball.rb', line 27

def reinitialize_position
  self.position = Field.center_position
  self.last_kicker = nil
end

#update(elapsed_time) ⇒ Object



32
33
34
35
36
37
# File 'lib/rubygoal/ball.rb', line 32

def update(elapsed_time)
  super

  prevent_out_of_bounds
  decelerate(elapsed_time)
end