Microsoft Small Basic

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

' Credit goes to GoToLoop, NaochanON, and litedev for helping to make this program better.
' Thank You for your suggestions!

debug = "unTrue"
SetupVariables()
SetupWindow()
SetupImages()
StartGameHere:
ShowIntro()
StartLevel:
LoadLevel()
GraphicsWindow.KeyDown = OnKeyDown
GraphicsWindow.KeyUp   = OnKeyUp

While lives > 0                             'This is the main loop
  '---------------------------------------------------------------------------------Calculate the jump direction and speed
  If Jump Then
    ManY = ManY + JumpCurentSpeed           'Adjust ManY for the jump
    If JumpCurentSpeed < JumpPower Then     'The man will only fall this fast
      JumpCurentSpeed = JumpCurentSpeed + JumpInc     'Add for gravity
    EndIf
  EndIf
  If ManY > gh-64 Then                      'The man landed on the bottom of the screen
    HitSpike()
  ElseIf ManY < 32 Then                     'The man hit the roof
    JumpCurentSpeed = .4
  EndIf

  '---------------------------------------------------------------------------------Falling off platforms, check for stars, hearts, and spikes
  If ManY = pfy5-64 And Jump = "" Then      'Check conditions of the bottom row of platforms
    If (pf5[pfx] > 0 And pf5[pfx] < 50) Or (pf5[pfx-1] > 0 And pf5[pfx-1] < 50) Or (pf5[pfx-2] > 0 And pf5[pfx-2] < 50) Or (pf5[pfx-3] > 0 And pf5[pfx-3] < 50) Or (pf5[pfx-4] > 0 And pf5[pfx-4] < 50) Then
    Else
      Jump = "True"
      JumpCurentSpeed = JumpInc
    EndIf
    If pf5[pfx] > 50 And pf5[pfx] < 70 Then 'Did the man hit a star?
      Sound.PlayMusic(TuneStar)
      Shapes.Move(star[pf5[pfx]],-32,pfy5)
      pf5[pfx] = ""
      Score = Score + 10
      StarCount = StarCount + 1
    ElseIf pf5[pfx] > 70 And pf5[pfx] < 80 Then 'Did the man hit a heart?
      Sound.PlayMusic(TuneHeart)
      Shapes.Move(heart[pf5[pfx]],-32,pfy5)
      pf5[pfx] = ""
      lives = lives + 1
    ElseIf pf5[pfx] > 80 And pf5[pfx] < 100 Then 'Did the man hit a spike?
      HitSpike()
    ElseIf pf5[pfx-1] = 119 Then            'Did the man hit the exit?
      Sound.PlayMusic("O5 C8 C8 E4")
      Program.Delay(1000)
      ResetImages()
      level = level + 1
      Goto StartLevel
    EndIf
  ElseIf ManY = pfy4-64 And Jump = "" Then  'Check conditions of the fourth row of platforms
    If (pf4[pfx] > 0 And pf4[pfx] < 50) Or (pf4[pfx-1] > 0 And pf4[pfx-1] < 50) Or (pf4[pfx-2] > 0 And pf4[pfx-2] < 50) Or (pf4[pfx-3] > 0 And pf4[pfx-3] < 50) Or (pf4[pfx-4] > 0 And pf4[pfx-4] < 50) Then
    Else
      Jump = "True"
      JumpCurentSpeed = JumpInc
    EndIf
    If pf4[pfx] > 50 And pf4[pfx] < 70 Then 'Did the man hit a star?
      Sound.PlayMusic(TuneStar)
      Shapes.Move(star[pf4[pfx]],-32,pfy4)
      pf4[pfx] = ""
      Score = Score + 10
      StarCount = StarCount + 1
    ElseIf pf4[pfx] > 70 And pf4[pfx] < 80 Then 'Did the man hit a heart?
      Sound.PlayMusic(TuneHeart)
      Shapes.Move(heart[pf4[pfx]],-32,pfy4)
      pf4[pfx] = ""
      lives = lives + 1
    ElseIf pf4[pfx] > 80 And pf4[pfx] < 100 Then 'Did the man hit a spike?
      HitSpike()
    EndIf
  ElseIf ManY = pfy3-64 And Jump = "" Then  'Check conditions of the third row of platforms
    If (pf3[pfx] > 0 And pf3[pfx] < 50) Or (pf3[pfx-1] > 0 And pf3[pfx-1] < 50) Or (pf3[pfx-2] > 0 And pf3[pfx-2] < 50) Or (pf3[pfx-3] > 0 And pf3[pfx-3] < 50) Or (pf3[pfx-4] > 0 And pf3[pfx-4] < 50) Then
    Else
      Jump = "True"
      JumpCurentSpeed = JumpInc
    EndIf
    If pf3[pfx] > 50 And pf3[pfx] < 70 Then 'Did the man hit a star?
      Sound.PlayMusic(TuneStar)
      Shapes.Move(star[pf3[pfx]],-32,pfy3)
      pf3[pfx] = ""
      Score = Score + 10
      StarCount = StarCount + 1
    ElseIf pf3[pfx] > 70 And pf3[pfx] < 80 Then 'Did the man hit a heart?
      Sound.PlayMusic(TuneHeart)
      Shapes.Move(heart[pf3[pfx]],-32,pfy3)
      pf3[pfx] = ""
      lives = lives + 1
    ElseIf pf3[pfx] > 80 And pf3[pfx] < 100 Then 'Did the man hit a spike?
      HitSpike()
    EndIf
  ElseIf ManY = pfy2-64 And Jump = "" Then  'Check conditions of the second row of platforms
    If (pf2[pfx] > 0 And pf2[pfx] < 50) Or (pf2[pfx-1] > 0 And pf2[pfx-1] < 50) Or (pf2[pfx-2] > 0 And pf2[pfx-2] < 50) Or (pf2[pfx-3] > 0 And pf2[pfx-3] < 50) Or (pf2[pfx-4] > 0 And pf2[pfx-4] < 50) Then
    Else
      Jump = "True"
      JumpCurentSpeed = JumpInc
    EndIf
    If pf2[pfx] > 50 And pf2[pfx] < 70 Then 'Did the man hit a star?
      Sound.PlayMusic(TuneStar)
      Shapes.Move(star[pf2[pfx]],-32,pfy2)
      pf2[pfx] = ""
      Score = Score + 10
      StarCount = StarCount + 1
    ElseIf pf2[pfx] > 70 And pf2[pfx] < 80 Then 'Did the man hit a heart?
      Sound.PlayMusic(TuneHeart)
      Shapes.Move(heart[pf2[pfx]],-32,pfy2)
      pf2[pfx] = ""
      lives = lives + 1
    ElseIf pf2[pfx] > 80 And pf2[pfx] < 100 Then 'Did the man hit a spike?
      HitSpike()
    EndIf
  ElseIf ManY = pfy1-64 And Jump = "" Then  'Check conditions of the first row of platforms
    If (pf1[pfx] > 0 And pf1[pfx] < 50) Or (pf1[pfx-1] > 0 And pf1[pfx-1] < 50) Or (pf1[pfx-2] > 0 And pf1[pfx-2] < 50) Or (pf1[pfx-3] > 0 And pf1[pfx-3] < 50) Or (pf1[pfx-4] > 0 And pf1[pfx-4] < 50) Then
    Else
      Jump = "True"
      JumpCurentSpeed = JumpInc
    EndIf
    If pf1[pfx] > 50 And pf1[pfx] < 70 Then 'Did the man hit a star?
      Sound.PlayMusic(TuneStar)
      Shapes.Move(star[pf1[pfx]],-32,pfy1)
      pf1[pfx] = ""
      Score = Score + 10
      StarCount = StarCount + 1
    ElseIf pf1[pfx] > 70 And pf1[pfx] < 80 Then 'Did the man hit a heart?
      Sound.PlayMusic(TuneHeart)
      Shapes.Move(heart[pf1[pfx]],-32,pfy1)
      pf1[pfx] = ""
      lives = lives + 1
    ElseIf pf1[pfx] > 80 And pf1[pfx] < 100 Then 'Did the man hit a spike?
      HitSpike()
    EndIf
  EndIf

  '---------------------------------------------------------------------------------Landing on platforms
  If JumpCurentSpeed > 0 And ManY < pfy5-32 And ManY > pfy5-64 Then
    If (pf5[pfx] > 0 And pf5[pfx] < 50) Or (pf5[pfx-1] > 0 And pf5[pfx-1] < 50) Or (pf5[pfx-2] > 0 And pf5[pfx-2] < 50) Or (pf5[pfx-3] > 0 And pf5[pfx-3] < 50) Or (pf5[pfx-4] > 0 And pf5[pfx-4] < 50) Then
      Jump = ""
      ManY = pfy5-64
    EndIf
  ElseIf JumpCurentSpeed > 0 And ManY < pfy4-32 And ManY > pfy4-64 Then
    If (pf4[pfx] > 0 And pf4[pfx] < 50) Or (pf4[pfx-1] > 0 And pf4[pfx-1] < 50) Or (pf4[pfx-2] > 0 And pf4[pfx-2] < 50) Or (pf4[pfx-3] > 0 And pf4[pfx-3] < 50) Or (pf4[pfx-4] > 0 And pf4[pfx-4] < 50) Then
      Jump = ""
      ManY = pfy4-64
    EndIf
  ElseIf JumpCurentSpeed > 0 And ManY < pfy3-32 And ManY > pfy3-64 Then
    If (pf3[pfx] > 0 And pf3[pfx] < 50) Or (pf3[pfx-1] > 0 And pf3[pfx-1] < 50) Or (pf3[pfx-2] > 0 And pf3[pfx-2] < 50) Or (pf3[pfx-3] > 0 And pf3[pfx-3] < 50) Or (pf3[pfx-4] > 0 And pf3[pfx-4] < 50) Then
      Jump = ""
      ManY = pfy3-64
    EndIf
  ElseIf JumpCurentSpeed > 0 And ManY < pfy2-32 And ManY > pfy2-64 Then
    If (pf2[pfx] > 0 And pf2[pfx] < 50) Or (pf2[pfx-1] > 0 And pf2[pfx-1] < 50) Or (pf2[pfx-2] > 0 And pf2[pfx-2] < 50) Or (pf2[pfx-3] > 0 And pf2[pfx-3] < 50) Or (pf2[pfx-4] > 0 And pf2[pfx-4] < 50) Then
      Jump = ""
      ManY = pfy2-64
    EndIf
  ElseIf JumpCurentSpeed > 0 And ManY < pfy1-32 And ManY > pfy1-64 Then
    If (pf1[pfx] > 0 And pf1[pfx] < 50) Or (pf1[pfx-1] > 0 And pf1[pfx-1] < 50) Or (pf1[pfx-2] > 0 And pf1[pfx-2] < 50) Or (pf1[pfx-3] > 0 And pf1[pfx-3] < 50) Or (pf1[pfx-4] > 0 And pf1[pfx-4] < 50) Then
      Jump = ""
      ManY = pfy1-64
    EndIf
  EndIf

  'If pfx < 0 Then 'Routine to wrap the playfield.
  ' pfx = pfx + pfw - 25 'The first 25 steps in the array
  'ElseIf pfx > pfw Then 'must match the last 25 steps
  ' pfx = pfx - pfw + 25 'in the SetupPlayField routine.
  'EndIf
  '---------------------------------------------------------------------------------Show playfield from array
  For i = 1 To 30
    pfxt = pfx-18+i
    t = i * 32 - 160 + bgx
    pftest = pf1[pfxt]                      'Show playfield line 1
    If pftest <> "" Then
      If pftest < 50 Then
        Shapes.Move(brick[pftest],t,pfy1)
      ElseIf pftest > 50 and pftest < 70 Then
        Shapes.Move(star[pftest],t,pfy1-32)
      ElseIf pftest > 70 and pftest < 80 Then
        Shapes.Move(heart[pftest],t,pfy1-32)
      ElseIf pftest > 80 and pftest < 100 Then
        Shapes.Move(spike[pftest],t,pfy1-32)
      EndIf
    EndIf
    pftest = pf2[pfxt]                      'Show playfield line 2
    If pftest <> "" Then
      If pftest < 50 Then
        Shapes.Move(brick[pftest],t,pfy2)
      ElseIf pftest > 50 and pftest < 70 Then
        Shapes.Move(star[pftest],t,pfy2-32)
      ElseIf pftest > 70 and pftest < 80 Then
        Shapes.Move(heart[pftest],t,pfy2-32)
      ElseIf pftest > 80 and pftest < 100 Then
        Shapes.Move(spike[pftest],t,pfy2-32)
      EndIf
    EndIf
    pftest = pf3[pfxt]                      'Show playfield line 3
    If pftest <> "" Then
      If pftest < 50 Then
        Shapes.Move(brick[pftest],t,pfy3)
      ElseIf pftest > 50 and pftest < 70 Then
        Shapes.Move(star[pftest],t,pfy3-32)
      ElseIf pftest > 70 and pftest < 80 Then
        Shapes.Move(heart[pftest],t,pfy3-32)
      ElseIf pftest > 80 and pftest < 100 Then
        Shapes.Move(spike[pftest],t,pfy3-32)
      EndIf
    EndIf
    pftest = pf4[pfxt]                      'Show playfield line 4
    If pftest <> "" Then
      If pftest < 50 Then
        Shapes.Move(brick[pftest],t,pfy4)
      ElseIf pftest > 50 and pftest < 70 Then
        Shapes.Move(star[pftest],t,pfy4-32)
      ElseIf pftest > 70 and pftest < 80 Then
        Shapes.Move(heart[pftest],t,pfy4-32)
      ElseIf pftest > 80 and pftest < 100 Then
        Shapes.Move(spike[pftest],t,pfy4-32)
      EndIf
    EndIf
    pftest = pf5[pfxt]                      'Show playfield line 5 this is the ground
    If pftest <> "" Then
      If pftest < 50 Then
        Shapes.Move(ground[pftest],t,pfy5)
      ElseIf pftest > 50 and pftest < 70 Then
        Shapes.Move(star[pftest],t,pfy5-32)
      ElseIf pftest > 70 and pftest < 80 Then
        Shapes.Move(heart[pftest],t,pfy5-32)
      ElseIf pftest > 80 and pftest < 100 Then
        Shapes.Move(spike[pftest],t,pfy5-32)
      ElseIf pftest > 100 and pftest < 110 Then
        Shapes.Move(icon[pftest],t,pfy5-32)
      ElseIf pftest > 110 and pftest < 120 Then
        Shapes.Move(icon[pftest],t,pfy5-99)
      EndIf
    EndIf
  EndFor
  '----------------------------------------------------------------------------Calculate and move background and roofline
  bgx = bgx + bgInc                         'Add the increment to the background X position
  If bgx < - 32 Then                        'Background images repeat every 32 pixels
    bgx = bgx + 32
    pfx = pfx + 1                           'Move right on the playfield array
  ElseIf bgx > 0 Then
    bgx = bgx - 32
    pfx = pfx - 1                           'Move left on the playfield array
  EndIf
  Shapes.Move(background,bgx,bgy)
  Shapes.Move(roofline,bgx,bgy)
  '----------------------------------------------------------------------------Generate animation for the man
  ManSlide = ManSlide + ManIncIs
  If ManSlide > 4.9   Then
    ManSlide =  1
  EndIf
  ManSlideFloor = Math.Floor(ManSlide)
  If ManDirLast <> ManDir Or ManSlideFloorLast <> ManSlideFloor Then
    Shapes.Move(Man[ManDir][ManSlideFloor],ManX,ManY)
    Shapes.ShowShape(man[ManDir][ManSlideFloor])
    Shapes.HideShape(man[ManDirLast][ManSlideFloorLast])
  EndIf
  If Jump Then
    Shapes.Move(man[ManDir][ManSlideFloor],ManX,ManY)
  EndIf
  ManDirLast = ManDir
  ManSlideFloorLast = ManSlideFloor

  '----------------------------------------------------------------------------Score board
  GraphicsWindow.Title = "RUN Little Soldier Dude, RUN! ---- Score = " + Score + " ---- Stars = " + StarCount + " ---- Lives = " + lives + " ---- Level = " + level
  While Clock.ElapsedMilliseconds < fps     'Wait here to create a consistant frames per second
  EndWhile
  fps = Clock.ElapsedMilliseconds + delay   'Calculate the time to wait for frames per second
  If debug Then
    DebugData()
  EndIf
