Microsoft Small Basic

Program Listing: KQZ622
' Animation Layer Test
' by GoToLoop (2012/Oct)

' http://social.msdn.microsoft.com/Forums/en-US/smallbasic
'/thread/94015515-5579-4463-b885-9d77ec11b2cb

GraphicsWindow.Width = 300
GraphicsWindow.Height = 200
GraphicsWindow.BackgroundColor = "Black"

InitVars()
CreateShapes()

Timer.Tick = AnimateShapes
Timer.Interval = 1000/fps

GraphicsWindow.TextInput = KeyPressed
GraphicsWindow.MouseDown = MousePressed

Sub InitVars

gw = GraphicsWindow.Width
gh = GraphicsWindow.Height

gwH = gw/2
ghH = gh/2

fps = 40
mv = 4

sz = 40
szH = sz/2

sqrX = gwH
sqrY = ghH

crlX = gwH
crlY = ghH

trgX = gwH
trgY = ghH

EndSub

Sub CreateShapes

GraphicsWindow.BrushColor = "Red"
square = Shapes.AddRectangle(sz,sz)

GraphicsWindow.BrushColor = "Green"
circle = Shapes.AddEllipse(sz,sz)

GraphicsWindow.BrushColor = "Blue"
triangle = Shapes.AddTriangle(szH,0 0,sz sz,sz)

EndSub

Sub AnimateShapes

sqrX = Math.Remainder(sqrX+mv gw)
crlY = Math.Remainder(crlY+mv gh)
trgX = Math.Remainder(trgX+mv gw)
trgY = Math.Remainder(trgY+mv gh)

Shapes.Move(square sqrX,sqrY)
Shapes.Move(circle crlX,crlY)
Shapes.Move(triangle trgX,trgY)

EndSub

Sub KeyPressed

If GraphicsWindow.LastKey = "Escape" Then
Sound.PlayChimeAndWait()
Program.End()
ElseIf isPaused Then
isPaused = "False"
Timer.Resume()
Else
isPaused = "True"
Timer.Pause()
EndIf

Sound.PlayClick()

EndSub

Sub MousePressed

KeyPressed()

EndSub