Author Topic: ScriptBasic Games  (Read 3700 times)

support

  • Administrator
  • *****
  • Posts: 845
    • Script BASIC Open Source Project
ScriptBasic Games
« on: March 20, 2013, 09:44:54 AM »
I converted a couple of Peter Wirbelauer's OxygenBasic games to ScriptBasic. If you haven't done so already, download the ScriptBasic 2.2 beta release for Windows and unzip it in the directory of choice. Set your system search path to the ScriptBasic bin directory. That will allow you to run ScriptBasic from anywhere and allow it to find it's configuration file that points to it's include and modules directories.

I have attached everything that is needed for each game. Make sure you copy the dllc.dll from the modules directory in the zip to the ScriptBasic modules directory. Feedback welcome.



SM.sbx
Code: [Select]
' ScriptBasic SokoMouse

INCLUDE "sbsw.inc"

SUB Initialize
  SW_DrawBmp p1, 0, 0, 640, 480, 0
' SW_BmpText fo, 200, 8, "SokoMouse", 24, 24
  zA = 0
  Notified = FALSE
  CALL ShowLevel
  FOR bc = 0 TO 299
    xBox[bc] = 0
    yBox[bc] = 0
    rBox[bc] = 0
    zBox[bc] = 0
    iBox[bc] = 0
  NEXT
  zR = 0
  vR = 0
  pHead = 3
  Ready = 0
  sl = 0
  cV = 0
  cR = 0
  Steps = 0
  RasReg = 0
  KeyR = 0
  KeyL = 0
  KeyU = 0
  KeyD = 0
  BoxRas = 0
  Turn = 1
  zTurn = 0
END SUB

SUB LoadMaps
  SW_LoadBytes "Maps/Map" & lev & "-1.bin", Map1
  SW_LoadBytes "Maps/Map" & lev & "-2.bin", Map2
  SW_LoadBytes "Maps/Map" & lev & "-3.bin", Map3
END SUB  
  
SUB ShowLevel
  SW_Sprite s8, 480, 450, zA
  SW_Sprite s9, 576, 450, zA
  SW_BmpText fo, 520, 450, FORMAT("%~00~",lev), 24, 24
  vA += 1
  IF vA = 8 THEN
    vA = 0
    zA = zA + 1
    IF zA = 4 THEN zA = 0
  END IF
END SUB

SUB ShowMaps
  FOR icx = 0 TO 14
    FOR idx = 0 TO 19
      ibx = icx * 20 + idx
      IF ASC(Map1[ibx]) = 3 THEN SW_Sprite s1, idx * 32, icx * 32, 3
      IF ASC(Map3[ibx]) = 2 THEN SW_Sprite s1, idx * 32, icx * 32, 2
      IF ASC(Map2[ibx]) = 5 THEN SW_Sprite s2, idx * 32, icx * 32, zR
    NEXT
  NEXT
  vR += 1
  IF vR = 10 THEN
    vR = 0
    zR += 1
  END IF
  IF zR = 4 THEN zR = 0
END SUB

SUB FindHead
  FOR icx = 0 TO 14
    FOR idx = 0 TO 19
      ibx = icx * 20 + idx
      IF ASC(Map3[ibx]) = 6 THEN
        xHead = idx * 32
        yHead = icx * 32
        rHead = 0
        zHead = 0
        EXIT SUB
      END IF
    NEXT
  NEXT
END SUB

SUB AllDone
  IF Ready >= 1 THEN EXIT SUB
  FOR icx = 0 TO 14
    FOR idx = 0 TO 19
      ibx = icx * 20 + idx
      IF ASC(Map2[ibx]) = 5 AND ASC(Map3[ibx]) <> 4 THEN
        EXIT SUB
      END IF
    NEXT
  NEXT
  Ready = 2
  RasReg = 1
  Turn = 0
  pHead = 0
  rTurn = SW_Rnd(1, 2)
  xTurn = xHead
  yTurn = yHead
END SUB

SUB TurnHead
  IF Turn > 0 THEN EXIT SUB
  IF rTurn = 1 THEN
    SW_Sprite s6, xTurn, yTurn, zTurn
  ELSE IF rTurn = 2 THEN
    SW_Sprite s7, xTurn, yTurn, zTurn
  END IF
  zTurn = zTurn + 1
  IF zTurn = 64 THEN zTurn = 0
END SUB

SUB FlashBox
  FOR icx = 0 TO 14
    FOR idx = 0 TO 19
      ibx = icx * 20 + idx
      IF ASC(Map2[ibx]) = 5 AND ASC(Map3[ibx]) = 4 THEN
        SW_Sprite s4, idx * 32, icx * 32, cR
      END IF
    NEXT
  NEXT
  cV += 1
  IF cV = 10 THEN
    cV = 0
    cR += 1
  END IF
  IF cR = 4 THEN cR = 0
END SUB

SUB ScanBoxes
  IF BoxRas > 0 THEN EXIT SUB
  FOR icx = 0 TO 14
    FOR idx = 0 TO 19
      ibx = icx * 20 + idx
      IF ASC(Map3[ibx]) = 4 THEN
        iBox[ibx] = 1
        xBox[ibx] = idx * 32
        yBox[ibx] = icx * 32
        rBox[ibx] = 0
      END IF
    NEXT
  NEXT
END SUB

SUB ShowBoxes
  FOR ibx = 20 TO 280
    IF iBox[ibx] = 1 AND rBox[ibx] = 0 THEN
      SW_Sprite s1, xBox[ibx], yBox[ibx], 4
    ELSE IF iBox[ibx] = 1 AND rBox[ibx] = 1 THEN
      xBox[ibx] = xBox[ibx] + 2
      SW_Sprite s1, xBox[ibx], yBox[ibx], 4
      zBox[ibx] = zBox[ibx] + 2
      IF zBox[ibx] = 32 THEN
        zBox[ibx] = 0
        iBox[ibx] = 0
        icx = (yBox[ibx] * 20 + xBox[ibx]) / 32
        Map3[icx] = CHR(4)
      END IF
    ELSE IF iBox[ibx] = 1 AND rBox[ibx] = 2 THEN
      xBox[ibx] = xBox[ibx] - 2
      SW_Sprite s1, xBox[ibx], yBox[ibx], 4
      zBox[ibx] = zBox[ibx] + 2
      IF zBox[ibx] = 32 THEN
        zBox[ibx] = 0
        iBox[ibx] = 0
        icx = (yBox[ibx] * 20 + xBox[ibx]) / 32
        Map3[icx] = CHR(4)
      END IF
    ELSE IF iBox[ibx] = 1 AND rBox[ibx] = 3 THEN
      yBox[ibx] = yBox[ibx] - 2
      SW_Sprite s1, xBox[ibx], yBox[ibx], 4
      zBox[ibx] = zBox[ibx] + 2
      IF zBox[ibx] = 32 THEN
        zBox[ibx] = 0
        iBox[ibx] = 0
        icx = (yBox[ibx] * 20 + xBox[ibx]) / 32
        Map3[icx] = CHR(4)
      END IF
    ELSE IF iBox[ibx] = 1 AND rBox[ibx] = 4 THEN
      yBox[ibx] = yBox[ibx] + 2
      SW_Sprite s1, xBox[ibx], yBox[ibx], 4
      zBox[ibx] = zBox[ibx] + 2
      IF zBox[ibx] = 32 THEN
        zBox[ibx] = 0
        iBox[ibx] = 0
        icx = (yBox[ibx] * 20 + xBox[ibx]) / 32
        Map3[icx] = CHR(4)
      END IF
    END IF
  NEXT
END SUB

