Microsoft Small Basic

Program Listing:
Embed this in your website
'Settings'
showturnerror = 0           '1 = Yes'
delaybeforeenemymove = 0    '0 = No'
enemydoublemovefrequency = 100
invisibiltyfrequency = 200
powerupfrequency = 40 '(1 = 1/1 chance per move, 2 = 1/2 chance, 3 = 1/3 chance, etc.)'
'End Settings'

Start:

  prevplayerleft = 250
  prevplayertop = 250
  prevenemyleft = 750
  prevenemytop = 250

GraphicsWindow.Height = 500
GraphicsWindow.Width = 1300
GraphicsWindow.BackgroundColor = "black"
GraphicsWindow.ShowMessage("Stay Away From The Blue Ball!", "Objective")
GraphicsWindow.BrushColor = "red"
GraphicsWindow.PenColor = "darkred"
player = Shapes.AddEllipse(50, 50)
Shapes.Move(player, 250, 250)
GraphicsWindow.BrushColor = "blue"
GraphicsWindow.PenColor = "darkblue"
enemy = Shapes.AddEllipse(50, 50)
Shapes.Move(enemy, 750, 250)
x = 0
activepowerup = 0
activepowerdown = 0
activepowerinvisibility = 0
activepower = 0
didenemydoublemove = 0
rulesloaded = 0
spacepowerdown = 0
powerup = 0
move = 25
moves = 0
enemymove = 25
turnnumber = 0
HowManyPowers()
GraphicsWindow.PenColor = "white"
GraphicsWindow.DrawLine(0, 0, 1300, 0)
GraphicsWindow.DrawLine(0, 0, 0, 500)
GraphicsWindow.DrawLine(1300, 500, 0, 500)
GraphicsWindow.DrawLine(1300, 500, 1300, 0)
GraphicsWindow.DrawLine(1000, 0, 1000, 500)
GraphicsWindow.KeyDown = KeyIsPressed
While x = 0
  If turnnumber = 1 then
  EnemyMove()
  turnnumber = 0
Endif
Endwhile
Goto Start

