Microsoft Small Basic

Program Listing:
Embed this in your website
'manbiki.sb for Small BASIC
'by takuya matsubara

GraphicsWindow.FontSize = 16
GraphicsWindow.Width = 640
GraphicsWindow.height = 48*9
GraphicsWindow.KeyDown = OnKeyDown

GraphicsWindow.BrushColor = "Black"
GraphicsWindow.FillRectangle(48*9, 0, 640-(48*9),48*9)
GraphicsWindow.BrushColor = "Red"
GraphicsWindow.DrawText(440, 50, "Manbiki Syonen 2010")
GraphicsWindow.DrawText(500, 90, "Since 1980")

'player
GraphicsWindow.BrushColor = "Blue"
box = Shapes.AddRectangle(16, 16)
ball = Shapes.AddEllipse(16, 16)
arm1 = Shapes.AddLine(16,0,0,16)
arm2 = Shapes.AddLine(0,0,16,16)
leg1 = Shapes.AddLine(0,0,0,16)
leg2 = Shapes.AddLine(0,0,0,16)

'teki
GraphicsWindow.BrushColor = "Red"
gbox = Shapes.AddRectangle(16, 16)
gball = Shapes.AddEllipse(16, 16)
garm1 = Shapes.AddLine(16,0,0,16)
garm2 = Shapes.AddLine(0,0,16,16)
gleg1 = Shapes.AddLine(0,0,0,16)
gleg2 = Shapes.AddLine(0,0,0,16)

retry:
goldcnt=0

GraphicsWindow.BrushColor = "Black"
GraphicsWindow.FillRectangle(0, 0, 48*9,48*9)
Program.Delay(500)
GraphicsWindow.BrushColor = "LightGray"
GraphicsWindow.FillRectangle(0, 0, 48*9,48*9)

GraphicsWindow.PenColor = "Black"
for y=0 to 48*8 Step 48*2
  For x=0 To 48*8 Step 48*2
    GraphicsWindow.BrushColor = "Green"
    GraphicsWindow.FillRectangle(x, y, 48,48)
    If(y<48*8)then
      GraphicsWindow.BrushColor = "LightBlue"
      GraphicsWindow.FillRectangle(x, y+24, 48,32)
      GraphicsWindow.DrawRectangle(x, y, 48,24)
      GraphicsWindow.BrushColor = "Yellow"
      GraphicsWindow.FillRectangle(x+12, y+28, 24, 24)
      GraphicsWindow.DrawRectangle(x+12, y+28, 24,24)
      GraphicsWindow.BrushColor = "Black"
      GraphicsWindow.DrawText(x+18, y+14+16, "$")
      goldexist[goldcnt]=1
      goldcnt=goldcnt+1
    endif
    GraphicsWindow.DrawRectangle(x, y, 48,48+8)
  endfor
endfor

tx = 48*1
ty = 48*1
x = 48*7
y = 48*7
score = 0
x1 = 0
y1 = 0
twalkcnt = 0
walkcnt = 0
movepitch = 4

PrintTeki()
PrintScore()
PrintPlayer()

Sound.PlayMusic("O3 C5 C7 G5")
endcode=0
while(endcode=0)
  If (twalkcnt = 0) then
    'move teki
    dir = Math.GetRandomNumber(4)
    tx1 = 0
    ty1 = 0
    If (dir=1) and (ty>0) Then
      ty1 = -1
    endif
    If (dir=2) and (ty<48*8) Then
      ty1 = 1
    endif
    If (dir=3) and (tx>0) Then
      tx1 = -1
    endif
    If (dir=4) and (tx<48*8) Then
      tx1 = 1
    endif
    If (Math.Remainder(tx , 48*2)=0) Then
      ty1=0
    endif
    If (Math.Remainder(ty , 48*2)=0) Then
      tx1=0
    endif
    twalkcnt = 48
    If (Math.Remainder(x , 48*2)<>0) and (x=tx) then
        endcode=1
    endif
    If (Math.Remainder(y , 48*2)<>0) and (y=ty) then
        endcode=1
    endif
  else
    tx = tx+tx1*movepitch
    ty = ty+ty1*movepitch
    PrintTeki()
    twalkcnt = twalkcnt-movepitch
  endif
  If (walkcnt =0)Then
    If (Math.Remainder(y , 48*2)<>0) Then
      If (Math.Remainder(x , 48*2)=0) Then
        i=Math.Round(x/(48*2))+Math.Round((y-48)/(48*2))*5
        if (goldexist[i]=1) then
          goldexist[i]=0
          goldcnt=goldcnt-1
          GraphicsWindow.BrushColor = "Black"
          GraphicsWindow.FillRectangle(x+12, y+28-48, 24, 24)
          Sound.PlayChimes()
          score = score+100
          PrintScore()
          If(goldcnt=0)then
            endcode=2
          endif
        endif
      endif
    endif
  else
    x = x+x1*movepitch
    y = y+y1*movepitch
    PrintPlayer()
    walkcnt = walkcnt-movepitch
  EndIf
  Program.Delay(20)
endwhile
'ending
If(endcode=1)then
  Sound.PlayBellRingAndWait()
  While((Math.Abs(x-tx)>8)Or(Math.Abs(y-ty)>8))
    If(x<tx)Then
      tx = tx-4
    else
      tx = tx+4
    endif
    If(y<ty)Then
      ty = ty-4
    else
      ty = ty+4
    endif
    Program.Delay(20)
    PrintTeki()
  endwhile
  GraphicsWindow.ShowMessage("miss!", "Manbiki")
endif
If(endcode=2)then
  Sound.PlayMusic("O5 C8 D8 E8 F8 G4 O5 C8 D8 E8 F8 G4")
  GraphicsWindow.ShowMessage("Clear!", "Manbiki")
endif
Goto retry

Sub OnKeyDown
  If (walkcnt=0) then
    x1=0
    y1=0
    If (GraphicsWindow.LastKey = "Up") and (y>0) Then
      y1 = -1
    endif
    If (GraphicsWindow.LastKey = "Down") and (y<48*8) Then
      y1 = 1
    endif
    If (GraphicsWindow.LastKey = "Left") and (x>0) Then
      x1 = -1
    endif
    If (GraphicsWindow.LastKey = "Right") and (x<48*8) Then
      x1 = 1
    endif
    If (Math.Remainder(x , 48*2)=0) Then
      y1=0
    endif
    If (Math.Remainder(y , 48*2)=0) Then
      x1=0
    endif
    walkcnt = 48
  endif
EndSub

Sub PrintScore
  GraphicsWindow.BrushColor = "Black"
  GraphicsWindow.FillRectangle(500, 300, 150, 20)
  GraphicsWindow.BrushColor = "Yellow"
  GraphicsWindow.DrawText(500, 300, "Score: " + score)
EndSub

Sub PrintPlayer
  Shapes.Move(ball, x+16, y)
  Shapes.Move(box, x+16, y+16)
  Shapes.Move(arm1, x, y+16)
  Shapes.Move(arm2, x+32, y+16)
  Shapes.Move(leg1, x+16, y+32)
  Shapes.Move(leg2, x+32, y+32)
EndSub

Sub PrintTeki
  Shapes.Move(gball, tx+16, ty)
  Shapes.Move(gbox, tx+16, ty+16)
  Shapes.Move(garm1, tx, ty+16)
  Shapes.Move(garm2, tx+32, ty+16)
  Shapes.Move(gleg1, tx+16, ty+32)
  Shapes.Move(gleg2, tx+32, ty+32)
EndSub
Copyright (c) Microsoft Corporation. All rights reserved.