Microsoft Small Basic

Program Listing:
Embed this in your website
' Soldier -- By Krueg -- June 2012
' ARROWS to move
' ESCAPE to quit

gw = 640                                    'Window width
gh = 480                                    'Window Height
md = 1
ms = 1
play = "true"
debug = "on?"
SetupWindow()
SetupImages()

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

While play = "true"
  If directionx = "Left" Then
    x = x + 2
    md = 1
    ms = ms + .1
  EndIf
  If directionx = "Right" Then
    x = x - 2
    md = 2
    ms = ms + .1
  EndIf
  If ms > 4.9 Then
    ms =  1
  EndIf
  y = y + directiony
  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,gh-32)
  Shapes.HideShape(man[mdlast][mslast])
  Shapes.ShowShape(man[md][Math.Floor(ms)])
  mdlast = md
  mslast = Math.Floor(ms)
  If debug = "on" Then
    DebugData()
  EndIf
  Program.Delay(10)
EndWhile

Sub OnKeyDown
  key = GraphicsWindow.LastKey
  If key = "Left" Then
    directionx = "Left"
  ElseIf key = "Right" Then
    directionx = "Right"
  ElseIf key = "Up" Then
    directiony = 1
  ElseIf key = "Down" Then
    directiony = -1
  ElseIf key = "Escape" Then
    Program.End()
  EndIf
EndSub

Sub OnKeyUp
  key = GraphicsWindow.LastKey
  If key = "Right" Or key = "Left" Then
    directionx = ""
  ElseIf key = "Up" Or key = "Down" Then
    directiony = ""
  EndIf
EndSub

Sub SetupWindow
  If debug = "on" Then
  TextWindow.Left = gw + 20
  TextWindow.Top = 10
  EndIf
  GraphicsWindow.Height = gh
  GraphicsWindow.Width = gw
  GraphicsWindow.Top = 5
  GraphicsWindow.Left = 5
  GraphicsWindow.BackgroundColor = "Black"
  GraphicsWindow.Show()
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 = " + directionx)
  TextWindow.WriteLine("DirectionY = " + directiony)
  TextWindow.WriteLine("MD = " + md + "MS = " + ms)
EndSub

Copyright (c) Microsoft Corporation. All rights reserved.