SUB ScanHead
  IF RasReg > 0 THEN EXIT SUB
  idx = xHead / 32
  icx = yHead / 32
  ibx = icx * 20 + idx
  IF ASC(Map3[ibx]) = 6 AND SW_Key(vk_right) AND ASC(Map3[ibx + 1]) = 4 AND ASC(Map3[ibx + 2]) = 0 AND KeyR = 0 THEN
    Map3[ibx] = CHR(0)
    Map3[ibx + 1] = CHR(6)
    rHead = 1
    pHead = 1
    BoxRas = 0
    xBox[ibx + 1] = xHead + 32
    yBox[ibx + 1] = yHead
    rBox[ibx + 1] = 1
    iBox[ibx + 1] = 1
    Steps += 1
    SW_PlayWav w2
  ELSE IF ASC(Map3[ibx]) = 6 AND SW_Key(vk_left) AND ASC(Map3[ibx - 1]) = 4 AND ASC(Map3[ibx - 2]) = 0 AND KeyL = 0 THEN
    Map3[ibx] = CHR(0)
    Map3[ibx - 1] = CHR(6)
    rHead = 2
    pHead = 2
    BoxRas = 0
    xBox[ibx - 1] = xHead - 32
    yBox[ibx - 1] = yHead
    rBox[ibx - 1] = 2
    iBox[ibx - 1] = 1
    Steps += 1
    SW_PlayWav w2
  ELSE IF ASC(Map3[ibx]) = 6 AND SW_Key(vk_up) AND ASC(Map3[ibx - 20]) = 4 AND ASC(Map3[ibx - 40]) = 0 AND KeyU = 0 THEN
    Map3[ibx] = CHR(0)
    Map3[ibx - 20] = CHR(6)
    rHead = 3
    pHead = 3
    BoxRas = 0
    xBox[ibx - 20] = xHead
    yBox[ibx - 20] = yHead - 32
    rBox[ibx - 20] = 3
    iBox[ibx - 20] = 1
    Steps += 1
    SW_PlayWav w2
  ELSE IF ASC(Map3[ibx]) = 6 AND SW_Key(vk_down) AND ASC(Map3[ibx + 20]) = 4 AND ASC(Map3[ibx + 40]) = 0 AND KeyD = 0 THEN
    Map3[ibx] = CHR(0)
    Map3[ibx + 20] = CHR(6)
    rHead = 4
    pHead = 4
    BoxRas = 0
    xBox[ibx + 20] = xHead
    yBox[ibx + 20] = yHead + 32
    rBox[ibx + 20] = 4
    iBox[ibx + 20] = 1
    Steps += 1
    SW_PlayWav w2
  ELSE IF ASC(Map3[ibx]) = 6 AND SW_Key(vk_right) AND ASC(Map3[ibx + 1]) = 0 AND KeyR = 0 THEN
    rHead = 1
    pHead = 1
    Map3[ibx] = CHR(0)
    Map3[ibx + 1] = CHR(6)
    Steps += 1
    SW_PlayWav w1
  ELSE IF ASC(Map3[ibx]) = 6 AND SW_Key(vk_left) AND ASC(Map3[ibx - 1]) = 0 AND KeyL = 0 THEN
    rHead = 2
    pHead = 2
    Map3[ibx] = CHR(0)
    Map3[ibx - 1] = CHR(6)
    Steps += 1
    SW_PlayWav w1
  ELSE IF ASC(Map3[ibx]) = 6 AND SW_Key(vk_up) AND ASC(Map3[ibx - 20]) = 0 AND KeyU = 0 THEN
    rHead = 3
    pHead = 3
    Map3[ibx] = CHR(0)
    Map3[ibx - 20] = CHR(6)
    Steps += 1
    SW_PlayWav w1
  ELSE IF ASC(Map3[ibx]) = 6 AND SW_Key(vk_down) AND ASC(Map3[ibx + 20]) = 0 AND KeyD = 0 THEN
    rHead = 4
    pHead = 4
    Map3[ibx] = CHR(0)
    Map3[ibx + 20] = CHR(6)
    Steps += 1
    SW_PlayWav w1
  ELSE
    rHead = 0
  END IF
END SUB

SUB ShowHead
  IF rHead = 0 AND pHead = 1 THEN
    SW_Sprite s3, xHead, yHead, 3
  ELSE IF rHead = 0 AND pHead = 2 THEN
    SW_Sprite s3, xHead, yHead, 1
  ELSE IF rHead = 0 AND pHead = 3 THEN
    SW_Sprite s3, xHead, yHead, 0
  ELSE IF rHead = 0 AND pHead = 4 THEN
    SW_Sprite s3, xHead, yHead, 2
  ELSE IF rHead = 1 THEN
    xHead += 2
    SW_Sprite s3, xHead, yHead, 3
    RasReg += 2
    IF RasReg = 32 THEN
      RasReg = 0
      rHead = 0
    END IF
  ELSE IF rHead = 2 THEN
    xHead -= 2
    SW_Sprite s3, xHead, yHead, 1
    RasReg += 2
    IF RasReg = 32 THEN
      RasReg = 0
      rHead = 0
    END IF
  ELSE IF rHead = 3 THEN
    yHead -= 2
    SW_Sprite s3, xHead, yHead, 0
    RasReg += 2
    IF RasReg = 32 THEN
      RasReg = 0
      rHead = 0
    END IF
  ELSE IF rHead = 4 THEN
    yHead += 2
    SW_Sprite s3, xHead, yHead, 2
    RasReg += 2
    IF RasReg = 32 THEN
      RasReg = 0
      rHead = 0
    END IF
  END IF
END SUB

SUB MousePos
  xPos = FIX(SW_xMouse() / 32)
  yPos = FIX(SW_yMouse() / 32)
  IF SW_MouseButton() = 1 THEN
    IF xPos = 15 AND yPos = 14 AND lev > 1 AND ButtonC = 0 THEN
      lev -= 1
      ButtonC = 1
      SW_PlayWav w4
      Initialize
      LoadMaps
      FindHead
      EXIT SUB
    END IF
  END IF
  IF SW_MouseButton() = 1 THEN
    IF xPos = 18 AND yPos = 14 AND lev < 30 AND ButtonC = 0 THEN
      lev += 1
      ButtonC = 1
      SW_PlayWav w4
      Initialize
      LoadMaps
      FindHead
    END IF
  END IF
  IF SW_MouseButton() = 0 THEN ButtonC = 0
END SUB


' MAIN

SW_Window 640, 480, 1
SW_SetCaption "ScriptBasic SokoMouse"

SW_SetFps(60)

Q  = SW_LoadBmp("SokoMedia/sokomouse.bmp", 1)
p1 = SW_LoadBmp("SokoMedia/smbg.bmp", 1)
Fo = SW_LoadBmp("SokoMedia/FontStrip.bmp", 96)
s1 = SW_LoadBmp("SokoMedia/SokoStrip.bmp", 5)
s2 = SW_LoadBmp("SokoMedia/RundStrip.bmp", 4)
s3 = SW_LoadBmp("SokoMedia/HeadStrip.bmp", 4)
s4 = SW_LoadBmp("SokoMedia/BoxsStrip.bmp", 4)
s6 = SW_LoadBmp("SokoMedia/HeadStripR.bmp", 64)
s7 = SW_LoadBmp("SokoMedia/HeadStripL.bmp", 64)
s8 = SW_LoadBmp("SokoMedia/ArroStripL.bmp", 4)
s9 = SW_LoadBmp("SokoMedia/ArroStripR.bmp", 4)

w1 = "SokoMedia/move.wav"
w2 = "SokoMedia/push.wav"
w3 = "SokoMedia/done.wav"
w4 = "SokoMedia/clic.wav"


SW_Cls  0xCCCCCC
SW_Sprite Q, 180, 60, 0
SW_BmpText fo, 205, 32, "SOKOMOUSE", 24, 24
SW_BmpText fo, 170, 428, "PRESS ANY KEY", 24, 24
SW_WaitKey

lev = 1
Initialize
LoadMaps
ShowLevel
FindHead

