Class: Rubygoal::Player
Constant Summary
Constants included
from Moveable
Moveable::MIN_DISTANCE
Instance Attribute Summary
Attributes included from Moveable
#position, #velocity
Instance Method Summary
collapse
Methods included from Moveable
#distance, #move_to, #moving?
Constructor Details
#initialize(game_window, side) ⇒ Player
Returns a new instance of Player.
10
11
12
13
14
15
16
|
# File 'lib/rubygoal/player.rb', line 10
def initialize(game_window, side)
super()
@image = Gosu::Image.new(game_window, image_filename(side), false)
@time_to_kick_again = 0
@field = game_window.field
end
|
Instance Method Details
#can_kick?(ball) ⇒ Boolean
18
19
20
|
# File 'lib/rubygoal/player.rb', line 18
def can_kick?(ball)
!waiting_to_kick_again? && control_ball?(ball)
end
|
#draw ⇒ Object
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/rubygoal/player.rb', line 42
def draw
if moving?
angle = Gosu.angle(position.x, position.y, destination.x, destination.y)
angle -= 90
else
angle = 0.0
end
image.draw_rot(position.x, position.y, 1, angle)
end
|
#kick(ball, target) ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/rubygoal/player.rb', line 22
def kick(ball, target)
strength = Config.player.kick_strength * Random.rand(error_range)
direction = Gosu.angle(position.x, position.y, target.x, target.y)
direction *= Random.rand(error_range)
velocity = Velocity.new(
Gosu.offset_x(direction, strength),
Gosu.offset_y(direction, strength)
)
ball.velocity = velocity
reset_waiting_to_kick!
end
|
#update ⇒ Object
37
38
39
40
|
# File 'lib/rubygoal/player.rb', line 37
def update
update_waiting_to_kick!
super
end
|