Sub KeyIsPressed
  If turnnumber = 0 then

    If activepowerup = 1 then
      If activepowerupduration = 3 Then
        move = 50
        activepowerupduration = 2
       Elseif activepowerupduration = 2 Then
         move = 50
         activepowerupduration = 1
       ElseIf activepowerupduration = 1 Then
         move = 50
         activepowerupduration = 0
       ElseIf activepowerupduration = 0 Then
        move = 25
        activepowerupduration  = 100
        activepowerup = 0
       EndIf
     Endif

        If GraphicsWindow.LastKey = "Up" Then
          playertop2 = Shapes.GetTop(player)
          moves = moves + 1
          If playertop2 < 25 Then
            GraphicsWindow.ShowMessage("Game Over! You Hit A Wall", "Game Over")
            GraphicsWindow.ShowMessage("You Got A Score Of: " + moves, "Game Over")
            x = 1
            GraphicsWindow.Clear()
          EndIf
          ChangeMoves()
          Shapes.Move(player, Shapes.GetLeft(player), Shapes.GetTop(player) - move)
        ElseIf GraphicsWindow.LastKey = "Down" Then
          playertop2 = Shapes.GetTop(player)
          moves = moves + 1
          If playertop2 > 425 Then
            GraphicsWindow.ShowMessage("Game Over! You Hit A Wall", "Game Over")
            GraphicsWindow.ShowMessage("You Got A Score Of: " + moves, "Game Over")
            x = 1
            GraphicsWindow.Clear()
          EndIf
          ChangeMoves()
          Shapes.Move(player, Shapes.GetLeft(player), Shapes.GetTop(player) + move)
        Elseif GraphicsWindow.LastKey = "Left" Then
          playerleft2 = Shapes.GetLeft(player)
          moves = moves + 1
          If playerleft2 < 25 Then
            GraphicsWindow.ShowMessage("Game Over! You Hit A Wall", "Game Over")
            GraphicsWindow.ShowMessage("You Got A Score Of: " + moves, "Game Over")
            x = 1
            GraphicsWindow.Clear()
          EndIf
          ChangeMoves()
          Shapes.Move(player, Shapes.GetLeft(player) - move, Shapes.GetTop(player))
        Elseif GraphicsWindow.LastKey = "Right" Then
          playerleft2 = Shapes.GetLeft(player)
          moves = moves + 1
          If playerleft2 > 925 Then
            GraphicsWindow.ShowMessage("Game Over! You Hit A Wall", "Game Over")
            GraphicsWindow.ShowMessage("You Got A Score Of: " + moves, "Game Over")
            x = 1
            GraphicsWindow.Clear()
          EndIf
          ChangeMoves()
          Shapes.Move(player, Shapes.GetLeft(player) + move, Shapes.GetTop(player))
        ElseIf GraphicsWindow.LastKey = "Space" then
          If spacepowerdown > 0 then
            spacepowerdown = spacepowerdown - 1
            HowManyPowers()
            activepowerdown = 1
            activepowerdownduration = 3
          EndIf
        EndIf


        playerleft = Shapes.GetLeft(player)
        playertop = Shapes.GetLeft(player)
        powerupleft = Shapes.GetLeft(powerup)
        poweruptop = Shapes.GetTop(powerup)
        powerdownleft = Shapes.GetLeft(powerdown)
        powerdowntop = Shapes.GetTop(powerdown)
        invisibilityleft = Shapes.GetLeft(invisibility)
        invisibilitytop = Shapes.GetTop(invisibility)

        If prevplayerleft = powerupleft And prevplayertop = poweruptop Then
          activepowerup = 1
          activepower = 0
          activepowerupduration = 3
          moves = moves + 50
          Shapes.Remove(powerup)
        ElseIf prevplayerleft = powerdownleft And prevplayertop = powerdowntop Then
          spacepowerdown = spacepowerdown + 1
          activepower = 0
          moves = moves + 50
          Shapes.Remove(powerdown)
        ElseIf prevplayerleft = invisibilityleft And prevplayertop = invisibilitytop Then
          activepowerinvisibilityduration = 20
          activepowerinvisibility = 1
          activepower = 0
          moves = moves + 50
          Shapes.Remove(invisibility)
        Endif



        If GraphicsWindow.LastKey = "Up" Then
          turnnumber = 1
        ElseIf GraphicsWindow.LastKey = "Down" Then
          turnnumber = 1
        Elseif GraphicsWindow.LastKey = "Left" Then
          turnnumber = 1
        Elseif GraphicsWindow.LastKey = "Right" Then
         turnnumber = 1
        EndIf
      Else
        If showturnerror = 1 then
          GraphicsWindow.ShowMessage("It's Not Your Turn", "Error")
        EndIf
      EndIf
EndSub

Sub EnemyMove
  HowManyPowers()

If  activepowerinvisibility = 1 Then
  If activepowerinvisibilityduration > 0 Then
    activepowerinvisibilityduration = activepowerinvisibilityduration - 1
    Shapes.SetOpacity(player, 50)
    enemymove = 0
  ElseIf activepowerinvisibilityduration = 0 then
    Shapes.SetOpacity(player, 100)
    activepowerinvisibility = 0
    enemymove = 25
  EndIf