EndWhile                                    'End of main loop
Sound.PlayMusic("O5 C8 C8 C8 O4 G4")

Sub HitSpike                                'The man hit a spike routine
  Sound.PlayMusic(TuneSpike)
  Jump = "True"
  JumpCurentSpeed = -JumpPower / 2          'Give the man a half jump
  lives = lives - 1                         'Take away one life
EndSub

Sub OnKeyDown
  key = GraphicsWindow.LastKey
  If key = "Left" Then                      'Left arrow was pressed
    bgInc = speed                           'Background increment to the right
    ManDir = 1                              'The man array for showing his left side
    ManIncIs = ManInc                       'The increment for the man walking animation
  ElseIf key = "Right"  Then                'Right arrow was pressed
    bgInc = -speed                          'Background increment to the left
    ManDir = 2                              'The man array for showing his right side
    ManIncIs = ManInc                       'The increment for the man walking animation
  ElseIf (key = "Up" or key = "Space") And Jump <> "True" Then
    Jump = "True"                           'Turn on the Jump flag
    JumpCurentSpeed = -JumpPower            'Get the man momentum for the jump
  ElseIf key = "Escape" Then                'Escape was pressed to quit
    Program.End()
  EndIf
EndSub

Sub OnKeyUp
  key = GraphicsWindow.LastKey
  If key = "Right" Or key = "Left" Then
    bgInc = 0
    ManIncIs = ""
  EndIf
