Microsoft Small Basic

Program Listing: GHP746-3
' Soldier -- By Krueg -- June 2012
' ARROWS to move
' ESCAPE to quit
' GHP746-3
' http://social.msdn.microsoft.com/Forums/en-US/smallbasic/
' thread/e07d592b-af60-426d-898f-d67d205be757

gw = 640 'Window width
gh = 480 'Window Height
gh32 = gh - 32

md = 1
z = 1

IncX = 2
IncY = 1
IncZ = .1

Delay = 10
play = "True"
debug = "False"

SetupWindow()
SetupImages()

Main:
GraphicsWindow.KeyDown = OnKeyDown
GraphicsWindow.KeyUp = OnKeyUp

While play

x = x + dx
y = y + dy
z = z + dz

If z > 4.9 Then
z = 1
EndIf

If x < -32 Then
x = x + 32
ElseIf x > 0 Then
x = x -32
EndIf

If y < -32 Then
y = y + 32
ElseIf y > 0 Then
y = y -32
EndIf

Shapes.Move(background x,y)
Shapes.Move(brickline x,gh32)

zInt = Math.Floor(z)

If mdlast <> md Or mslast <> zInt Then
Shapes.ShowShape(man[md][zInt])
Shapes.HideShape(man[mdlast][mslast])
EndIf

mdlast = md
mslast = zInt

If debug Then
DebugData()
EndIf

Program.Delay(Delay)

EndWhile

Sub OnKeyDown

key = GraphicsWindow.LastKey

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

EndSub

Sub OnKeyUp

key = GraphicsWindow.LastKey

If key = "Right" Or key = "Left" Then
dx = ""
dz = ""
ElseIf key = "Up" Or key = "Down" Then
dy = ""
EndIf

EndSub

Sub SetupWindow
If debug Then
TextWindow.Left = gw + 20
TextWindow.Top = 10
EndIf
GraphicsWindow.Height = gh
GraphicsWindow.Width = gw
GraphicsWindow.Top = 5
GraphicsWindow.Left = 5
GraphicsWindow.BackgroundColor = "Black"
EndSub

Sub SetupImages
'path = Program.Directory + "\"
path = "http://krueg.com/sb/samples/"
manl2 = ImageList.LoadImage(path + "man_l2.png")
manr2 = ImageList.LoadImage(path + "man_r2.png")
background = Shapes.AddImage(ImageList.LoadImage(path + "background.png"))
brickline = Shapes.AddImage(ImageList.LoadImage(path + "brickline.png"))
man[1][1] = Shapes.AddImage(ImageList.LoadImage(path + "man_l1.png"))
man[1][2] = Shapes.AddImage(manl2)
man[1][3] = Shapes.AddImage(ImageList.LoadImage(path + "man_l3.png"))
man[1][4] = Shapes.AddImage(manl2)
man[2][1] = Shapes.AddImage(ImageList.LoadImage(path + "man_r1.png"))
man[2][2] = Shapes.AddImage(manr2)
man[2][3] = Shapes.AddImage(ImageList.LoadImage(path + "man_r3.png"))
man[2][4] = Shapes.AddImage(manr2)
Shapes.Move(brickline, -32,gh-32)
For i = 1 To 4
Shapes.Move(man[1][i],gw/2,gh-80)
Shapes.Zoom(man[1][i],2,2)
Shapes.HideShape(man[1][i])
Shapes.Move(man[2][i],gw/2,gh-80)
Shapes.Zoom(man[2][i],2,2)
Shapes.HideShape(man[2][i])
EndFor
EndSub

Sub DebugData
TextWindow.Clear()
TextWindow.WriteLine("X = " + x + " Y = " + y)
TextWindow.WriteLine("DirectionX = " + dx)
TextWindow.WriteLine("DirectionY = " + dy)
TextWindow.WriteLine("MD = " + md + "Z = " + z)
EndSub