WHILE SW_Key(27) = 0
  ShowMaps
  IF sl THEN ShowLevel
  ScanBoxes
  ScanHead
  ShowBoxes
  ShowHead
  FlashBox
  AllDone
  MousePos
  TurnHead
  IF SW_Key(vk_space) THEN
    SW_BmpText fo, 64, 420, "Wait...", 24, 24
    Initialize
    LoadMaps
    FindHead
  END IF
  IF Ready = 2 AND NOT(Notified) THEN
    SW_BmpText fo, 64, 450, Steps & " moves to solve.", 20, 20
    SW_Sync
    SW_PlayWav w3
    sl = 1
    Notified = TRUE
  END IF
  BoxRas += 2
  IF BoxRas = 32 THEN BoxRas = 0
  IF SW_Key(vk_right) = 0 THEN KeyR = 1
  IF SW_Key(vk_right)THEN
    KeyR = 0
    SW_Wait(10)
  END IF
  IF SW_Key(vk_left) = 0 THEN KeyL = 1
  IF SW_Key(vk_left) THEN
    KeyL = 0
    SW_Wait(10)
  END IF
  IF SW_Key(vk_up) = 0 THEN KeyU = 1
  IF SW_Key(vk_up) THEN
    KeyU = 0
    SW_Wait(10)
  END IF
  IF SW_Key(vk_down) = 0 THEN KeyD = 1
  IF SW_Key(vk_down) THEN
    KeyD = 0
    SW_Wait(10)
  END IF
  SW_Sync
WEND
SW_CloseWindow




BS.sbx
Code: [Select]
' ScriptBasic Angry Birds Lite

INCLUDE "sbsw.inc"

'   ********
SUB InitVars
'   ********
  SPLITA STRING(40,"0") BY "" TO xMeg
  SPLITA STRING(40,"0") BY "" TO yMeg
  SPLITA STRING(40,"0") BY "" TO zMeg
  SPLITA STRING(40,"0") BY "" TO xUfo
  SPLITA STRING(40,"0") BY "" TO yUfo
  SPLITA STRING(40,"0") BY "" TO zUfo
  SPLITA STRING(40,"0") BY "" TO rUfo
  SPLITA STRING(40,"0") BY "" TO iUfo
  SPLITA STRING(40,"0") BY "" TO nUfo
  SPLITA STRING(40,"0") BY "" TO xRok
  SPLITA STRING(40,"0") BY "" TO yRok
  SPLITA STRING(40,"0") BY "" TO rRok
  SPLITA STRING(40,"0") BY "" TO xBum
  SPLITA STRING(40,"0") BY "" TO yBum
  SPLITA STRING(40,"0") BY "" TO iBum
  SPLITA STRING(40,"0") BY "" TO zBum
  SPLITA STRING(40,"0") BY "" TO vBum
  
  xRak = 0
  yRak = 0
  rRak = 0
  zRak = 0
  iBx = 0
  iDx = 0
  iCx = 0
  iAx = 0
  zFrame = 0
  z1 = 0
  z2 = 0
  z3 = 0
  z4 = 0
  bmap = 0
  w1 = 0
  w2 = 0
  w3 = 0
  s = 0
  y = 0
  sc = 0
  uz = 0
  jx = 0
  drop = 0
  Ok = 0
  count = 0
  px = 0
  
  jv = 0.0
  zv = 0.0
  dv = 0.0
  za = 0.0

END SUB

'        *************
FUNCTION CircleCollide(x1, y1, r1, x2, y2, r2)
'        *************
  IF SQR((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)) <  r1 + r2 THEN
    CircleCollide = 1
  END IF
END FUNCTION

'   ******
SUB Timer1
'   ******
  dv = dv + 0.1
  IF dv >= 1 THEN
    dv = 0
    zFrame += 1
    IF zFrame = 8 THEN zFrame = 0
  END IF
END SUB

'   ******
SUB Timer2
'   ******
  jv = jv + 1
  IF jv = 50 THEN
    jv = 0
    jx = jx + 1
    IF jx = 21 THEN jx = 0
  END IF
END SUB

'   ******
SUB Timer3
'   ******
  Drop = SW_Rnd(0,40)
END SUB

'   ******
SUB Timer4
'   ******
  IF Ok = 1 THEN EXIT SUB
  za += .2
  IF za >= 5 THEN
    za = 0
    count = count - 1
    IF count <= 0 THEN count = 0
  END IF
END SUB

'   *********
SUB SetExplos(xx, yy, ii)
'   *********
  FOR iDx = 0 TO 39
    IF yBum[iDx] = 0 THEN
      xBum[iDx] = xx
      yBum[iDx] = yy
      iBum[iDx] = ii
      EXIT SUB
    END IF
  NEXT
END SUB

'   **********
SUB ShowExplos
'   **********
  FOR iDx = 0 TO 39
  IF iBum[iDx] = 1 THEN
    SW_DrawTile bmap, xBum[iDx], yBum[iDx], 64, 64, zBum[iDx], 1
    vBum[iDx] = vBum[iDx] + 0.1
    IF vBum[iDx] >= 1 THEN
      vBum[iDx] = 0
      zBum[iDx] = zBum[iDx] + 1
    END IF
    IF zBum[iDx] = 8 THEN
      zBum[iDx] = 0
      yBum[iDx] = 0
      iBum[iDx] = 0
      vBum[iDx] = 0
    END IF
  END IF
  NEXT
END SUB

'   *********
SUB SetRocket(xx, yy)
'   *********
  FOR iAx = 0 TO 39
  IF yRok[iAx] = 0 THEN
    xRok[iAx] = xx
    yRok[iAx] = yy
    rRok[iAx] = 1
    EXIT SUB
  END IF
  NEXT
END SUB

'   **********
SUB ScanRocket
'   **********
  FOR iAx = 0 TO 39
  IF rRok[iAx] = 1 AND yRok[iAx] <= -32 THEN
    rRok[iAx] = 0
    yRok[iAx] = 0
  END IF
  NEXT
END SUB

'   **********
SUB ShowRocket
'   **********
  FOR iAx = 0 TO 39
  IF rRok[iAx] = 1 THEN
    SW_DrawTile bmap, xRok[iAx], yRok[iAx], 64, 64, zFrame, 0
    yRok[iAx] = yRok[iAx] - 4
    IF yRok[iAx] = 400 THEN zRak = 0
  END IF
  NEXT
END SUB

'   **********
SUB ScanRakete
'   **********
  IF rRak = 5 THEN EXIT SUB
  IF SW_Key(32) AND SW_Key(39) AND zRak = 0 THEN
    SetRocket(xRak, yRak)
    rRak = 1
    zRak = 1
    SW_PlayWav w1
  ELSE IF SW_Key(32) AND SW_Key(37) AND zRak = 0 THEN
    SetRocket(xRak, yRak)
    rRak = 2
    zRak =1
    SW_PlayWav w1
  ELSE IF SW_Key(32) AND zRak = 0 THEN
    SetRocket(xRak, yRak)
    zRak = 1
    SW_PlayWav w1
  ELSE IF SW_Key(39) AND xRak < 736 THEN
    rRak = 1
  ELSE IF SW_Key(37) AND xRak > 0 THEN
    rRak = 2
  ELSE
    rRak = 0  
  END IF
END SUB

'   **********
SUB ShowRakete
'   **********
  IF rRak = 0 THEN
    SW_DrawTile bmap, xRak, yRak, 64, 64, zFrame, 4
  ELSE IF rRak = 1 THEN
    SW_DrawTile bmap, xRak, yRak, 64, 64, zFrame, 4
    xRak = xRak + 1
  ELSE IF rRak = 2 THEN
    SW_DrawTile bmap, xRak, yRak, 64, 64, zFrame, 4
    xRak = xRak - 1
  END IF
END SUB

'   ***************
SUB RocketCollision
'   ***************
  FOR iBx = 0 TO uz
    FOR iCx = 0 TO 39
      IF rRok[iCx] > 0 AND rUfo[iBx] > 0 THEN
        IF CircleCollide(xRok[iCx] + 32, yRok[iCx] + 32, 16, xUfo[iBx] + 32, yUfo[iBx] + 32, 16) = 1 THEN
          SetExplos(xUfo[iBx], yUfo[iBx], 1)
          rRok[iCx] = 0
          yRok[iCx] = 0
          rUfo[iBx] = 0
          yUfo[iBx] = 0
          SW_PlayWav w2
          sc = sc + 25
          EXIT SUB
        END IF
      END IF
    NEXT
  NEXT
