-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththief.rb
43 lines (39 loc) · 856 Bytes
/
thief.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
require './piece'
class Thief < Piece
def initialize(game_window)
which = rand(1..4)
if which < 4
image = "thief#{which}"
@points = 300
else
image = 'rex'
@points = 1000
end
super(game_window, "images/#{image}.png")
restart
end
def restart
if (rand(1..2)==1) # left of right
@x = 0
@speed = rand(3..6)
else
@x = @game_window.width
@speed = -1 * rand(3..6)
end
@y = rand(@game_window.width - @icon.width)
end
def update
@x += @speed
# destroy if off screen
if @x > @game_window.width or @x < 0
@destroyed = true
end
end
def hit_by?(obj)
# can only be hit by an player
if obj.is_a? Player and Intersector.intersects(self, obj) and !@destroyed
@game_window.add_points @points
@destroyed = true
end
end
end