Sub Goal_Check
' param x, y - ball position
' param lastx, lasty - ball last position
' return bound - "True" if bound (collision detected)
cx = x + size / 2
cy = y + size / 2
gx = posGoal["x"] ' center x of goal
gy = posGoal["y"] ' center y of goal
distance = Math.SquareRoot(Math.Power(cx - gx, 2) + Math.Power(cy - gy, 2))
If goal = "False" And distance < size / 2 And gy < cy Then
Goal_Show()
nGoal = nGoal + 1
goal = "True"
EndIf
EndSub
Sub Goal_Show
Sound.PlayBellRing()
For i = 0 To 100
Shapes.SetOpacity(oBanner, i)
Program.Delay(10)
EndFor
For i = 100 To 0 Step -1
Shapes.SetOpacity(oBanner, i)
Program.Delay(10)
EndFor
EndSub
Sub Joint_Add
' param id
' param xj[id] - x beam root
' param yj[id] - y beam root
' param lj[id] - length beam
' param aj[id] - angle beam
' return xj[id+1] - x beam front
' return yj[id+1] - y beam front
oLeg[id] = Shapes.AddLine(0, 0, lj[id], 0)
Joint_Move()
EndSub
Sub Joint_Move
' param id
' param xj[id] - x beam root
' param yj[id] - y beam root
' param aj[id] - angle beam
' return xj[id+1] - x beam front
' return yj[id+1] - y beam front
Stack.PushValue("local", x)
Stack.PushValue("local", y)
x = xj[id] + (lj[id] / 2) * Math.Cos(aj[id] * Math.Pi / 180) - (lj[id] / 2)
y = yj[id] + (lj[id] / 2) * Math.Sin(aj[id] * Math.Pi / 180)
Shapes.Move(oLeg[id], x, y)
Shapes.Rotate(oLeg[id], aj[id])
xj[id + 1] = xj[id] + lj[id] * Math.Cos(aj[id] * Math.Pi / 180)
yj[id + 1] = yj[id] + lj[id] * Math.Sin(aj[id] * Math.Pi / 180)
y = Stack.PopValue("local")
x = Stack.PopValue("local")
EndSub
Sub Man_Add
' Man | Add man
' return oMan
xMan = ENDX + 580 + 12 + 28
yMan = FLOORY - 48 * 2
man["num"] = man["num"] + 1
oMan = "Man" + man["num"]
man[oMan + ".x"] = xMan
man[oMan + ".y"] = yMan
GraphicsWindow.BrushColor = "Black"
GraphicsWindow.PenColor = "Black"
oHead = Shapes.AddEllipse(24, 24)
man[oMan + ".oHead"] = oHead
Shapes.Move(oHead, xMan - 12, yMan - 84)
oBody = Shapes.AddLine(0, 0, 0, 48)
man[oMan + ".oBody"] = oBody
Shapes.Move(oBody, xMan, yMan - 48)
GraphicsWindow.PenColor = "Black"
id = 10 ' for arm
xj[id] = xMan
yj[id] = yMan - 48
al = "1=60;2=90;3=-45;4=-15;"
ll = "1=36;2=36;3=9;4=12;"
Man_AddLimb()
id = 20 ' for leg
xj[id] = xMan
yj[id] = yMan
al = "1=100;2=-20;3=100;4=0;"
ll = "1=48;2=48;3=21;4=7;"
Man_AddLimb()
EndSub
Sub Man_AddLimb
' param id - limb id
' param al[] - angle of joints
' param ll[] - length of linterjoint
Stack.PushValue("local", id)
For i = 1 To 4
lj[id] = ll[i] ' length
Joint_Add()
id = id + 1
EndFor
id = Stack.PopValue("local")
Man_MoveLimb()
EndSub
Sub Man_Catch
' Man | Catch ball
' param oBall
' param oMan
' param x, y - top left positon of ball
EndSub
Sub Man_Hold
' Man | Hold ball
' param oBall
' param oMan
x = man[oMan + ".x"] - 48
y = man[oMan + ".y"] - 48
Ball_Move()
id = 10 ' for arm
al = "1=85;2=120;3=90;4=-20;"
Man_MoveLimb()
EndSub
Sub Man_MoveLimb
' param id - id limb
' param al[] - angle of joints
Stack.PushValue("local", id)
aj[id] = al[1] ' angle
Joint_Move()
id = id + 1
For i = 2 To 4
aj[id] = aj[id - 1] + al[i] ' angle
Joint_Move()
id = id + 1
EndFor
id = Stack.PopValue("local")
EndSub
Sub Man_Throw
' Man | Throw ball
' param oBall
' param oMan
size = ball[oBall + ".size"]
x = man[oMan + ".x"] - 48
y = FLOORY - 144 - size
Ball_Move()
id = 10 ' for arm
al = "1=120;2=120;3=110;4=-40;"
Man_MoveLimb()
Program.Delay(500)
x = man[oMan + ".x"] - 48
y = FLOORY - 192 - 12
Ball_Move()
id = 10 ' for arm
al = "1=180;2=80;3=100;4=-40;"
Man_MoveLimb()
Program.Delay(1000)
id = 10 ' for arm
al[3] = -45
Man_MoveLimb()
g = 9.80665 ' acceleration of gravity [m/s^2]
y0 = y
x0 = x
v0_ = Controls.GetTextBoxText(oVelocity) ' [km/h]
v0 = v0_ * 1000 / 3600 ' [m/s]
angle = Controls.GetTextBoxText(oAngle) ' [degree]
v0x = v0 * Math.Cos(angle * Math.Pi / 180)
v0y = v0 * Math.Sin(angle * Math.Pi / 180)
a = ball[oBall + ".angle"]
da = 10 ' [degree]
dt = 0.01 ' [s]
vy = v0y
vx = v0x
goal = "False"
For t = 0.1 To 30.0 Step dt ' [s]
a = a + da
angle = a
Ball_Rotate()
vy = vy - g * dt / 2 ' velocity [m/s]
lasty = y
lastx = x
y = y - (vy * dt) * 100 ' vertical position [cm]
x = x - (vx * dt) * 100 ' horizontal position [cm]
If x < -24 Or 950 < x Then
y = FLOORY - size
Goto exit_throw
EndIf
If FLOORY - size < y Then ' bounds on the floor
y = FLOORY - size
't = 0
y0 = y
x0 = x
vy = -vy * Math.SquareRoot(1.3 / 1.8)
If vy < 0.1 Then
Goto exit_throw
EndIf
da = -vx * dt * 100 * 360 / Math.Pi / size
EndIf
Goal_BoundOnRing()
If bound Then
Goto move_ball
EndIf
Goal_BoundOnBoard()
If bound Then
Goto move_ball
EndIf
Goal_BoundOnFlange()
If bound Then
Goto move_ball
EndIf
Goal_Check()
move_ball:
Ball_Move()
If Math.Remainder(t * 100, 10) = 0 Then
GraphicsWindow.BrushColor = "Gray"
GraphicsWindow.FillEllipse(x, y, size, size)
EndIf
Program.Delay(10)
EndFor
exit_throw:
id = 10 ' for arm
al = "1=60;2=90;3=-45;4=-15;"
Man_MoveLimb()
EndSub