EndIf
  If activepowerdown = 1 then
    If activepowerdownduration = 3 Then
        enemymove = 0
        activepowerdownduration = 2
       Elseif activepowerdownduration = 2 Then
         enemymove = 0
         activepowerdownduration = 1
       ElseIf activepowerdownduration = 1 Then
         enemymove = 0
         activepowerdownduration = 0
       ElseIf activepowerdownduration = 0 Then
        enemymove = 25
        activepowerdownduration  = 100
        activepowerdown = 0
       EndIf
     Endif

    If activepower = 0 Then
      If activepowerinvisibility = 0 Then
        If Math.GetRandomNumber(invisibiltyfrequency) = 1 Then
          GraphicsWindow.BrushColor = "magenta"
          GraphicsWindow.PenColor = "darkmagenta"
          invisibility = Shapes.AddEllipse(50, 50)
          HowManyPowers()
          Shapes.Move(invisibility, Math.GetRandomNumber(38) * 25, Math.GetRandomNumber(18) * 25)
          activepower = 1
          movesleft = 50
        EndIf
      EndIf
    EndIf

  If math.GetRandomNumber(powerupfrequency) = 1 Then
    If activepower = 0 Then
      If activepowerinvisibility = 0 Then
        If Math.GetRandomNumber(2) = 1 Then
          GraphicsWindow.BrushColor = "yellow"
          GraphicsWindow.PenColor = "darkyellow"
          powerup = Shapes.AddEllipse(50, 50)
          HowManyPowers()
          Shapes.Move(powerup, Math.GetRandomNumber(38) * 25, Math.GetRandomNumber(18) * 25)
          activepower = 1
          movesleft = 50
        Else
          GraphicsWindow.BrushColor = "green"
          GraphicsWindow.PenColor = "darkgreen"
          powerdown = Shapes.AddEllipse(50, 50)
          HowManyPowers()
          Shapes.Move(powerdown, Math.GetRandomNumber(38) * 25, Math.GetRandomNumber(18) * 25)
          activepower = 1
          movesleft = 50
        EndIf
      EndIf
    EndIf
  EndIf

  Program.Delay(delaybeforeenemymove)
  playerleft = Shapes.GetLeft(player)
  playertop = Shapes.GetTop(player)
  enemyleft = Shapes.GetLeft(enemy)
  enemytop = Shapes.GetTop(enemy)
  whichmove = Math.GetRandomNumber(2)

  If Math.GetRandomNumber(enemydoublemovefrequency) = 1 Then
    enemymove = 2 * enemymove
    didenemydoublemove = 1
  EndIf

  If prevplayerleft = prevenemyleft and prevplayertop = prevenemytop Then
    GraphicsWindow.ShowMessage("You Got A Score Of: " + moves, "Game Over")
    GraphicsWindow.Clear()
    x = 1

  ElseIf playerleft < enemyleft and playertop < enemytop Then
    If whichmove = 1 Then
      Shapes.Move(enemy, enemyleft - enemymove, enemytop)
    ElseIf whichmove = 2 Then
      Shapes.Move(enemy, enemyleft, enemytop - enemymove)
    EndIf

  ElseIf playerleft < enemyleft and playertop > enemytop Then
    If whichmove = 1 Then
      Shapes.Move(enemy, enemyleft - enemymove, enemytop)
    ElseIf whichmove = 2 Then
      Shapes.Move(enemy, enemyleft, enemytop + enemymove)
    EndIf

  Elseif playerleft < enemyleft and playertop = enemytop Then
    Shapes.Move(enemy, enemyleft - enemymove, enemytop)

  Elseif playerleft = enemyleft and playertop > enemytop Then
    Shapes.Move(enemy, enemyleft, enemytop + enemymove)

  Elseif playerleft = enemyleft and playertop < enemytop Then
    Shapes.Move(enemy, enemyleft, enemytop - enemymove)

  Elseif playerleft > enemyleft and playertop > enemytop Then
    If whichmove = 1 Then
      Shapes.Move(enemy, enemyleft + enemymove, enemytop)
    ElseIf whichmove = 2 Then
      Shapes.Move(enemy, enemyleft, enemytop + enemymove)
    EndIf

  Elseif playerleft > enemyleft and playertop < enemytop Then
    If whichmove = 1 Then
      Shapes.Move(enemy, enemyleft + enemymove, enemytop)
    ElseIf whichmove = 2 Then
      Shapes.Move(enemy, enemyleft, enemytop - enemymove)
    EndIf

  Elseif playerleft > enemyleft and playertop = enemytop Then
    Shapes.Move(enemy, enemyleft + enemymove, enemytop)
  Endif
  prevplayerleft = Shapes.GetLeft(player)
  prevplayertop = Shapes.GetTop(player)
  prevenemyleft = Shapes.GetLeft(enemy)
  prevenemytop = Shapes.GetTop(enemy)

  If didenemydoublemove = 1 Then
    enemymove = 25
  EndIf