EndSub

Sub SetupVariables
  gw = 800                                  'Window Width
  gh = 672                                  'Window Height
  lives = 5                                 'Players lives
  health = 10                               'Players health
  bgx = 0                                   'Backgound X position
  speed = 2                                 'Background X increment / speed
  bgy = 0                                   'Background Y position
  ManDir = 1                                'Man direction 1=left 2=right
  ManSlide  = 1                             'Man's slide number for walking animation
  ManX = gw/2-16                            'Man's position X, center on screen
  ManY = gh-96                              'Man's position Y
  ManInc = .1                               'Walking appearance speed
  JumpPower = 8                             'Jump power
  JumpInc = .2                              'Jump Gravity
  level = 1                                 'Start level
  Score = 0                                 'It's not a game without a score
  StarCount = 0                             'Stars collected
  delay = 9                                 'Change this for smooth frame rate
  TuneStar = "O6 C64"
  TuneSpike = "O3 C64"
  TuneHeart = "O7 C64"
  TuneIntro = "O5 C8 C8 D8 E8 C8 E8 D4"
EndSub

Sub LoadLevel
  GraphicsWindow.FontSize = 96
  GraphicsWindow.BrushColor = "Yellow"
  GraphicsWindow.PenColor = "Blue"
  LevelIcon = Shapes.AddText("LEVEL " + level)
  For i = gh To gh / 3 Step -2
    Shapes.Move(LevelIcon,gw*.25,i)
    Program.Delay(2)
  EndFor
  Program.Delay(2000)
  For i = gh / 3 To gh
    Shapes.Move(LevelIcon,gw*.25,i)
    Program.Delay(2)
  EndFor
  If level = 1 Then
    LoadLevel1()
  ElseIf level = 2 Then
    LoadLevel2()
  ElseIf level = 3 Then
    LoadLevel3()
  ElseIf level = 4 Then
    LoadLevel4()
  ElseIf level = 5 Then
    LoadLevel5()
  ElseIf level = 6 Then
    LoadLevel6()
  ElseIf level = 7 Then
    LoadLevel7()
  ElseIf level = 8 Then
    LoadLevel8()
  ElseIf level = 9 Then
    LoadLevel9()
  EndIf
