-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.rb
64 lines (57 loc) · 1.51 KB
/
player.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
class Player
ROTATION_SPEED = 3
ACCELERATION = 2
FRICTION = 0.9
attr_reader :x, :y, :angle, :radius # shortcut for GETters
def initialize(window)
@x = 750
@y = 750
@angle = 0
@image = Gosu::Image.new('images/witch.png')
@velocity_x = 0
@velocity_y = 0
@radius = 20
@window = window
end
def draw
@image.draw_rot(@x, @y, 0, @angle)
end
def turn_right
#@angle += ROTATION_SPEED # if left not move but change angle
@velocity_x += Gosu.offset_x(@angle+90, ACCELERATION)
end
def turn_left
#@angle -= ROTATION_SPEED # if right not move but change angle
@velocity_x -= Gosu.offset_x(@angle+90, ACCELERATION)
end
def accelerate
#@velocity_x += Gosu.offset_x(@angle, ACCELERATION) # if left & right not move but change angle
@velocity_y += Gosu.offset_y(@angle, ACCELERATION)
end
def goback
#@velocity_x -= Gosu.offset_x(@angle, ACCELERATION) # if left & right not move but change angle
@velocity_y -= Gosu.offset_y(@angle, ACCELERATION)
end
def move
@x += @velocity_x
@y += @velocity_y
@velocity_x *= FRICTION
@velocity_y *= FRICTION
if @x > @window.width - @radius then
@velocity_x = 0
@x = @window.width - @radius
end
if @x < @radius then
@velocity_x = 0
@x = @radius
end
if @y > @window.height - @radius then
@velocity_y = 0
@y = @window.height - @radius
end
if @y < @radius then
@velocity_y = 0
@y = @radius
end
end
end