-
Notifications
You must be signed in to change notification settings - Fork 0
/
Star Wars.rb
147 lines (122 loc) · 3.96 KB
/
Star Wars.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
require './shapes'
Shoes.app width:800 do
background white
click do |_, *pt|
alert pt.to_s
end
# Darth Vader
arc 100, 100, 100, 100, Shoes::PI, 0
oval 104, 80, 10, 6, fill:aliceblue
oval 80, 80, 10, 6, fill:aliceblue
line 80, 90, 80, 100, stroke:white
line 90, 90, 90, 100, stroke:white
line 100, 90, 100, 100, stroke:white
line 110, 90, 110, 100, stroke:white
rect 80, 100, 40, 20
rect 25, 120, 150, 250
line 45, 120, 35, 400, stroke:white
line 145, 120, 160, 400, stroke:white
rect 45, 370, 30, 40
rect 125, 370, 30, 40
@saber1 = line 60, 220, 60, 100, displace_left: 0, strokewidth: 10, stroke:darkred, cap: :curve
@saber2 = line 60, 220, 60, 102, displace_left: 0, strokewidth: 5, stroke:red, cap: :curve
@fist = oval 40, 220, 35, 30, fill:darkgray
# Yoda
@ears = []
@ears << line(260, 150, 320, 235, strokewidth:10, stroke:red)
@ears << line(260, 150, 320, 220, strokewidth:10, stroke:limegreen, cap: :curve)
@ears << line(260, 150, 320, 250, strokewidth:10, stroke:limegreen, cap: :curve)
@ears << line(440, 150, 380, 235, strokewidth:10, stroke:red)
@ears << line(440, 150, 380, 220, strokewidth:10, stroke:limegreen, cap: :curve)
@ears << line(440, 150, 380, 250, strokewidth:10, stroke:limegreen, cap: :curve)
oval 300, 200, 100, 100, fill:limegreen, stroke:limegreen
oval 320, 250, 10, 10
oval 380, 250, 10, 10
line 340, 220, 360, 220, stroke:aliceblue
line 335, 230, 365, 230, stroke:aliceblue
line 330, 240, 370, 240, stroke:aliceblue
rect 300, 300, 100, 100, fill:brown, stroke:brown
rect 340, 300, 20, 30, fill:black
oval 290, 330, 20, 20, fill:limegreen, stroke:limegreen
oval 400, 330, 20, 20, fill:limegreen, stroke:limegreen
rect 310, 400, 20, 20, fill:limegreen, stroke:limegreen
rect 370, 400, 20, 20, fill:limegreen, stroke:limegreen
# Leia
oval 550, 100, 70, 80, fill:antiquewhite
oval 530, 120, 30, 40, fill:saddlebrown
oval 610, 120, 30, 40, fill:chocolate
oval 570, 130, 6, 3, fill:blue, stroke:blue
oval 590, 130, 6, 3, fill:blue, stroke:blue
para "^", left: 575, top: 135
line 562, 170, 540, 400
line 602, 171, 658, 400
line 540, 400, 658, 400
@leah_saber1 = line 495, 235, 495, 235, displace_left: 0, strokewidth: 10, stroke:fuchsia, cap: :curve
@leah_saber2 = line 495, 245, 495, 245, displace_left: 0, strokewidth: 5, stroke:darkmagenta, cap: :curve
line 494, 232, 561, 184
line 494, 232, 555, 235
oval 484, 230, 20, 20, fill:peachpuff
line 605, 182, 691, 218
line 620, 235, 690, 226
oval 688, 212, 20, 20, fill:bisque
rect 560, 400, 20, 30
rect 620, 400, 20, 30
keypress do |key|
case key
when "d"
move_saber(10)
when "D"
move_saber(-10)
when "y"
move_ears(10)
when "Y"
move_ears(-10)
when "l"
move_leah_saber(20)
when "L"
move_leah_saber(-20)
end
end
def move_saber(value)
return if @animate_saber
@animate_saber = animate do
if (@saber1.left <= 30 && value < 0) || (@saber1.left > 180 && value > 0)
@animate_saber.stop
@animate_saber = nil
else
@saber1.left += value
@saber1.right += value
@saber2.left += value
@saber2.right += value
@fist.left += value
end
end
end
def move_ears(value)
return if @animate_ears
@animate_ears = animate do
if (@ears.first.top > 220 && value > 0) || (@ears.first.top <= 150 && value < 0)
@animate_ears.stop
@animate_ears = nil
else
@ears.each do |ear|
ear.top += value
end
end
end
end
def move_leah_saber(value)
return if @animate_leah
@animate_leah = animate do
if (@leah_saber1.height > 150 && value > 0) || (@leah_saber1.height < 1 && value < 0)
@animate_leah.stop
@animate_leah = nil
else
@leah_saber1.top -= value
@leah_saber1.height += value
@leah_saber2.top -= value
@leah_saber2.height += value
end
end
end
end