EndSub

Sub LoadLevel1
  pfx = 14                                  'Playfield position
  pfy1 = 128                                'Playfield line 1 Y position
  pfy2 = 256                                'Playfield line 2 Y position
  pfy3 = 384                                'Playfield line 3 Y position
  pfy4 = 512                                'Playfield line 4 Y position
  pfy5 = 640                                'Playfield line 5 Y position, the ground

  pfw = 100                                 'Playfield width -- not used yet
  '-----------------------------------------------------------------------------------------------Platforms Array
  '--------------------------These arrays correspond with 5 different levels of platforms and objects on the play field -- pf1 = "18=1", pf1 is the top row of platforms
  '--------------------------The first number represents the position from the left on the playfield -- pf1 = "18=1", 18 is the playfield position
  '--------------------------The second number represents the object on that position -- pf1 = "18=1", 1 is the brown bricks
  '--------------------------These are all 5 blocks wide These are 1 block wide These are 2 blocks wide
  '--------------------------bricks[1-9] are brown bricks star[51-59] are blue stars icon[101] is the sign pointing right
  '--------------------------bricks[11-19] are blue bricks star[61-69] are red stars icon[102] is the sign pointing left
  '--------------------------bricks[21-29] are green bricks spike[81-89] are green spikes
  '--------------------------bricks[31-39] are red bricks spike[91-99] are red spikes
  '--------------------------ground[41-49] are ground images icon[119] door to next level
  '--------------------------The screen will show 25 blocks of the playfield and calculate 30 to push objects off the screen
  '--------------------------Issues: do not let the same object show up twice on the screen it will blink, that's why there are 9 images, to avoid repeats
  '--------------------------I chose this method of defining the whole array in one statement versus defining a whole lot of individual variables of the same array
  pf1 = "6=5;18=1;20=65;21=71;23=2;25=66;28=3;30=67;31=72;33=4;35=68;48=11;53=12;75=8;76=71;77=72;78=73;90=9"
  pf2 = "2=33;38=31;39=61;40=62;41=63;42=64;43=32;75=18;76=57;77=58;78=59;85=19;86=97;87=98;88=99"
  pf3 = "6=23;28=21;30=82;31=83;32=84;33=22;73=28;84=29;85=68;86=79;87=69"
  pf4 = "2=11;18=18;19=55;20=56;23=19;25=57;26=58;27=59;79=39"
  pf5 = "0=41;1=101;5=42;10=43;15=44;20=45;21=91;22=92;23=93;24=94;25=46;30=47;35=48;40=41;45=42;50=43;55=44;56=51;57=52;58=53;59=54;60=45;65=46;70=47;75=48;85=43;90=44;91=119;95=45;100=46;102=102"
