'Main loop - just move the ball
t = Clock.ElapsedMilliseconds
While ("True")
processKey()
If bullet <> "" Then
bx = Shapes.GetLeft(bullet)
by = Shapes.GetTop(bullet)
Shapes.Move(bullet, bx - 10, by)
EndIf
'Key press event subroutines
'A separate Down and Up is checked for each key, this tells us the state for any key
'And isn't affected by auto-repeat delays for keys
Sub OnKeyDown
lastKey = GraphicsWindow.LastKey
If(lastKey = "Up") Then
keyUp = 1
ElseIf(lastKey = "Down") Then
keyDown = 1
ElseIf(lastKey="Space")Then
KeySpace =1
EndIf
EndSub
Sub OnKeyUp
lastKey = GraphicsWindow.LastKey
If(lastKey = "Up") Then
keyUp = 0
ElseIf(lastKey = "Down") Then
keyDown = 0
Elseif (lastKey="Space")Then
KeySpace=0
EndIf
EndSub
Sub processKey
randNum = Math.GetRandomNumber(400)
If KeySpace=1 And bullet = "" Then
bullet=Shapes.AddEllipse(20,20)
Shapes.Move(bullet,gw,CannonY-6)
EndIf
'Check for hitting edges
If (CannonY < 0) Then
CannonY = -CannonY
BoomY=-BoomY
EndIf
If (Cannon > gh) Then
CannonY = -CannonY
BoomY=-BoomY
EndIf
If t + 500 < Clock.ElapsedMilliseconds Then
Shapes.Animate(balloon,10,randNum,500)
t = Clock.ElapsedMilliseconds
EndIf
EndSub
Sub Collison
Ball_Amount=2
If bullet <> "" Then
Bullet_X=Shapes.GetLeft(bullet) + 10
Bullet_Y=Shapes.GetTop(bullet) + 10
Balloon_X=Shapes.GetLeft(balloon) + 25
Balloon_Y=Shapes.GetTop(balloon) + 25
dx = Balloon_X - Bullet_X
dy = Balloon_Y - Bullet_Y
d = Math.SquareRoot(dx * dx + dy * dy)
If d < 35 Then
Sound.PlayClick()
GraphicsWindow.DrawText(Bullet_X, Bullet_Y, "Hello")
Shapes.Remove(bullet)
bullet = ""
ElseIf Bullet_X < 0 Then
Shapes.Remove(bullet)
bullet = ""
EndIf
EndIf
EndSub