END SUB

'   ***************
SUB RaketeCollision
'   ***************
  IF Ok = 1 THEN EXIT SUB
  FOR iAx = 0 TO 40
    IF yMeg[iAx] > 0 THEN
      IF CircleCollide(xRak, yRak, 16, xMeg[iAx], yMeg[iAx], 16) = 1 THEN
        SetExplos(xRak, yRak, 1)
        rRak = 5
        Ok = 1
        SW_PlayWav w3
        EXIT SUB
      END IF
    END IF
  NEXT
END SUB

'   *******
SUB SetUfos
'   *******
  FOR iAx = 0 TO uz
    xUfo[iAx] = SW_Rnd(16,736)
    yUfo[iAx] = SW_Rnd(16,300)
    rUfo[iAx] = SW_Rnd(1,4)
    zUfo[iAx] = 0
    nUfo[iAX] = 0
  NEXT
END SUB

'   ********
SUB ScanUfos
'   ********
  FOR iBx = 0 TO uz
    IF rUfo[iBx] = 1 AND xUfo[iBx] >= 736 THEN
      rUfo[iBx] = 2
    ELSE IF rUfo[iBx] = 2 AND xUfo[iBx] <= 0 THEN
      rUfo[iBx] = 1
    ELSE IF rUfo[iBx] = 3 AND yUfo[iBx] <= 0 THEN
      rUfo[iBx] = 4
    ELSE IF rUfo[iBx] = 4 AND yUfo[iBx] >= 350 THEN
      rUfo[iBx] = 3
    ELSE IF jx = 5 AND rUfo[iBx] = 4 THEN
      rUfo[iBx] = SW_Rnd(1,4)
    ELSE IF jx = 10 AND rUfo[iBx] = 3 THEN
      rUfo[iBx] = SW_Rnd(1,4)
    ELSE IF jx = 15 AND rUfo[iBx] = 2 THEN
      rUfo[iBx] = SW_Rnd(1,4)
    ELSE IF jx = 20 AND rUfo[iBx] = 1 THEN
      rUfo[iBx] = SW_Rnd(1,4)
    END IF
  NEXT
END SUB

'   ********
SUB ShowUfos
'   ********
  FOR iBx = 0 TO uz
    IF rUfo[iBx] = 1 THEN
      SW_DrawTile bmap, xUfo[iBx], yUfo[iBx], 64, 64, zFrame, 2
      xUfo[iBx] = xUfo[iBx] + 1
    ELSE IF rUfo[iBx] = 2 THEN
      SW_DrawTile bmap, xUfo[iBx], yUfo[iBx], 64, 64, zFrame, 2
      xUfo[iBx] = xUfo[iBx] - 1
    ELSE IF rUfo[iBx] = 3 THEN
      SW_DrawTile bmap, xUfo[iBx], yUfo[iBx], 64, 64, zFrame, 2
      yUfo[iBx] = yUfo[iBx] - 1
    ELSE IF rUfo[iBx] = 4 THEN
      SW_DrawTile bmap, xUfo[iBx], yUfo[iBx], 64, 64, zFrame, 2
      yUfo[iBx] = yUfo[iBx] + 1
    END IF
  NEXT
END SUB

'   *******
SUB SetData
'   *******
  xRak = 384
  yRak = 536
  rRak = 0
  za = 0
  uz = 40
  sc = 0
  Ok = 0
  count = 300
  SetUfos
  FOR iBx = 0 TO 40
    yMeg[iBx] = 0
    xMeg[iBx] = 0
  NEXT
END SUB

'   ********
SUB TestUfos
'   ********
  FOR iAx = 0 TO 40
    IF yUfo[iAx] > 0 OR Ok = 1 THEN EXIT SUB
  NEXT
  Ok = 1
  sc += count
END SUB

'   ************
SUB ScanUfoBombs
'   ************
  FOR iAx = 0 TO drop STEP 2
    IF rUfo[iAx] > 0 THEN
      IF yMeg[iAx] = 0 THEN
        xMeg[iAx] = xUfo[iAx]
        yMeg[iAx] = yUfo[iAx] + 32
      END IF
    END IF
  NEXT
END SUB

'   ********
SUB UfoBombs
'   ********
  FOR iDx = 0 TO 40
    IF yMeg[iDx] > 0 THEN
      IF iDx < 20 THEN
        SW_DrawTile bmap, xMeg[iDx], yMeg[iDx], 64, 64, zFrame, 3
      ELSE IF iDx >= 20 THEN
        SW_DrawTile bmap, xMeg[iDx], yMeg[iDx], 64, 64, zFrame, 3
      END IF
      yMeg[iDx] = yMeg[iDx] + 1
      IF yMeg[iDx] >= 600 THEN yMeg[iDx] = 0
    END IF
  NEXT
END SUB

' *******
'  MAIN *
' *******  

InitVars

SW_Window 800, 600, 1
SW_SetFont 28, 48, 0, ""
bmap = SW_LoadTile("bmp/bitmap.bmp", 8, 5)
w1 = "bmp/shoot.wav"
w2 = "bmp/explo.wav"
w3 = "bmp/xship.wav"
SW_ShowMouse 0
SetData
SW_SetFPS 60

WHILE SW_Key(27) = 0
  SW_Cls 0
  SW_SetCaption "Frames " & SW_ShowFPS()
  IF Ok = 1 THEN
    SW_SetText 460, 0, "SCORE " & sc, SW_RGB(255,255,255)
  ELSE IF Ok = 0 THEN
    SW_SetText 460, 0, "SCORE " & sc, SW_RGB(255,255,255)
  END IF
  ScanUfos
  ShowUfos
  ScanRocket
  ShowRocket
  ScanRakete
  ShowRakete
  ScanUfoBombs
  UfoBombs
  ShowExplos
  RocketCollision
  RaketeCollision
  TestUfos
  Timer1
  Timer2
  Timer3
  Timer4
  IF Ok = 1 THEN
    SW_SetText 240, 300, "ONCE AGAIN?", SW_RGB(255,255,255)
    SW_SetText 240, 344, "HIT [c] KEY", SW_RGB(255,255,255)
    IF SW_Key(67) THEN SetData()
  END IF
  SW_SetText 16, 0, "BONUS " & count, SW_RGB(255,255,255)
  SW_Sync
WEND
SW_Quit

The competition aspect of these games is being featured on the All Basic Forum if you would like to participate.

« Last Edit: March 20, 2013, 10:49:08 AM by support »
Script BASIC Project Manager

support

  • Administrator
  • *****
  • Posts: 845
    • Script BASIC Open Source Project
Re: ScriptBasic Games
« Reply #1 on: March 21, 2013, 07:12:27 PM »
Peter has offered up yet another one of his mind torquing games.

Magic 24



Code: [Select]
' Magic24 by Peter Wirbelauer

INCLUDE "sbsw.inc"

SPLITA STRING(64,"0") BY "" TO Map
SPLITA STRING(26,"0") BY "" TO Buf
num = 0
xm = 0
ym = 0
ibx = 0
iax = 0
Ras = 0
bDir = 0
x1 = 0
y1 = 0
z1 = 0
a = 0
move = 0