EndSub

Sub LoadLevel2
  pfx = 89                                  'Playfield position
  '--------------------------These are all 5 blocks wide These are 1 block wide These are 2 blocks wide
  '--------------------------bricks[1-9] are brown bricks star[51-59] are blue stars icon[101] is the sign pointing right
  '--------------------------bricks[11-19] are blue bricks star[61-69] are red stars icon[102] is the sign pointing left
  '--------------------------bricks[21-29] are green bricks spike[81-89] are green spikes
  '--------------------------bricks[31-39] are red bricks spike[91-99] are red spikes
  '--------------------------ground[41-49] are ground images icon[119] door to next level
  pf1 = "18=1;20=65;21=71;23=2;25=66;28=3;30=67;31=72;33=4;35=68;48=11;53=12;75=8;76=71;77=72;78=73;90=9"
  pf2 = "38=31;39=61;40=62;41=63;42=64;43=32;75=18;76=57;77=58;78=59;85=19;86=97;87=98;88=99"
  pf3 = "28=21;30=82;31=83;32=84;33=22;73=28;84=29;85=68;86=79;87=69"
  pf4 = "18=18;19=55;20=56;23=19;25=57;26=58;27=59;79=39"
  pf5 = "0=41;1=101;5=42;10=43;15=44;20=45;21=91;22=92;23=93;24=94;25=46;30=47;35=48;40=41;45=42;50=43;55=44;56=51;57=52;58=53;59=54;60=45;65=46;70=47;75=48;85=43;90=44;91=119;95=45;100=46;102=102"
