Class: Rubygoal::Player

Inherits:
Object
  • Object
show all
Includes:
Moveable
Defined in:
lib/rubygoal/player.rb

Direct Known Subclasses

AveragePlayer, CaptainPlayer, FastPlayer

Constant Summary collapse

STRAIGHT_ANGLE =
180

Constants included from Moveable

Moveable::MIN_DISTANCE

Instance Attribute Summary collapse

Attributes included from Moveable

#destination, #position, #rotation, #velocity

Instance Method Summary collapse

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_positionObject

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

#nameObject (readonly)

Returns the value of attribute name.



14
15
16
# File 'lib/rubygoal/player.rb', line 14

def name
  @name
end

#sideObject (readonly)

Returns the value of attribute side.



14
15
16
# File 'lib/rubygoal/player.rb', line 14

def side
  @side
end

#typeObject (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

Returns:

  • (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_positionObject



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