class Rubygoal::Player
Constants
- STRAIGHT_ANGLE
Attributes
coach_defined_position[RW]
error[R]
player_movement[RW]
side[R]
time_to_kick_again[RW]
type[R]
Public Class Methods
new(game, side)
click to toggle source
Calls superclass method
Rubygoal::Moveable::new
# File lib/rubygoal/player.rb, line 17 def initialize(game, side) super() @time_to_kick_again = 0 @side = side @player_movement = PlayerMovement.new(game, self) end
Public Instance Methods
can_kick?(ball)
click to toggle source
# File lib/rubygoal/player.rb, line 25 def can_kick?(ball) !waiting_to_kick_again? && control_ball?(ball) end
kick(ball, target)
click to toggle source
# File lib/rubygoal/player.rb, line 29 def kick(ball, target) direction = random_direction(target) strength = random_strength ball.move(direction, strength) reset_waiting_to_kick! end
move_to_coach_position()
click to toggle source
# File lib/rubygoal/player.rb, line 37 def move_to_coach_position move_to(coach_defined_position) end
update(elapsed_time)
click to toggle source
Calls superclass method
Rubygoal::Moveable#update
# File lib/rubygoal/player.rb, line 41 def update(elapsed_time) update_waiting_to_kick(elapsed_time) player_movement.update(elapsed_time) if moving? super end
Private Instance Methods
control_ball?(ball)
click to toggle source
# File lib/rubygoal/player.rb, line 68 def control_ball?(ball) distance(ball.position) < Rubygoal.configuration.distance_control_ball end
random_direction(target)
click to toggle source
# File lib/rubygoal/player.rb, line 78 def random_direction(target) direction = Util.angle(position.x, position.y, target.x, target.y) max_angle_error = STRAIGHT_ANGLE * error angle_error_range = -max_angle_error..max_angle_error direction += Random.rand(angle_error_range) end
random_strength()
click to toggle source
# File lib/rubygoal/player.rb, line 72 def random_strength error_range = (1 - error)..(1 + error) error_coef = Random.rand(error_range) Rubygoal.configuration.kick_strength * error_coef end
reset_waiting_to_kick!()
click to toggle source
# File lib/rubygoal/player.rb, line 60 def reset_waiting_to_kick! self.time_to_kick_again = Rubygoal.configuration.kick_again_delay end
update_waiting_to_kick(time_elapsed)
click to toggle source
# File lib/rubygoal/player.rb, line 64 def update_waiting_to_kick(time_elapsed) self.time_to_kick_again -= time_elapsed if waiting_to_kick_again? end
waiting_to_kick_again?()
click to toggle source
# File lib/rubygoal/player.rb, line 56 def waiting_to_kick_again? time_to_kick_again > 0 end