EndSub

Sub LoadLevel3
  pfx = 87                                  'Playfield position
  '--------------------------These are all 5 blocks wide These are 1 block wide These are 2 blocks wide
  '--------------------------bricks[1-9] are brown bricks star[51-59] are blue stars icon[101] is the sign pointing right
  '--------------------------bricks[11-19] are blue bricks star[61-69] are red stars icon[102] is the sign pointing left
  '--------------------------bricks[21-29] are green bricks spike[81-89] are green spikes
  '--------------------------bricks[31-39] are red bricks spike[91-99] are red spikes
  '--------------------------ground[41-49] are ground images icon[119] door to next level
  pf1 = ""
  pf2 = ""
  pf3 = ""
  pf4 = ""
  pf5 = "0=41;1=101;5=42;10=43;15=44;20=45;21=91;22=92;23=93;24=94;25=46;30=47;35=48;40=41;45=42;50=43;55=44;56=51;57=52;58=53;59=54;60=45;65=46;70=47;75=48;85=43;90=44;91=119;95=45;100=46;102=102"
EndSub

Sub LoadLevel4
  pfx = 14                                  'Playfield position
  '--------------------------These are all 5 blocks wide These are 1 block wide These are 2 blocks wide
  '--------------------------bricks[1-9] are brown bricks star[51-59] are blue stars icon[101] is the sign pointing right
  '--------------------------bricks[11-19] are blue bricks star[61-69] are red stars icon[102] is the sign pointing left
  '--------------------------bricks[21-29] are green bricks spike[81-89] are green spikes
  '--------------------------bricks[31-39] are red bricks spike[91-99] are red spikes
  '--------------------------ground[41-49] are ground images icon[119] door to next level
  pf1 = ""
  pf2 = ""
  pf3 = ""
  pf4 = ""
  pf5 = "0=41;1=101;5=42;10=43;15=44;20=45;21=91;22=92;23=93;24=94;25=46;30=47;35=48;40=41;45=42;50=43;55=44;56=51;57=52;58=53;59=54;60=45;65=46;70=47;75=48;85=43;90=44;91=119;95=45;100=46;102=102"
EndSub

Sub LoadLevel5
  pfx = 14                                  'Playfield position
  '--------------------------These are all 5 blocks wide These are 1 block wide These are 2 blocks wide
  '--------------------------bricks[1-9] are brown bricks star[51-59] are blue stars icon[101] is the sign pointing right
  '--------------------------bricks[11-19] are blue bricks star[61-69] are red stars icon[102] is the sign pointing left
  '--------------------------bricks[21-29] are green bricks spike[81-89] are green spikes
  '--------------------------bricks[31-39] are red bricks spike[91-99] are red spikes
  '--------------------------ground[41-49] are ground images icon[119] door to next level
  pf1 = ""
  pf2 = ""
  pf3 = ""
  pf4 = ""
  pf5 = "0=41;1=101;5=42;10=43;15=44;20=45;21=91;22=92;23=93;24=94;25=46;30=47;35=48;40=41;45=42;50=43;55=44;56=51;57=52;58=53;59=54;60=45;65=46;70=47;75=48;85=43;90=44;91=119;95=45;100=46;102=102"
EndSub

Sub LoadLevel6
  pfx = 14                                  'Playfield position
  '--------------------------These are all 5 blocks wide These are 1 block wide These are 2 blocks wide
  '--------------------------bricks[1-9] are brown bricks star[51-59] are blue stars icon[101] is the sign pointing right
  '--------------------------bricks[11-19] are blue bricks star[61-69] are red stars icon[102] is the sign pointing left
  '--------------------------bricks[21-29] are green bricks spike[81-89] are green spikes
  '--------------------------bricks[31-39] are red bricks spike[91-99] are red spikes
  '--------------------------ground[41-49] are ground images icon[119] door to next level
  pf1 = ""
  pf2 = ""
  pf3 = ""
  pf4 = ""
  pf5 = "0=41;1=101;5=42;10=43;15=44;20=45;21=91;22=92;23=93;24=94;25=46;30=47;35=48;40=41;45=42;50=43;55=44;56=51;57=52;58=53;59=54;60=45;65=46;70=47;75=48;85=43;90=44;91=119;95=45;100=46;102=102"
EndSub

