-
Notifications
You must be signed in to change notification settings - Fork 4
/
test.ms
212 lines (162 loc) · 4.27 KB
/
test.ms
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
import "physics"
import "shapes"
import "debugDraw"
import "mathUtil"
debugDrawEnabled = false
clear
display(5).clear color.gray
sprDisp = display(4)
control = null
createBlock = function(x, y, tint, scale=1, rotation=0)
body = new Sprite
body.image = file.loadImage("/sys/pics/Block4.png")
body.scale = scale
body.tint = tint
body.x = x
body.y = y
body.rotation = rotation
physics.initPhys body
sprDisp.sprites.push body
return body
end function
createCircle = function(x, y, tint, scale=1)
body = new Sprite
body.image = file.loadImage("./circle.png")
body.scale = scale
body.tint = tint
body.x = x
body.y = y
physics.initPhys body, shapes.Circle(32 * scale)
sprDisp.sprites.push body
return body
end function
createWalls = function
b = createBlock(480, -75, color.yellow, 4)
b.setStatic true
l = createBlock(-130, 480, color.yellow, 4, 90)
l.setStatic true
r = createBlock(1090, 480, color.yellow, 4, 90)
r.setStatic true
return { "bottom": b, "left": l, "right": r }
end function
scenarioBalls = function
createWalls
debugDrawEnabled = false
for i in range(25)
clr = color.rgb(rnd * 255, rnd * 255, rnd * 255)
createCircle display(5).width * rnd, display(5).height * rnd, clr, 1
end for
end function
scenarioBallsCollision = function
createWalls
c = createCircle(300, 500, color.yellow)
c.vel[0] = 200
c = createCircle(600, 500, color.green)
c.vel[0] = -200
globals.control = c
end function
scenarioBallSlope = function
b = createBlock(400, 400, color.blue, 1, -20)
b.setStatic true
b = createBlock(620, 200, color.blue, 1, 20)
b.setStatic true
globals.control = createCircle(350, 500, color.yellow, 1)
end function
scenarioOneBall = function
walls = createWalls
walls.left.elasticity = 1
walls.right.elasticity = 1
c = createCircle(600, 300, color.green)
c.vel[0] = -500
c.elasticity = 1
globals.control = c
end function
scenarioSqueeze = function
b = createBlock(480, -75, color.yellow, 4)
b.setStatic true
b = createBlock(300, 480, color.yellow, 4)
b.rotation = 90
b.setStatic true
b = createBlock(700, 480, color.yellow, 4)
b.rotation = 90
b.setStatic true
createCircle 495, 300, color.green
createCircle 498, 400, color.orange
createCircle 492, 500, color.red
end function
scenarioDragRace = function
createWalls
balls = 10
for i in range(balls - 1)
clr = color.rgb(rnd * 255, rnd * 255, rnd * 255)
createCircle display(5).width * (i / balls) + 50, 600, clr, 1 - (i / balls) * 0.5
end for
end function
scenarioCannonBall = function
createWalls
impulse = 1500
c = createCircle(100, 400, color.green, 1)
c.vel[0] = impulse
c = createCircle(100, 500, color.red, 1)
c.vel[0] = impulse
c.dragCoef = 0
end function
scenarioTestCollisions = function
globals.debugDrawEnabled = true
physics.gravity = 0
physics.enableCollisionResponse = false
b = createBlock(400, 200, color.blue, 2, 20)
globals.control = createBlock(400, 400, color.yellow)
end function
scenarioStacking = function
createWalls
createBlock 700, 150, color.red
createBlock 500, 350, color.yellow, 1.25
globals.control = createBlock(300, 550, color.green, 1.5, 25)
end function
scenarioBat = function
physics.gravity = 0
bat = createBlock(200, 300, color.blue, 2)
bat.rotSpeed = mathUtil.degToRad(-60)
createCircle 300, 500, color.yellow
end function
scenarioBallTorque = function
walls = createWalls
circle = createCircle(200, 100, color.red)
circle.vel[0] = 300
end function
demos = [
["Balls", @scenarioBalls],
["Balls Collision", @scenarioBallsCollision],
["Ball Slope", @scenarioBallSlope],
["One Ball", @scenarioOneBall],
["Squeeze", @scenarioSqueeze],
["Drag Race", @scenarioDragRace],
["Cannon Ball", @scenarioCannonBall],
["Test Collisions", @scenarioTestCollisions],
["Stacking", @scenarioStacking],
["Bat", @scenarioBat]]
for i in demos.indexes
print (i+1) + ". " + demos[i][0]
end for
print
choice = input("Select demo: ").val - 1
scenario = @demos[choice][1]
scenario
dt = 1/60
while not key.available
physics.updateMany sprDisp.sprites, dt
if control != null then
if mouse.button(0) then
control.x = mouse.x
control.y = mouse.y
control.vel[0] = 0
control.vel[1] = 0
end if
if mouse.button(1) then
control.rotation = control.rotation + 1
end if
end if
yield
end while
key.clear