GraphicsWindow.Title = "Balloons"
Init()
GraphicsWindow.PenWidth = 0
For i = 1 To n
GraphicsWindow.BrushColor = GraphicsWindow.GetRandomColor()
AddBalloon()
x = Math.GetRandomNumber(gw - 2 * ew) + ew
y = Math.GetRandomNumber(gh / 2 - 2 * eh) + eh
MoveBalloon()
EndFor
GraphicsWindow.MouseDown = OnMouseDown
Timer.Interval = dt * 1000
Timer.Tick = OnTick
While "True"
If mouseDown Then
CheckBalloonClick()
If 0 < balloonClicked Then
v[balloonClicked] = v0
EndIf
mouseDown = "False"
Else
Program.Delay(200)
EndIf
EndWhile
Sub AddBalloon
' param ew - width
' param eh = height
' param i = index
e[i] = Shapes.AddEllipse(ew, eh)
t[i] = Shapes.AddTriangle(0, 0, tw, 0, tw / 2, th)
v[i] = 0
a[i] = 0
EndSub
Sub CheckBalloonClick
balloonClicked = 0
For i = n To 1 Step -1
If ex[i] <= mx And mx <= ex[i] + ew And ey[i] <= my And my <= ey[i] + eh Then
balloonClicked = i
i = 1 ' exit For
ElseIf tx[i] <= mx And mx <= tx[i] + tw And ty[i] <= my And my <= ty[i] + th Then
balloonClicked = i
i = 1 ' exit For
EndIf
EndFor
EndSub
Sub MoveBalloon
' param i - index
' param x, y - position
ex[i] = x - ew / 2
ey[i] = y - eh / 2
Shapes.Move(e[i], ex[i], ey[i])
tx[i] = x - tw / 2
ty[i] = y + th
Shapes.Move(t[i], tx[i], ty[i])
EndSub