EndSub

Sub HowManyPowers
  GraphicsWindow.BrushColor = "black"
  GraphicsWindow.FillRectangle(1001, 0, 299, 100)
  GraphicsWindow.BrushColor = "White"
  GraphicsWindow.DrawBoundText(1125, 15, 299, "Immobilise: " + spacepowerdown)
  If activepower = 1 then
    GraphicsWindow.DrawBoundText(1025, 45, 299, "Moves Left Until Power Disappears: " + movesleft)
  ElseIf activepowerinvisibility = 1 Then
    GraphicsWindow.DrawBoundText(1025, 45, 299, "Invisible For: " + activepowerinvisibilityduration + " Turns")
  Elseif activepower = 0 Then
    GraphicsWindow.DrawBoundText(1110, 45, 299, "No Powers To Get")
  EndIf
    GraphicsWindow.DrawBoundText(1140, 75, 299, "Score: " + moves)
  If rulesloaded = 0 Then
    rulesloaded = 1
    GraphicsWindow.BrushColor = "purple"
    GraphicsWindow.FillRectangle(1001, 100, 299, 400)
    GraphicsWindow.FontSize = 20
    GraphicsWindow.BrushColor = "black"
    GraphicsWindow.DrawBoundText(1100, 115, 150, "The Rules:")
    GraphicsWindow.FontSize = 12
    GraphicsWindow.DrawBoundText(1100, 160, 125, "Your Player: Move With Arrow Keys")
    GraphicsWindow.DrawBoundText(1100, 215, 125, "The Enemy: Stay Away From It")
    GraphicsWindow.DrawBoundText(1100, 270, 125, "Immobilise: Pick It Up, Press Space To Use")
    GraphicsWindow.DrawBoundText(1100, 325, 125, "Speed Boost: Pick It Up, Boosted Speed For 3 Turns")
    GraphicsWindow.DrawBoundText(1100, 380, 125, "Invisibility: Pick It Up, Can't Be Seen By Enemy")
    GraphicsWindow.DrawBoundText(1050, 430, 200, "Don't Hit The Walls! The Enemy Has A Chance To Double-Move, 50 Points For A Powerup, 1 Point For A Move.")

    GraphicsWindow.BrushColor = "red"
    GraphicsWindow.PenColor = "darkred"
    showplayer = Shapes.AddEllipse(25, 25)
    Shapes.Move(showplayer, 1050, 165)
    GraphicsWindow.BrushColor = "blue"
    GraphicsWindow.PenColor = "darkblue"
    showenemy = Shapes.AddEllipse(25, 25)
    Shapes.Move(showenemy, 1050, 220)
    GraphicsWindow.BrushColor = "green"
    GraphicsWindow.PenColor = "darkgreen"
    showimmobilise = Shapes.AddEllipse(25, 25)
    Shapes.Move(showimmobilise, 1050, 275)
    GraphicsWindow.BrushColor = "yellow"
    GraphicsWindow.PenColor = "yellow"
    showpowerup = Shapes.AddEllipse(25, 25)
    Shapes.Move(showpowerup, 1050, 330)
    GraphicsWindow.BrushColor = "magenta"
    GraphicsWindow.PenColor = "darkmagenta"
    showinvisibility = Shapes.AddEllipse(25, 25)
    Shapes.Move(showinvisibility, 1050, 385)
  EndIf
EndSub

Sub ChangeMoves
  If activepower = 1 Then
    If movesleft > 0 Then
      movesleft = movesleft - 1
      HowManyPowers()
    ElseIf movesleft = 0 then
      activepower = 0
     Shapes.Remove(powerup)
     Shapes.Remove(powerdown)
     Shapes.Remove(invisibility)
    EndIf
  EndIf
EndSub
Copyright (c) Microsoft Corporation. All rights reserved.