'   ********
SUB MoveBloc
'   ********
  IF Ras = 0 THEN EXIT SUB
    IF bDir = 1 THEN
      SW_DrawBmp num, x1, y1, 64, 64, iax
      x1 += 2
      z1 += 2
      IF z1 = 64 THEN
        Ras = 0
        z1 = 0
        x1 = x1 / 64
        y1 = y1 / 64
        ibx = y1 * 5 + x1
        Map[ibx] = iax
      END IF
    ELSE IF bDir = 2 THEN
      SW_DrawBmp num, x1, y1, 64, 64, iax
      x1 -= 2
      z1 += 2
      IF z1 = 64 THEN
        Ras = 0
        z1 = 0
        x1 = x1 / 64
        y1 = y1 / 64
        ibx = y1 * 5 + x1
        Map[ibx] = iax
      END IF
    ELSEIF bDir = 3 THEN
      SW_DrawBmp num, x1, y1, 64, 64, iax
      y1 -= 2
      z1 += 2
      IF z1 = 64 THEN
        Ras = 0
        z1 = 0
        x1 = x1 / 64
        y1 = y1 / 64
        ibx = y1 * 5 + x1
        Map[ibx] = iax
      END IF
    ELSE IF bDir = 4 THEN
      SW_DrawBmp num, x1, y1, 64, 64, iax
      y1 += 2
      z1 += 2
      IF z1 = 64 THEN
        Ras = 0
        z1 =0
        x1 = x1 / 64
        y1 = y1 / 64
        ibx = y1 * 5 + x1
        Map[ibx] = iax
      END IF
    END IF
END SUB

'   ******
SUB IsBloc
'   ******
  IF Ras > 0 THEN EXIT SUB
  xm = FIX(SW_xMouse() / 64)
  ym = FIX(SW_yMouse() / 64)
  ibx = ym * 5 + xm
  IF SW_MouseButton() = 1 THEN
    iax = Map[ibx]
    IF iax = 0 THEN EXIT SUB
    IF Map[ibx+1] = 0 THEN
      Ras = 1
      bDir = 1
      Map[ibx] = 0
      x1 = xm * 64
      y1 = ym * 64
      SW_PlayWav w2
      move += 1
    ELSE IF Map[ibx-1] = 0 AND xm > 0 THEN
      Ras = 1
      bDir = 2
      Map[ibx] = 0
      x1 = xm * 64
      y1 = ym * 64
      SW_PlayWav w2
      move += 1
    ELSE IF Map[ibx - 5] = 0 AND ym > 0 THEN
      Ras = 1
      bDir = 3
      Map[ibx] = 0
      x1 = xm * 64
      y1 = ym * 64
      SW_PlayWav w2
      move += 1
    ELSE IF Map[ibx+5] = 0 THEN
      Ras = 1
      bDir = 4
      Map[ibx] = 0
      x1 = xm * 64
      y1 = ym * 64
      SW_PlayWav w2
      move += 1
    END IF
  END IF
END SUB

'   *******
Sub ShowMap
'   *******
  LOCAL px, py, pz, pa
  px = 0
  py = 0
  pz = 0
  pa = 0
  FOR py = 0 TO 4
    FOR px = 0 TO 4
      pa = py * 5 + px
      pz = Map[pa]
      SW_DrawBmp num, px * 64, py * 64, 64, 64, pz
    NEXT
  NEXT
END SUB

'        ******
FUNCTION Buffer(rd)
'        ******
  LOCAL ix
  ix = 0
  WHILE ix < 24
    IF Buf[ix] = rd THEN
      Buffer = 1
      EXIT FUNCTION
    END IF
    ix += 1
  WEND
  ix = 0
  WHILE ix < 24
    IF Buf[ix] = 0 THEN
      Buf[ix] = rd
      Buffer = 0
      EXIT FUNCTION
    END IF
    ix += 1
  WEND
  Buffer = 0
END FUNCTION

'   *****
SUB Start
'   *****
  LOCAL pa, px, pz
  pa = 0
  px = 0
  pz = 0
  FOR pa = 0 TO 64
    Map[pa] = 255
  NEXT
  move = 0
  Ras = 0
  z1 = 0
  a = 0
  FOR pa = 0 TO 24
    Buf[pa] = 0
    Map[pa] = 0
  NEXT
  WHILE px < 24
    pa = SW_Rnd(1,24)
    pz = Buffer(pa)
    IF pz <> 1 THEN
      Map[px] = pa
      px += 1
    END IF
  WEND
END SUB

'   *****
SUB Ready
'   *****
  LOCAL ix
  IF a = 1 THEN EXIT SUB
  FOR ix = 0 TO 23
    IF Map[ix] <> ix + 1 THEN EXIT SUB
  NEXT
  SW_PlayWav w1
  a = 1
END SUB


' ******
' MAIN *
' ******

SW_Window 320, 350, 1
SW_SetFPS 60
SW_SetCaption "ScriptBasic Magic 24"
SW_SetFont 16, 38, bold, ""
num = SW_LoadBmp("media/blocks.bmp", 25)
w1 = "media/o23.wav"
w2 = "media/clic.wav"
Start
WHILE SW_Key(27) = 0
  SW_Cls 0
  ShowMap
  IsBloc
  MoveBloc
  Ready
  IF a = 1 THEN
    SW_SetText 16, 100, "    YOU GOT IT ", SW_RGB(255,255,255)
    SW_SetText 16, 140, "  PRESS SPACE BAR", SW_RGB(255,255,255)
    IF SW_Key(32) THEN Start()
  END IF
  SW_SetText 100, 320, "MOVES " & move, SW_RGB(255,255,255)
  SW_Sync
WEND
SW_Quit
Script BASIC Project Manager

support

  • Administrator
  • *****
  • Posts: 845
    • Script BASIC Open Source Project
Re: ScriptBasic Games
« Reply #2 on: March 21, 2013, 09:39:23 PM »


Code: OxygenBasic
  1. ' ScriptBasic PONG by Peter Wirbelauer
  2.  
  3. INCLUDE "sbsw.inc"
  4.  
  5. SW_Window 320, 240, 1
  6. SW_SetCaption "ScriptBasic Pong"
  7.  
  8. SW_SetFPS 60
  9.  
  10. x = 50
  11. y = 50
  12. x2 = 130
  13. y2 = 150
  14. pspeed = 2
  15. xadj = 2
  16. yadj = 2
  17. delay = 1
  18. score = 0
  19.  
  20. haha = "wav/haha.wav"
  21. pong = "wav/pong.wav"
  22.  
  23. WHILE SW_Key(27) = 0
  24.   SW_Cls SW_RGB(200, 200, 247)
  25.   SW_FillCircle x, y, 8, SW_RGB(0, 0, 255)
  26.   SW_FillBox x2, y2, 30, 4, SW_RGB(255, 255, 255)
  27.   SW_Box 20, 20, 280, 160, 4, SW_RGB(255, 255, 0)
  28.   SW_SetText 10, 0, "SCORE:" & score, SW_RGB(255, 0, 0)
  29.   IF y <= 20 THEN
  30.     yadj = 1
  31.     SW_PlayWav pong
  32.   END IF
  33.   IF y >= 180 THEN
  34.     yadj = -1
  35.     SW_PlayWav pong
  36.   END IF
  37.   IF x >= 300 THEN
  38.     xadj = -1
  39.     SW_PlayWav pong
  40.   END IF
  41.   IF x <= 20 THEN
  42.     xadj = 1
  43.     SW_PlayWav pong
  44.   END IF
  45.   IF SW_Key(37) AND x2 > 18 THEN x2 = x2 - pspeed
  46.   IF SW_Key(39) AND x2 < 270 THEN x2 = x2 + pspeed
  47.   x += xadj
  48.   y += yadj
  49.   IF y > y2 - 7 AND y2 < y2 + 2 AND x < x2 + 30 AND x > x2 THEN
  50.     yadj = -1
  51.     score += 1
  52.   END IF
  53.   IF y > y2 + 10 THEN
  54.     SW_SetText 100, 200, "GAME OVER!", SW_RGB(0, 160, 55)
  55.     SW_Playwav haha
  56.     SW_Waitkey
  57.     score = 0
  58.     x = 50
  59.     y = 50
  60.     x2 = 130
  61.     y2 = 150
  62.   END IF
  63.   SW_Sync
  64. WEND
  65. SW_CloseWindow
  66.  
Script BASIC Project Manager

support

  • Administrator
  • *****
  • Posts: 845
    • Script BASIC Open Source Project