Sub LoadLevel7
  pfx = 14                                  'Playfield position
  '--------------------------These are all 5 blocks wide These are 1 block wide These are 2 blocks wide
  '--------------------------bricks[1-9] are brown bricks star[51-59] are blue stars icon[101] is the sign pointing right
  '--------------------------bricks[11-19] are blue bricks star[61-69] are red stars icon[102] is the sign pointing left
  '--------------------------bricks[21-29] are green bricks spike[81-89] are green spikes
  '--------------------------bricks[31-39] are red bricks spike[91-99] are red spikes
  '--------------------------ground[41-49] are ground images icon[119] door to next level
  pf1 = ""
  pf2 = ""
  pf3 = ""
  pf4 = ""
  pf5 = "0=41;1=101;5=42;10=43;15=44;20=45;21=91;22=92;23=93;24=94;25=46;30=47;35=48;40=41;45=42;50=43;55=44;56=51;57=52;58=53;59=54;60=45;65=46;70=47;75=48;85=43;90=44;91=119;95=45;100=46;102=102"
EndSub

Sub LoadLevel8
  pfx = 14                                  'Playfield position
  '--------------------------These are all 5 blocks wide These are 1 block wide These are 2 blocks wide
  '--------------------------bricks[1-9] are brown bricks star[51-59] are blue stars icon[101] is the sign pointing right
  '--------------------------bricks[11-19] are blue bricks star[61-69] are red stars icon[102] is the sign pointing left
  '--------------------------bricks[21-29] are green bricks spike[81-89] are green spikes
  '--------------------------bricks[31-39] are red bricks spike[91-99] are red spikes
  '--------------------------ground[41-49] are ground images icon[119] door to next level
  pf1 = ""
  pf2 = ""
  pf3 = ""
  pf4 = ""
  pf5 = "0=41;1=101;5=42;10=43;15=44;20=45;21=91;22=92;23=93;24=94;25=46;30=47;35=48;40=41;45=42;50=43;55=44;56=51;57=52;58=53;59=54;60=45;65=46;70=47;75=48;85=43;90=44;91=119;95=45;100=46;102=102"
EndSub

Sub LoadLevel9
  pfx = 14                                  'Playfield position
  '--------------------------These are all 5 blocks wide These are 1 block wide These are 2 blocks wide
  '--------------------------bricks[1-9] are brown bricks star[51-59] are blue stars icon[101] is the sign pointing right
  '--------------------------bricks[11-19] are blue bricks star[61-69] are red stars icon[102] is the sign pointing left
  '--------------------------bricks[21-29] are green bricks spike[81-89] are green spikes
  '--------------------------bricks[31-39] are red bricks spike[91-99] are red spikes
  '--------------------------ground[41-49] are ground images icon[119] door to next level
  pf1 = ""
  pf2 = ""
  pf3 = ""
  pf4 = ""
  pf5 = "0=41;1=101;5=42;10=43;15=44;20=45;21=91;22=92;23=93;24=94;25=46;30=47;35=48;40=41;45=42;50=43;55=44;56=51;57=52;58=53;59=54;60=45;65=46;70=47;75=48;85=43;90=44;95=45;100=46;102=102"
EndSub

Sub SetupWindow
  If debug Then
    TextWindow.Left = gw + 20
    TextWindow.Top  = 10
    TextWindow.Title = "Soldier Dude Debug."
  EndIf
  GraphicsWindow.Hide()
  GraphicsWindow.Height = gh
  GraphicsWindow.Width  = gw
  GraphicsWindow.Top  = 5
  GraphicsWindow.Left = 5
  GraphicsWindow.Title = "RUN Little Soldier Dude, RUN! ---- By Krueg -- 2012"
  GraphicsWindow.BackgroundColor = "Black"
EndSub

