Microsoft Small Basic

Program Listing: QZN342
' Turtle Dodger 0.1a
' Copyright (c) 2014 Nonki Takahashi.
'
' License:
' The MIT License (MIT)
' http://opensource.org/licenses/mit-license.php
'
' History:
' 0.1a 2014-04-02 Created.
'
GraphicsWindow.Title = "Turtle Dodger 0.1a"
gw = 598
gh = 428
GraphicsWindow.BackgroundColor = "DodgerBlue"
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
Turtle.Speed = 7
Turtle.PenUp()
color = "1=Orange;2=Cyan;3=Lime;"
size = "1=20;2=16;3=12;"
x = gw / 2
y = gh - 40
Turtle.MoveTo(x, y)
Turtle.Angle = 0
Not = "False=True;True=False;"
moving = "False"
GraphicsWindow.KeyDown = OnKeyDown
tick = "False"
Timer.Interval = 1000 / 24
Timer.Tick = OnTick
lastems = Clock.ElapsedMilliseconds
obj["iMin"] = 1
While "True"
If tick Then
ems = Clock.ElapsedMilliseconds
If ems - lastems > 500 Then
AddObject()
lastems = ems
EndIf
ScrollObject()
tick = "False"
EndIf
EndWhile
Sub OnTick
tick = "True"
EndSub
Sub ScrollObject
iMin = obj["iMin"]
iMax = obj["iMax"]
For i = iMin To iMax
x = obj[i]["x"]
y = obj[i]["y"] + 5
If y > gh Then
Shapes.Remove(obj[i]["obj"])
obj[i] = ""
obj["iMin"] = i + 1
Else
Shapes.Move(obj[i]["obj"], x, y)
obj[i]["x"] = x
obj[i]["y"] = y
EndIf
EndFor
EndSub
Sub AddObject
iMax = obj["iMax"] + 1
obj["iMax"] = iMax
GraphicsWindow.PenWidth = 1
type = Math.GetRandomNumber(3)
obj[iMax]["type"] = type
GraphicsWindow.BrushColor = color[type]
sz = size[type]
obj[iMax]["obj"] = Shapes.AddRectangle(sz, sz)
x = Math.GetRandomNumber(gw - 20) + 10
y = -20
obj[iMax]["x"] = x
obj[iMax]["y"] = y
Shapes.Move(obj[iMax]["obj"], x, y)
Shapes.Rotate(obj[iMax]["obj"], Math.GetRandomNumber(360))
EndSub
Sub OnKeyDown
If Not[moving] Then
moving = "True"
key = GraphicsWindow.LastKey
If key = "Left" Then
Turtle.TurnLeft()
Turtle.Move(30)
Turtle.TurnRight()
ElseIf key = "Right" Then
Turtle.TurnRight()
Turtle.Move(30)
Turtle.TurnLeft()
EndIf
moving = "False"
EndIf
EndSub