Re: ScriptBasic Games
« Reply #3 on: April 14, 2013, 09:42:56 PM »
Peter posted a PAC-MAN like game for OxygenBasic which I then converted to ScriptBasic using DLLC.

Quote from: Peter
Read this!

The game itself is a small Puzzle Game with 11 maps. You only have to gather all the pills and stars.
You may not touch a Fire head.

You can restart a Map by pressing the Space Bar. If you have brought home a Map, then press "n" for the next Map.
With this game, you could test your strategy skills.



PB.sb
Code: [Select]
' PAC-BOY by PETER WIRBELAUER

INCLUDE "sbsw.inc"

' Game Routines
SUB BoyBumm
  LOCAL vExp
  IF yExp > 0 THEN
    SW_Sprite s9, xExp, yExp, zExp
    IF play = 0 THEN
      SW_PlayWav w4
      play = 1
    END IF
    vExp += .2
    IF vExp >= 1 THEN
      vExp = 0
      zExp += 1
      IF zExp = 16 THEN
        yExp = 0
       iExp = 1
      END IF
    END IF
  END IF
END SUB

SUB InitEny
  P = 0
  FOR y = 0 TO 29
    FOR x = 0 TO 39
      z = y * 40 + x
      IF map3[z] = 62 THEN
        xEny[p] = x * 64
        yEny[p] = y * 64
        rEny[p] =- 1
        p += 1
      ELSE IF map3[z] = 63 THEN
        xEny[p] = x * 64
        yEny[p] = y * 64
        rEny[p] =- 1
        p += 1
      ELSE IF map3[z] = 64 THEN
        xEny[p] = x * 64
        yEny[p] = y * 64
        rEny[p] = -1
        p += 1
      ELSE IF map3[z] = 65 THEN
        xEny[p] = x * 64
        yEny[p] = y * 64
        rEny[p] = -1
        p += 1
      END IF
      IF p = 4 THEN EXIT SUB
    NEXT
  NEXT
END SUB

SUB ScanEnemy
  IF eras > 0 THEN EXIT SUB
    FOR x = 0 TO 3
      z = (yEny[x] * 40 + xEny[x]) / 64
      IF map3[z] = 62 AND map3[z+1] = 111 THEN
        map3[z] = 32
        map3[z + 1] = 62
        rEny[x] = 1
      ELSE IF map3[z] = 63 AND map3[z - 1] = 111 THEN
        map3[z] = 32
        map3[z - 1] = 63
        rEny[x]=2
      ELSE IF map3[z] = 64 AND map3[z - 40] = 111 THEN
        map3[z] = 32
        map3[z - 40] = 64
        rEny[x] = 3
      ELSE IF map3[z] = 65 AND map3[z + 40] = 111 THEN
        map3[z] = 32
        map3[z + 40] = 65
        rEny[x]=4
      ELSE IF (map3[z] = 62 AND map3[z + 40] = 111) OR (map3[z] = 63 AND map3[z + 40] = 111) THEN
        map3[z] = 32
        map3[z + 40] = 65
        rEny[x] = 4
      ELSE IF (map3[z] = 62 AND map3[z - 40] = 111) OR (map3[z] = 63 AND map3[z - 40] = 111) THEN
        map3[z] = 32
        map3[z - 40] = 64
        rEny[x] = 3
      ELSE IF (map3[z] = 64 AND map3[z - 1] = 111) OR (map3[z] = 65 AND map3[z - 1] = 111) THEN
        map3[z] = 32
        map3[z - 1] = 63
        rEny[x] = 2
      ELSE IF (map3[z] = 64 AND map3[z + 1] = 111) OR (map3[z] = 65 AND map3[z + 1] = 111) THEN
        map3[z] = 32
        map3[z + 1] = 62
        rEny[x] = 1
      ELSE IF map3[z] = 62 THEN
        IF map1[z]=105 AND map3[z + 1] = 32 AND map3[z + 40] = 32 THEN
          rx = SW_Rnd(1, 2)
          IF rx = 1 THEN
            rEny[x] = 1
            map3[z] = 32
            map3[z + 1] = 62
          ELSE IF rx = 2 THEN
            rEny[x] = 4
            map3[z] = 32
            map3[z + 40] = 65
          END IF
        ELSE IF map1[z] = 105 AND map3[z + 1] = 32 AND map3[z - 40] = 32 THEN
          rx = SW_Rnd(1, 2)
          IF rx = 1 THEN
            rEny[x] = 1
            map3[z] = 32
            map3[z + 1] = 62
          ELSE IF rx = 2 THEN
            rEny[x] = 3
            map3[z] = 32
            map3[z - 40] = 64
          END IF
        ELSE IF map1[z] = 105 AND map3[z + 40] = 32 AND map3[z - 40] = 32 THEN
          rx = SW_Rnd(1, 2)
          IF rx = 1 THEN
            rEny[x] = 4
            map3[z] = 32
            map3[z + 40] = 64
          ELSE IF rx = 2 THEN
            rEny[x] = 3
            map3[z] = 32
            map3[z - 40] = 64
          END IF
        ELSE IF map3[z + 40] = 32 AND map3[z + 1] > 32 THEN
          map3[z] = 32
          map3[z + 40] = 65
          rEny[x] = 4
        ELSE IF map3[z - 40] = 32 AND map3[z + 1] > 32 THEN
          map3[z] = 32
          map3[z - 40] = 64
          rEny[x] = 3
        ELSE IF map3[z + 1] > 32 AND map3[z + 40] > 32 AND map3[z - 40] > 32 AND map3[z - 1] = 32 THEN
          map3[z] = 32
          map3[z - 1] = 63
          rEny[x] = 2
        ELSE IF map3[z + 1] > 32 AND map3[z + 40] > 32 AND map3[z - 40] > 32 THEN
          rEny[x] = -1
        ELSE IF map3[z] = 62 AND map3[z + 1] = 32 THEN
          map3[z] = 32
          map3[z + 1] = 62
          rEny[x] = 1
        END IF
      ELSE IF map3[z] = 63 THEN
      IF map1[z] = 105 AND map3[z - 1] = 32 AND map3[z - 40] = 32 THEN
        rx = SW_Rnd(1, 2)
        IF rx = 1 THEN
          rEny[x] = 2
          map3[z] = 32
          map3[z - 1] = 63
        ELSE IF rx = 2 THEN
          rEny[x] = 3
          map3[z] = 32
          map3[z - 40] = 64
        END IF
      ELSE IF map1[z] = 105 AND map3[z + 40] = 32 AND map3[z - 40] = 32 THEN
          rx = SW_Rnd(1, 2)
          IF rx = 1 THEN
            rEny[x] = 4
            map3[z] = 32
            map3[z + 40] = 64
          ELSE IF rx = 2 THEN
            rEny[x] = 3
            map3[z] = 32
            map3[z - 40] = 64
          END IF
      ELSE IF map1[z] = 105 AND map3[z - 1] = 32 AND map3[z + 40] = 32 THEN
        rx = SW_Rnd(1, 2)
        IF rx = 1 THEN
          rEny[x] = 2
          map3[z] = 32
          map3[z - 1] = 63
        ELSE IF rx = 2 THEN
          rEny[x] = 4
          map3[z] = 32
          map3[z + 40] = 65
        END IF
      ELSE IF map3[z + 40] = 32 AND map3[z - 1] > 32 THEN
        map3[z] = 32
        map3[z + 40] = 65
        rEny[x] = 4
      ELSE IF map3[z - 40] = 32 AND map3[z - 1] > 32 THEN
        map3[z] = 32
        map3[z - 40] = 64
        rEny[x] = 3
      ELSE IF map3[z - 1] > 32 AND map3[z + 40] > 32 AND map3[z - 40] > 32 AND map3[z + 1] = 32 THEN
        map3[z] = 32
        map3[z + 1] = 62
        rEny[x] = 1
      ELSE IF map3[z - 1] > 32 AND map3[z + 40] > 32 AND map3[z - 40] > 32 THEN
        rEny[x] = -1
      ELSE IF map3[z] = 63 AND map3[z - 1] = 32 THEN
        map3[z] = 32
        map3[z - 1] = 63
        rEny[x] = 2
      END IF
    ELSE IF map3[z] = 64 THEN
      IF map1[z] = 105 AND map3[z - 40] = 32 AND map3[z + 1] = 32 THEN
        rx = SW_Rnd(1, 2)
        IF rx = 1 THEN
          rEny[x] = 3
          map3[z] = 32
          map3[z - 40] = 64
        ELSE IF rx = 2 THEN
          rEny[x] = 1
          map3[z] = 32
          map3[z + 1] = 62
        END IF
      ELSE IF map1[z] = 105 AND map3[z - 40] = 32 AND map3[z - 1] = 32 THEN
        rx = SW_Rnd(1, 2)
        IF rx = 1 THEN
          rEny[x] = 3
          map3[z] = 32
          map3[z - 40] = 64
        ELSE IF rx = 2 THEN
          rEny[x] = 2
          map3[z] = 32
          map3[z - 1] = 63
        END IF
      ELSE IF map1[z] = 105 AND map3[z - 1] = 32 AND map3[z + 1] = 32 THEN
        rx = SW_Rnd(1, 2)
        IF rx = 1 THEN
          rEny[x] = 1
          map3[z] = 32
          map3[z + 1] = 62
        ELSE IF rx = 2 THEN
          rEny[x] = 2
          map3[z] = 32
          map3[z - 1] = 63
        END IF
      ELSE IF map3[z - 40] > 32 AND map3[z - 1] = 32 THEN
        map3[z] = 32
        map3[z - 1] = 63
        rEny[x] = 2
      ELSE IF map3[z - 40] > 32 AND map3[z + 1] = 32 THEN
        map3[z] = 32
        map3[z + 1] = 62
        rEny[x] = 1
      ELSE IF map3[z - 40] > 32 AND map3[z + 1] > 32 AND map3[z - 1] > 32 AND map3[z + 40] = 32 THEN
        map3[z] = 32
        map3[z + 40] = 65
        rEny[x] = 4
      ELSE IF map3[z - 40] > 32 AND map3[z + 1] > 32 AND map3[z - 1] > 32 THEN
        rEny[x] = -1
      ELSE IF map3[z] = 64 AND map3[z - 40] = 32 THEN
        map3[z] = 32
        map3[z - 40] = 64
        rEny[x] = 3
      ELSE
        rEny[x] = -1
      END IF
    ELSE IF map3[z] = 65 THEN
      IF map1[z] = 105 AND map3[z + 40] = 32 AND map3[z + 1] = 32 THEN
        rx= SW_Rnd(1, 2)
        IF rx = 1 THEN
          rEny[x] = 4
          map3[z] = 32
          map3[z + 40] = 65
        ELSE IF rx = 2 THEN
          rEny[x] = 1
          map3[z] = 32
          map3[z + 1] = 62
        END IF
      ELSE IF map1[z] = 105 AND map3[z + 40] = 32 AND map3[z - 1] = 32 THEN
        rx = SW_Rnd(1, 2)
        IF rx = 1 THEN
          rEny[x] = 4
          map3[z] = 32
          map3[z + 40] = 65
        ELSE IF rx = 2 THEN
          rEny[x] = 2
          map3[z] = 32
          map3[z - 1] = 63
        END IF
      ELSE IF map1[z] = 105 AND map3[z + 1] = 32 AND map3[z - 1] = 32 THEN
        rx = SW_Rnd(1, 2)
        IF rx = 1 THEN
          rEny[x] = 1
          map3[z] = 32
          map3[z + 1] = 62
        ELSE IF rx = 2 THEN
          rEny[x] = 2
          map3[z]=32
          map3[z-1]=63
        END IF
      ELSE IF map3[z + 40] > 32 AND map3[z - 1] = 32 THEN
        map3[z] = 32
        map3[z - 1] = 63
        rEny[x] = 2
      ELSE IF map3[z + 40] > 32 AND map3[z + 1] = 32 THEN
        map3[z] = 32
        map3[z + 1] = 62
        rEny[x] = 1
      ELSE IF map3[z + 40] > 32 AND map3[z + 1] > 32 AND map3[z - 1] > 32 AND map3[z -40] = 32 THEN
        map3[z] = 32
        map3[z - 40] = 64
        rEny[x] = 3
      ELSE IF map3[z + 40] > 32 AND map3[z + 1] > 32 AND map3[z - 1] > 32 THEN
        rEny[x] = -1
      ELSE IF map3[z + 40] = 32 THEN
        map3[z] = 32
        map3[z + 40] = 65
        rEny[x] = 4
      END IF
    END IF
  NEXT
