Microsoft Small Basic

Program Listing: CVK888-1
' Scrolling Background -- By Krueg -- June 2012
' Use ARROWS to move
' ESCAPE to quit
' CVK888-1
' http://social.msdn.microsoft.com/Forums/en-US/smallbasic
' /thread/c9b72dd3-95b4-4304-a777-8c583e93c552

gw = 640 'Window Width
gh = 480 'Window Height
GraphicsWindow.Height = gh
GraphicsWindow.Width = gw
GraphicsWindow.Top = 5
GraphicsWindow.Left = 5
GraphicsWindow.BackgroundColor = "Black"

path = Program.Directory + "\"
path = "http://krueg.com/sb/samples/"

sea = ImageList.LoadImage(path + "sea.png")

seaW = ImageList.GetWidthOfImage (sea)
seaH = ImageList.GetHeightOfImage (sea)

If seaW < gw Then
seaW = gw + 64
EndIf

If seaH < gh Then
seaH = gh + 64
EndIf

LimX = seaW - gw
LimY = seaH - gh

IncX = 2
IncY = 1.5

sea = Shapes.AddImage(sea)

GraphicsWindow.KeyDown = OnKeyDown
GraphicsWindow.KeyUp = OnKeyUp

Loop:

x = x + dx
y = y + dy

If x < -LimX Then
x = -1
ElseIf x > 0 Then
x = -LimX - 1
EndIf

If y < -LimY Then
y = -1
ElseIf y > 0 Then
y = -LimY - 1
EndIf

Shapes.Move(sea x,y)
Program.Delay(5)

Goto Loop

Sub OnKeyDown

key = GraphicsWindow.LastKey

If key = "Left" Then
dx = IncX
ElseIf key = "Right" Then
dx = -IncX
ElseIf key = "Up" Then
dy = IncY
ElseIf key = "Down" Then
dy = -IncY
ElseIf key = "Escape" Then
Program.End()
EndIf

EndSub

Sub OnKeyUp

dx = 0
dy = 0

EndSub