class Rubygoal::Ball
Public Class Methods
new()
click to toggle source
Calls superclass method
Rubygoal::Moveable::new
# File lib/rubygoal/ball.rb, line 9 def initialize super reinitialize_position end
Public Instance Methods
goal?()
click to toggle source
# File lib/rubygoal/ball.rb, line 14 def goal? Field.goal?(position) end
move(direction, speed)
click to toggle source
# File lib/rubygoal/ball.rb, line 18 def move(direction, speed) self.velocity = Velocity.new( Util.offset_x(direction, speed), Util.offset_y(direction, speed) ) end
reinitialize_position()
click to toggle source
# File lib/rubygoal/ball.rb, line 25 def reinitialize_position self.position = Field.center_position end
update(elapsed_time)
click to toggle source
Calls superclass method
Rubygoal::Moveable#update
# File lib/rubygoal/ball.rb, line 29 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 47 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 53 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 38 def prevent_out_of_bounds if Field.out_of_bounds_width?(position) velocity.x *= -1 end if Field.out_of_bounds_height?(position) velocity.y *= -1 end end