END SUB

SUB SetEny(e)
  vEny[e] += .2
  IF vEny[e] >= 1 THEN
    vEny[e] = 0
    zEny[e] += 1
    IF zEny[e] = 16 THEN zEny[e] = 0
  END IF
END SUB

SUB ShowEnemy
  FOR z = 0 TO 3
    IF rEny[z] = -1 THEN
      SW_Sprite(sc, xEny[z], yEny[z], zEny[z])
      SetEny(z)
    ELSE IF rEny[z] = 1 THEN
      xEny[z] += 1
      SW_Sprite(sc, xEny[z], yEny[z], zEny[z])
      SetEny(z)
    ELSE IF rEny[z] = 2 THEN
      xEny[z] -= 1
      SW_Sprite(sc, xEny[z], yEny[z], zEny[z])
      SetEny(z)
    ELSE IF rEny[z] = 3 THEN
      yEny[z] -= 1
      SW_Sprite(sc, xEny[z], yEny[z], zEny[z])
      SetEny(z)
    ELSE IF rEny[z] = 4 THEN
      yEny[z] += 1
      SW_Sprite(sc, xEny[z], yEny[z], zEny[z])
      SetEny(z)
    END IF
  NEXT
  eras += 1
  IF eras = 64 THEN eras = 0
END SUB

SUB ShowMaps
  LOCAL vAtom
  FOR y = 0 TO 29
    FOR x = 0 TO 39
      z = y * 40 + x
      IF map1[z] = 34 THEN SW_Sprite(s1, x * 64, y * 64, 1)
      IF map1[z] = 107 THEN SW_Sprite(s1, x * 64, y * 64, 2)
      IF map1[z] = 105 THEN SW_Sprite(s1, x * 64, y * 64, 2)
      IF map2[z] = 91 THEN SW_Sprite(s2, x * 64, y * 64, zAtom)
      IF map2[z] = 121 THEN SW_Sprite(s7, x * 64, y * 64, 0)
      IF map2[z] = 81 THEN SW_Sprite(sa, x * 64, y * 64, zAtom)
    NEXT
  NEXT
  vAtom += .2
  IF vAtom >= 1 THEN
    vAtom = 0
    zAtom += 1
    IF zAtom = 16 THEN zAtom = 0
  END IF
END SUB

SUB InitBoy
  FOR y = 0 TO 29
    FOR x = 0 TO 39
      z = y * 40 + x
      IF map3[z] = 111 THEN
        xBoy = x * 64
        yBoy = y * 64
      END IF
      IF map2[z] = 91 OR map2[z] = 81 THEN
        pills += 1
      END IF
      IF map2[z] = 121 THEN
        xExit = x * 64
        yExit = y * 64
      END IF
    NEXT
  NEXT
END SUB

