forked from ruby4kids/jump
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjump.rb
More file actions
45 lines (39 loc) · 775 Bytes
/
Copy pathjump.rb
File metadata and controls
45 lines (39 loc) · 775 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
module Jump
def update_jump
if @jumping
if @go_up
handle_up_motion
elsif @go_down
handle_down_motion
end
end
end
def handle_up_motion
if @go_down_at < Time.now.to_f
@go_down = true
@go_up = false
else
if @y < 0
@y = 0
else
@y = @y - 10
end
end
end
def handle_down_motion
if (current_platform = @game_window.find_platform(self))
@y = current_platform.top - @icon.height + current_platform.height
@jumping = false
else
@y = @y + 10
end
end
def jump
unless @jumping
@go_up = true
@jumping = true
@go_down_at = (Time.now.to_f + 0.3)
@end_jump_at = @go_down_at + 0.3
end
end
end