Class: Rubygoal::Player
- Inherits:
-
Object
- Object
- Rubygoal::Player
- Includes:
- Moveable
- Defined in:
- lib/rubygoal/player.rb
Direct Known Subclasses
Constant Summary collapse
- STRAIGHT_ANGLE =
180
Constants included from Moveable
Instance Attribute Summary collapse
-
#coach_defined_position ⇒ Object
Returns the value of attribute coach_defined_position.
-
#side ⇒ Object
readonly
Returns the value of attribute side.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Attributes included from Moveable
#destination, #position, #rotation, #velocity
Instance Method Summary collapse
- #can_kick?(ball) ⇒ Boolean
-
#initialize(game, side) ⇒ Player
constructor
A new instance of Player.
- #kick(ball, target) ⇒ Object
- #move_to_coach_position ⇒ Object
- #update(elapsed_time) ⇒ Object
Methods included from Moveable
#distance, #move_to, #moving?, #position_after_update, #stop
Constructor Details
#initialize(game, side) ⇒ Player
17 18 19 20 21 22 23 |
# 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 |
Instance Attribute Details
#coach_defined_position ⇒ Object
Returns the value of attribute coach_defined_position.
15 16 17 |
# File 'lib/rubygoal/player.rb', line 15 def coach_defined_position @coach_defined_position end |
#side ⇒ Object (readonly)
Returns the value of attribute side.
14 15 16 |
# File 'lib/rubygoal/player.rb', line 14 def side @side end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
14 15 16 |
# File 'lib/rubygoal/player.rb', line 14 def type @type end |
Instance Method Details
#can_kick?(ball) ⇒ Boolean
25 26 27 |
# File 'lib/rubygoal/player.rb', line 25 def can_kick?(ball) !waiting_to_kick_again? && control_ball?(ball) end |
#kick(ball, target) ⇒ Object
29 30 31 32 33 34 35 |
# 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 ⇒ Object
37 38 39 |
# File 'lib/rubygoal/player.rb', line 37 def move_to_coach_position move_to(coach_defined_position) end |
#update(elapsed_time) ⇒ Object
41 42 43 44 45 46 |
# 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 |