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.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#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, name) ⇒ 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, name) ⇒ Player
Returns a new instance of Player.
17 18 19 20 21 22 23 24 |
# File 'lib/rubygoal/player.rb', line 17 def initialize(game, side, name) super() @time_to_kick_again = 0 @side = side @player_movement = PlayerMovement.new(game, self) @name = name 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 |
#name ⇒ Object (readonly)
Returns the value of attribute name.
14 15 16 |
# File 'lib/rubygoal/player.rb', line 14 def name @name 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
26 27 28 |
# File 'lib/rubygoal/player.rb', line 26 def can_kick?(ball) !waiting_to_kick_again? && control_ball?(ball) end |
#kick(ball, target) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/rubygoal/player.rb', line 30 def kick(ball, target) direction = random_direction(target) strength = random_strength ball.move(direction, strength, name: name, side: side) reset_waiting_to_kick! end |
#move_to_coach_position ⇒ Object
38 39 40 |
# File 'lib/rubygoal/player.rb', line 38 def move_to_coach_position move_to(coach_defined_position) end |
#update(elapsed_time) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/rubygoal/player.rb', line 42 def update(elapsed_time) update_waiting_to_kick(elapsed_time) player_movement.update(elapsed_time) if moving? super end |