Microsoft Small Basic

Program Listing: JDV399
size = 70

sprite = Shapes.AddRectangle(size size)

GraphicsWindow.BrushColor = "Red"
target = Shapes.AddRectangle(size size)
Shapes.Move(target, GraphicsWindow.Width - size, GraphicsWindow.Height - size)

GraphicsWindow.BrushColor = "Black"
targetMessage = Shapes.AddText("Click Me")
Shapes.Move(targetMessage, Shapes.GetLeft(target) + 10, Shapes.GetTop(target) + 10)

targetControl = Controls.AddButton("", Shapes.GetLeft(target), Shapes.GetTop(target))
Controls.SetSize(targetControl size size)
Shapes.SetOpacity(targetControl 0)

Controls.ButtonClicked = OnButtonClicked

'MAIN LOOP
While 0=0
If buttonClicked Then
If Controls.LastClickedButton = targetControl Then
startAnimate = Clock.ElapsedMilliseconds
Shapes.Animate(sprite, Shapes.GetLeft(target), Shapes.GetTop(target), 2000)
Sound.PlayChimes()
EndIf

buttonClicked = "False" 'Once processed - ready for another buttonClick
EndIf

If startAnimate <> "" And Clock.ElapsedMilliseconds - startAnimate > 2000 Then
Shapes.Remove(target)
Shapes.Remove(targetMessage)
Controls.Remove(targetControl)

startAnimate = "" 'flag Off
EndIf

'Delay not needed here BUT takes some load of your CPU
Program.Delay(100)
EndWhile

'Handles button Clicks Only by setting a flag. The Main Loop will Process when buttonClicked = "True"
Sub OnButtonClicked
buttonClicked = "True"
EndSub