forked from Metalab/elle-and-the-spooky-arrow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathguy.rb
38 lines (33 loc) · 743 Bytes
/
guy.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
class Guy
attr_reader :body, :lane
def initialize(screen)
@alive = true
@screen = screen
@speed = 1
@direction = 1
@lane = 0
@body = [
[0, Proc.new { @lane * 3 + 0 }], [1, Proc.new { @lane * 3 + 0 }],
[0, Proc.new { @lane * 3 + 1 }], [0, Proc.new { @lane * 3 + 2 }]
]
end
def die!
@alive = false
end
def update(action)
case action
when :up then @lane = [@lane - 1, 0].max
when :down then @lane = [@lane + 1, 2].min
end
@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