SUB CheckBoy
  IF ras > 0 OR rBoy >= 5 THEN EXIT SUB
  z = (yBoy * 40 + xBoy) / 64
  IF map3[z] >= 62 AND map3[z] <= 65 THEN
    rBoy = 6
    xExp = xBoy
    yExp = yBoy
  ELSE IF map2[z] = 121 AND aExit = 1 THEN
    xShrink = xBoy
    yShrink = yBoy
    map3[z] = 32
    rBoy = 5
  ELSE IF map2[z] = 91 THEN
    xPill = xBoy
    yPill = yBoy
    Pills -= 1
    map2[z] = 32
    map3[z] = 32
    rBoy = 0
    SW_PlayWav w2
  ELSE IF map2[z] = 81 THEN
    xStar = xBoy
    yStar = yBoy
    Pills -= 1
    map2[z] = 32
    map3[z] = 32
    rBoy = 0
    SW_PlayWav w5
  ELSE IF SW_Key(39) < 0 AND map3[z + 1] = 32 THEN
    map3[z] = 32
    map3[z + 1] = 111
    rBoy = 1
  ELSE IF SW_Key(37) < 0 AND map3[z - 1] = 32 THEN
    map3[z] = 32
    map3[z - 1] = 111
    rBoy = 2
  ELSE IF SW_Key(38) < 0 AND map3[z - 40] = 32 THEN
    map3[z] = 32
    map3[z - 40] = 111
    rBoy = 3
  ELSE IF SW_Key(40) < 0 AND map3[z + 40] = 32 THEN
    map3[z] = 32
    map3[z + 40] = 111
    rBoy = 4
  ELSE
    rBoy = 0
  END IF
END SUB

SUB DrawBoy
  LOCAL vBoy
  IF rBoy = 0 THEN
    SW_Sprite s3, xBoy, yBoy, 0
  ELSE IF rBoy = 1 THEN
    xBoy += 1
    SW_Sprite s5,xBoy,yBoy,zBoy
    vBoy += .2
    IF vBoy >= 1 THEN
      vBoy = 0
      zBoy += 1
      IF zBoy = 16 THEN zBoy = 0
    END IF
    ras += 1
    IF ras = 64 THEN ras = 0
  ELSE IF rBoy = 2 THEN
    xBoy -= 1
    SW_Sprite s6, xBoy, yBoy, zBoy
    vBoy += .2
    IF vBoy >= 1 THEN
      vBoy = 0
      zBoy += 1
      IF zBoy = 16 THEN zBoy = 0
    END IF
    ras += 1
    IF ras = 64 THEN ras = 0
  ELSE IF rBoy = 3 THEN
    yBoy -= 1
    SW_Sprite s4, xBoy, yBoy, zBoy
    vBoy += .2
    IF vBoy >= 1 THEN
      vBoy = 0
      zBoy += 1
      IF zBoy = 16 THEN zBoy = 0
    END IF
    ras += 1
    IF ras = 64 THEN ras = 0
  ELSE IF rBoy = 4 THEN
    yBoy +=1
    SW_Sprite s3, xBoy, yBoy, zBoy
    vBoy += .2
    IF vBoy >= 1 THEN
      vBoy = 0
      zBoy += 1
      IF zBoy = 16 THEN zBoy = 0
    END IF
    ras += 1
    IF ras = 64 THEN ras = 0
  END IF
END SUB

SUB PillsAni
  LOCAL vPill
  IF ypill > 0 THEN
    SW_Sprite s8, xpill, yPill, zPill
    vPill += .2
    IF vPill >= 1 THEN
      vPill = 0
      zPill += 1
      IF zPill = 8 THEN
        zPill = 0
        yPill = 0
      END IF
    END IF
  END IF
END SUB

SUB NoPills
  IF Pills = 0 THEN
    IF pills = 0 AND aExit = 0 THEN SW_PlayWav(w1)
    aExit = 1
  END IF
END SUB

SUB ExitActiv
  LOCAL vExit
  IF aExit = 1 THEN
    SW_Sprite s7, xExit, yExit, zExit
    vExit += .2
    IF vExit >= 1 THEN
      vExit = 0
      zExit += 1
      IF zExit = 16 THEN zExit=0
    END IF
  END IF
END SUB

SUB BoyShrink
  LOCAL vShrink
  IF yShrink > 0 THEN
    SW_Sprite s9, xShrink, yShrink, zShrink
    vShrink +=.2
    IF vShrink >= 1 THEN
      vShrink = 0
      zShrink += 1
      IF zShrink = 16 THEN
        yShrink = 0
        SW_PlayWav w4
      END IF
    END IF
  END IF
END SUB

SUB StarShrink
  LOCAL vStar
  IF yStar > 0 THEN
    SW_Sprite sb, xStar, yStar, zStar
    vStar += .4
    IF vStar >= 1 THEN
      vStar=0
      zStar += 1
      IF zStar = 16 THEN
        zStar = 0
        yStar = 0
        vStar = 0
      END IF
    END IF
  END IF
END SUB

SUB InitDat
  FOR x = 0 TO 4
    xEny[x] = 0
    yEny[x] = 0
    rEny[x] = 0
    zEny[x] = 0
    vEny[x] = 0
  NEXT
  xBoy = 0
  yBoy = 0
  zBoy = 0
  rBoy = 0
  xExit = 0
  yExit = 0
  zExit = 0
  aExit = 0
  xShrink = 0
  yShrink = 0
  zShrink = 0
  ras = 0
  pills = 0
  yPill = 0
  xPill = 0
  zPill = 0
  x = 0
  y = 0
  z = 0
  p = 0
  rx = 0
  zAtom = 0
  yStar = 0
  xStar = 0
  zStar=0
  xExp = 0
  yExp = 0
  zExp = 0
  iExp = 0
  eras = 0
  play = 0
END SUB

SUB NewGame
    SW_LoadBytes("maps/map" & m & "-1.txt",map1)
    SW_LoadBytes("maps/map" & m & "-2.txt",map2)
    SW_LoadBytes("maps/map" & m & "-3.txt",map3)
    InitDat
    InitEny
    InitBoy
END SUB


' Main

SW_Window 768,708,1
' Load Bitmaps
s1 = SW_LoadBmp("gfx/char.bmp", 60)
s2 = SW_LoadBmp("gfx/atom.bmp", 16)
s3 = SW_LoadBmp("gfx/boyd.bmp", 16)
s4 = SW_LoadBmp("gfx/boyu.bmp", 16)
s5 = SW_LoadBmp("gfx/boyr.bmp", 16)
s6 = SW_LoadBmp("gfx/boyl.bmp", 16)
s7 = SW_LoadBmp("gfx/exitani.bmp", 16)
s8 = SW_LoadBmp("gfx/pillani.bmp", 16)
s9 = SW_LoadBmp("gfx/bummani.bmp", 16)
sa = SW_LoadBmp("gfx/starani.bmp", 16)
sb = SW_LoadBmp("gfx/shrani.bmp", 16)
sc = SW_LoadBmp("gfx/fire.bmp", 16)

' Assign Sound Files
w1 = "gfx/success.wav"
w2 = "gfx/caim.wav"
w3 = "gfx/drown.wav"
w4 = "gfx/hit.wav"
w5 = "gfx/grab.wav"

'loadmaps
m = 1
SW_LoadBytes("maps/map" & m & "-1.txt",map1)
SW_LoadBytes("maps/map" & m & "-2.txt",map2)
SW_LoadBytes("maps/map" & m & "-3.txt",map3)
InitDat
InitEny
InitBoy
SW_SetFps(140)

WHILE SW_Key(27) = 0
  SW_SetCaption "PILLS: " & pills & "    MAP " & m
  IF SW_GetKey() = 32 THEN NewGame()
  IF SW_GetKey() = 110 AND rBoy = 5 THEN
    m += 1
    IF m = 12 THEN m = 1
    NewGame
  END IF
  ShowMaps
  ExitActiv
  BoyShrink
  BoyBumm
  ScanEnemy
  ShowEnemy
  CheckBoy
  DrawBoy
  PillsAni
  NoPills
  Starshrink
  IF rBoy = 5 THEN
    SW_BmpText s1, 140, 340, "NEXT MAP PRESS N", 32, 64
  END IF
  IF rBoy = 6 THEN
    SW_BmpText s1, 140, 340, "YOU WERE NABBED", 32, 64
  END IF
  SW_Redraw
WEND
SW_Quit()

Note: This zip contains the latest DLLC, SW, Oxygen (DLLs) and sbsw.inc.
Script BASIC Project Manager