forked from ruby4kids/platformer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhunter.rb
More file actions
50 lines (42 loc) · 857 Bytes
/
hunter.rb
File metadata and controls
50 lines (42 loc) · 857 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
class Hunter
def initialize(game_window, runner,x=nil, y=nil)
@game_window = game_window
@icon = Gosu::Image.new(@game_window, "images/hunter.png", true)
@x = x || rand(@game_window.width)
@y = y || rand(@game_window.height)
@maxspeed = rand(4)+2
@speed = 2
@runner = runner
end
def change_speed
@speed= @speed +1 unless @speed == @maxspeed
end
def x
@x
end
def y
@y
end
def set_x_y
@x = rand(@game_window.width)
@y = rand(@game_window.height)
end
def chase
if @runner.x < @x
@x = @x - @speed
elsif @runner.x > @x
@x = @x + @speed
end
if @runner.y < @y
@y = @y - @speed
elsif @runner.y > @y
@y = @y + @speed
end
end
def cross_screen
@x = @x + @speed
end
def draw
@icon.draw(@x,@y,20)
end
end