Sub OnDataReceived
If Not[moving] Then
dataIn = LDCommPort.RXAll()
key = Text.GetSubText(dataIn, 1, 1)
If Text.IsSubText("AB", key) Then
moving = "True"
EndIf
EndIf
EndSub
Sub OnTick
If Not[scrolling] Then
scrolling = "True"
ems = Clock.ElapsedMilliseconds
If ems - lastems > 500 Then
AddObject()
lastems = ems
EndIf
ScrollObject()
scrolling = "False"
EndIf
If debug Then
x = Math.Floor(Turtle.X)
y = Math.Floor(Turtle.Y)
Shapes.SetText(pos, "(" + x + "," + y + ")")
Shapes.Move(cross1, x, y)
Shapes.Move(cross2, x, y)
EndIf
EndSub
Sub Opening
url = "http://gallery.technet.microsoft.com/Turtle-PNG-Bitmap-for-582b449c/file/116666/1/Turtle.png"
bigTurtle = Shapes.AddImage(url)
Shapes.Move(bigTurtle, 180, 140)
GraphicsWindow.BrushColor = "White"
GraphicsWindow.FontName = "Trebuchet MS"
GraphicsWindow.FontSize = 50
x = (gw - 443) / 2
y = 40
GraphicsWindow.DrawText(x, y, title)
Program.Delay(3000)
GraphicsWindow.Clear()
EndSub
Sub Ready
GraphicsWindow.FontSize = 40
rdy = Shapes.AddText("Ready?")
x = (gw - 130) / 2
y = 100
Shapes.Move(rdy, x, y)
For opacity = 100 To 0 Step -10
Shapes.SetOpacity(rdy, opacity)
Program.Delay(200)
EndFor
Shapes.Remove(rdy)
EndSub
Sub ScrollObject
iMin = obj["iMin"]
iMax = obj["iMax"]
For i = iMin To iMax
x = obj[i]["x"]
y = obj[i]["y"] + 5
tx = Math.Floor(Turtle.X)
ty = Math.Floor(Turtle.Y)
d = Math.SquareRoot(Math.Power(tx - x, 2) + Math.Power(ty - y, 2))
If d < (size[obj[i]["type"]] + 16) / 2 Then
cd = "True" ' collision detected
Goto break
EndIf
If y > gh Then
passed = passed + 1
Shapes.SetText(score, passed)
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
break:
EndSub