forked from Metalab/elle-and-the-spooky-arrow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharrow.rb
35 lines (31 loc) · 793 Bytes
/
arrow.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
class Arrow
attr_reader :body, :lane
def initialize(screen)
@alive = true
@screen = screen
@speed = 2
@direction = 1
@lane = 0
@body = [
[16 + 2, Proc.new { @lane * 3 + 0 }], [16 + 0, Proc.new { @lane * 3 + 1 }],
[16 + 1, Proc.new { @lane * 3 + 1 }], [16 + 2, Proc.new { @lane * 3 + 1 }],
[16 + 3, Proc.new { @lane * 3 + 1 }], [16 + 2, Proc.new { @lane * 3 + 2 }]
]
end
def die!
@alive = false
end
def update(frame_count)
@lane = [0, 1, 2].sample if frame_count % 15 == 0
@body.each do |el|
el[0] = (el[0] + (@speed * @direction)) % @screen.width
end
end
def draw
if @alive
@body.each do |el|
@screen[el[0], el[1].call] = true
end
end
end
end