class Rubygoal::Ball
Attributes
last_kicker[RW]
Public Class Methods
new()
click to toggle source
Calls superclass method
Rubygoal::Moveable::new
# File lib/rubygoal/ball.rb, line 10 def initialize super reinitialize_position end
Public Instance Methods
goal?()
click to toggle source
# File lib/rubygoal/ball.rb, line 15 def goal? Field.goal?(position) end
move(direction, speed, kicker)
click to toggle source
# 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_position()
click to toggle source
# File lib/rubygoal/ball.rb, line 27 def reinitialize_position self.position = Field.center_position self.last_kicker = nil end
update(elapsed_time)
click to toggle source
Calls superclass method
Rubygoal::Moveable#update
# File lib/rubygoal/ball.rb, line 32 def update(elapsed_time) super prevent_out_of_bounds decelerate(elapsed_time) end
Private Instance Methods
decelerate(elapsed_time)
click to toggle source
# File lib/rubygoal/ball.rb, line 48 def decelerate(elapsed_time) coef = deceleration_coef(elapsed_time) self.velocity = velocity.mult(coef) end
deceleration_coef(elapsed_time)
click to toggle source
# File lib/rubygoal/ball.rb, line 54 def deceleration_coef(elapsed_time) custom_frame_rate = 1 / 60.0 time_coef = elapsed_time / custom_frame_rate Rubygoal.configuration.deceleration_coef ** time_coef end
prevent_out_of_bounds()
click to toggle source
# File lib/rubygoal/ball.rb, line 43 def prevent_out_of_bounds velocity.x *= -1 if Field.out_of_bounds_width?(position) velocity.y *= -1 if Field.out_of_bounds_height?(position) end