Sub SetupImages
  'path = Program.Directory + "\"
  path = "http://krueg.com/sb/soldier/"
  background = Shapes.AddImage(ImageList.LoadImage(path + "background.png"))
  Shapes.Move(background,0,gh+32)
  roofline = Shapes.AddImage(ImageList.LoadImage(path + "roofline.png"))
  Shapes.Move(roofline,0,-32)
  icon[101] = Shapes.AddImage(ImageList.LoadImage(path + "signright.png"))
  Shapes.Move(icon[101],-100,pfy5-32)
  icon[102] = Shapes.AddImage(ImageList.LoadImage(path + "signleft.png"))
  Shapes.Move(icon[102],-100,pfy5-32)
  icon[119] = Shapes.AddImage(ImageList.LoadImage(path + "arch.png"))
  Shapes.Move(icon[119],-100,pfy5-32)
  For i = 1 To 9
    brick[i] = Shapes.AddImage(ImageList.LoadImage(path + "5brickbrown.png"))
    Shapes.Move(brick[i],-160,pfy1)
    brick[i+10] = Shapes.AddImage(ImageList.LoadImage(path + "5brickblue.png"))
    Shapes.Move(brick[i+10],-160,pfy2)
    brick[i+20] = Shapes.AddImage(ImageList.LoadImage(path + "5brickgreen.png"))
    Shapes.Move(brick[i+20],-160,pfy3)
    brick[i+30] = Shapes.AddImage(ImageList.LoadImage(path + "5brickred.png"))
    Shapes.Move(brick[i+30],-160,pfy4)
    ground[i+40] = Shapes.AddImage(ImageList.LoadImage(path + "5ground.png"))
    Shapes.Move(ground[i+40],-165,pfy5)
    star[i+50] = Shapes.AddImage(ImageList.LoadImage(path + "starblue.png"))
    Shapes.Move(star[i+50],-160,pfy5)
    star[i+60] = Shapes.AddImage(ImageList.LoadImage(path + "starred.png"))
    Shapes.Move(star[i+60],-160,pfy5)
    heart[i+70] = Shapes.AddImage(ImageList.LoadImage(path + "heart.png"))
    Shapes.Move(heart[i+70],-160,pfy5)
    spike[i+80] = Shapes.AddImage(ImageList.LoadImage(path + "spikegreen.png"))
    Shapes.Move(spike[i+80],-160,pfy5)
    spike[i+90] = Shapes.AddImage(ImageList.LoadImage(path + "spikered.png"))
    Shapes.Move(spike[i+90],-160,pfy5)
  EndFor
  manl2 = ImageList.LoadImage(path + "man_l2.png")
  manr2 = ImageList.LoadImage(path + "man_r2.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)
  For i = 1 To 4
    Shapes.Move(man[1][i],ManX,ManY)
    Shapes.Zoom(man[1][i],2,2)
    Shapes.HideShape(man[1][i])
    Shapes.Move(man[2][i],ManX,ManY)
    Shapes.Zoom(man[2][i],2,2)
    Shapes.HideShape(man[2][i])
  EndFor
EndSub

Sub ResetImages
  Shapes.Move(background,0,gh+32)
  Shapes.Move(roofline,0,-32)
  Shapes.Move(icon[101],-100,pfy5-32)
  Shapes.Move(icon[102],-100,pfy5-32)
  Shapes.Move(icon[119],-100,pfy5-32)
  For i = 1 To 9
    Shapes.Move(brick[i],-160,pfy1)
    Shapes.Move(brick[i+10],-160,pfy2)
    Shapes.Move(brick[i+20],-160,pfy3)
    Shapes.Move(brick[i+30],-160,pfy4)
    Shapes.Move(ground[i+40],-165,pfy5)
    Shapes.Move(star[i+50],-160,pfy5)
    Shapes.Move(star[i+60],-160,pfy5)
    Shapes.Move(heart[i+70],-160,pfy5)
    Shapes.Move(spike[i+80],-160,pfy5)
    Shapes.Move(spike[i+90],-160,pfy5)
  EndFor
EndSub

Sub ShowIntro
  GraphicsWindow.FontSize = 40
  'GraphicsWindow.DrawImage(path + "intro.png",0,0)
  introscreen = Shapes.AddImage(ImageList.LoadImage(path + "intro.png"))
  Shapes.SetOpacity(introscreen,0)
  GraphicsWindow.Show()
  For i = 0 To 10000
    Shapes.SetOpacity(introscreen,i/100)
  EndFor
  Sound.PlayMusic(TuneIntro)
  GraphicsWindow.BrushColor = "DarkBlue"
  GraphicsWindow.FontSize = 12
  ready = Controls.AddButton("Play",gw*.75-100,gh*.65)
  quit = Controls.AddButton("Quit",gw*.75,gh*.65)
  Controls.SetSize(ready,90,30)
  Controls.SetSize(quit,90,30)
  Controls.ButtonClicked = onbuttonpress
  While play < 1
  EndWhile
  play = 0
  Controls.Remove(ready)
  Controls.Remove(quit)
  Mouse.HideCursor()
  For i = 0 To gh + 32
    Shapes.Move(introscreen,0,i)
    Program.Delay(2)
  EndFor
  Program.Delay(1000)
EndSub

Sub onbuttonpress
  If Controls.LastClickedButton = ready Then
    play = 1
  EndIf
  If Controls.LastClickedButton = quit Then
    Program.End()
  EndIf
EndSub

Sub DebugData
  TextWindow.Clear()
  TextWindow.WriteLine("key = " + key)
  TextWindow.WriteLine("bgInc = " + bgInc)
  TextWindow.WriteLine("bgx = " + bgx)
  TextWindow.WriteLine("pfx = " + pfx)
  TextWindow.WriteLine("Jump = " + Jump)
  TextWindow.WriteLine("ManX = " + ManX)
  TextWindow.WriteLine("ManY = " + ManY)
  TextWindow.WriteLine("JumpCurentSpeed = " + JumpCurentSpeed)
  TextWindow.WriteLine("")
  TextWindow.WriteLine("pf1 = " + pf1)
  TextWindow.WriteLine("pf2 = " + pf2)
  TextWindow.WriteLine("pf3 = " + pf3)
  TextWindow.WriteLine("pf4 = " + pf4)
  TextWindow.WriteLine("pf5 = " + pf5)
EndSub

Copyright (c) Microsoft Corporation. All rights reserved.