-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrunner.rb
More file actions
58 lines (50 loc) · 988 Bytes
/
runner.rb
File metadata and controls
58 lines (50 loc) · 988 Bytes
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
class Runner
def initialize(game_window)
@game_window = game_window
@icon = Gosu::Image.new(@game_window, "images/runner.png", true)
@x = rand(game_window.width)
@y = rand(game_window.height)
@speed = 10
end
def x
@x
end
def y
@y
end
def draw
@icon.draw(@x,@y,1)
end
def move_left
if @x <= 0
@x = 0
else
@x = @x - @speed
end
end
def touch?(hunters, wall)
hunters.any? {|h| Gosu::distance(@x, @y, h.x, h.y) < 10} or
wall.any? {|h| Gosu::distance(@x, @y, h.x, h.y) < 10}
end
def move_right
if @x >=(@game_window.width - @icon.width)
@x = @game_window.width - @icon.width
else
@x = @x + @speed
end
end
def move_up
if @y <= 0
@y = 0
else
@y = @y - @speed
end
end
def move_down
if @y >= (@game_window.height-@icon.height)
@y = @game_window.height - @icon.height
else
@y = @y + @speed
end
end
end