home *** CD-ROM | disk | FTP | other *** search
/ Enter 2003: The Beautiful Scenery / enter-parhaat-2003.iso / files / frendz.exe / frendz.dcr / Scripts_24_b_GameLoop.ls < prev    next >
Encoding:
Text File  |  2002-12-31  |  11.5 KB  |  349 lines

  1. property pEndOfGame, pSetNextLevel, pTicks, pBlink
  2. global gGameState, gLevelNum, gGameOverTime, gCurMoveNum, gJuggleTime, gTraceMap, gComputerPlayer, gHumanMove, gScorePlayer1, gScorePlayer2, gPlayerWon, gPlayAnimation, NUM_SQUARES, gDifficulity, gLevel, gPoints, gpvMainBoard, gAniPairRed, gAniPairBlue, gAniPairWon, gAniPairLost, gStartLevel, gBonus, gCheater, gBlueBored, gDidntCount, gMouseOn, gSoundEnabled, gOldKey
  3.  
  4. on beginSprite me
  5.   pEndOfGame = 1
  6.   pSetNextLevel = 1
  7. end
  8.  
  9. on enterFrame me
  10.   yawned = goUpdate(gGameState)
  11.   if gGameState = #startNewGame then
  12.     setGameState(#player1Move)
  13.     gBlueBored = 0
  14.     gDidntCount = 0
  15.   else
  16.     if gGameState = #player1Move then
  17.       if goNumPossibleMoves(1) = 0 then
  18.         if goNumPossibleMoves(2) = 0 then
  19.           setGameState(#Endgame)
  20.         else
  21.           setGameState(#player1Passing)
  22.         end if
  23.       else
  24.         if gComputerPlayer[1] then
  25.           goStartComputerMove(1)
  26.           setGameState(#waitingComputer1)
  27.         else
  28.           gHumanMove = 0
  29.           setGameState(#waitingHuman1)
  30.         end if
  31.       end if
  32.     else
  33.       if gGameState = #waitingHuman1 then
  34.         sprite(9).locH = 81
  35.         if gHumanMove > 0 then
  36.           if goCheckValidMove(gHumanMove, 1) then
  37.             goTransitionBoard(gHumanMove, 1)
  38.             goSetPiece(gHumanMove, 1)
  39.             setGameState(#player1Done)
  40.           else
  41.             setGameState(#player1BadMove)
  42.           end if
  43.         end if
  44.       else
  45.         if gGameState = #waitingComputer1 then
  46.           if pBlink = 1 then
  47.             sprite(9).locH = 81
  48.             pTicks = pTicks + 1
  49.             if pTicks = 6 then
  50.               pBlink = 0
  51.               pTicks = 0
  52.             end if
  53.           else
  54.             sprite(9).locH = -100
  55.             pTicks = pTicks + 1
  56.             if pTicks = 3 then
  57.               pBlink = 1
  58.               pTicks = 0
  59.             end if
  60.           end if
  61.           sprite(95).locH = -500
  62.           sprite(94).locH = 3
  63.           sprite(85).member = "graydot"
  64.           sprite(85).locH = -500
  65.           pieceNum = goContinueComputerMove()
  66.           if pieceNum > 0 then
  67.             sound(3).play(member("s_mouseDown"))
  68.             goTransitionBoard(pieceNum, 1)
  69.             goSetPiece(pieceNum, 1)
  70.             setGameState(#player1Done)
  71.             playFlashAnimationPair(gAniPairRed, 13, 14, gSoundEnabled)
  72.             pTicks = 0
  73.           end if
  74.         else
  75.           if gGameState = #player1Done then
  76.             setGameState(#player2Move)
  77.           else
  78.             if gGameState = #player2Move then
  79.               if goNumPossibleMoves(2) = 0 then
  80.                 if goNumPossibleMoves(1) = 0 then
  81.                   setGameState(#Endgame)
  82.                 else
  83.                   setGameState(#player2Passing)
  84.                 end if
  85.               else
  86.                 if gComputerPlayer[2] then
  87.                   goStartComputerMove(2)
  88.                   setGameState(#waitingComputer2)
  89.                 else
  90.                   gHumanMove = 0
  91.                   setGameState(#waitingHuman2)
  92.                 end if
  93.               end if
  94.             else
  95.               if gGameState = #waitingHuman2 then
  96.                 sprite(9).locH = 295
  97.                 if pBlink = 1 then
  98.                   sprite(9).locH = 295
  99.                   pTicks = pTicks + 1
  100.                   if pTicks = 6 then
  101.                     pBlink = 0
  102.                     pTicks = 0
  103.                   end if
  104.                 else
  105.                   sprite(9).locH = -100
  106.                   pTicks = pTicks + 1
  107.                   if pTicks = 3 then
  108.                     pBlink = 1
  109.                     pTicks = 0
  110.                   end if
  111.                 end if
  112.                 sprite(94).locH = -500
  113.                 sprite(95).locH = 308
  114.                 if gHumanMove > 0 then
  115.                   if goCheckValidMove(gHumanMove, 2) then
  116.                     sound(3).play(member("s_mouseOver"))
  117.                     x = goTransitionBoard(gHumanMove, 2)
  118.                     newPoints = x * gPoints
  119.                     y = getScore() + newPoints
  120.                     setScore(y)
  121.                     if goIsStar(gHumanMove) then
  122.                       sprite(85).member = "xplode"
  123.                       sprite(85).loc = gMouseOn
  124.                       moleShowScoreBubble(gMouseOn.locH, gMouseOn.locV, gBonus)
  125.                       sound(2).play(member("ATTTONES"))
  126.                       y = getScore() + gBonus
  127.                       setScore(y)
  128.                     end if
  129.                     goSetPiece(gHumanMove, 2)
  130.                     setGameState(#player2Done)
  131.                     playFlashAnimationPair(gAniPairBlue, 14, 13, gSoundEnabled)
  132.                     pTicks = 0
  133.                   else
  134.                     if gDidntCount < 3 then
  135.                       playFlashAnimationOne("didnt", 14, gSoundEnabled)
  136.                       gDidntCount = gDidntCount + 1
  137.                     end if
  138.                     setGameState(#player2BadMove)
  139.                   end if
  140.                 else
  141.                   if (gBlueBored < 1) and (yawned = 1) then
  142.                     playFlashAnimationOne("bored", 14, gSoundEnabled)
  143.                     gBlueBored = gBlueBored + 1
  144.                   end if
  145.                 end if
  146.               else
  147.                 if gGameState = #waitingComputer2 then
  148.                   sprite(9).locH = 295
  149.                   pieceNum = goContinueComputerMove()
  150.                   if pieceNum > 0 then
  151.                     goTransitionBoard(pieceNum, 2)
  152.                     goSetPiece(pieceNum, 2)
  153.                     setGameState(#player2Done)
  154.                   end if
  155.                 else
  156.                   if gGameState = #player2Done then
  157.                     setGameState(#player1Move)
  158.                   else
  159.                     if gGameState = #Endgame then
  160.                       case pEndOfGame of
  161.                         1:
  162.                           if goGetNumPieces(2) >= goGetNumPieces(1) then
  163.                             sound(3).play(member("tada"))
  164.                             pEndOfGame = 2
  165.                           else
  166.                             sound(3).play(member("buzzer"))
  167.                             pEndOfGame = 3
  168.                           end if
  169.                         2:
  170.                           if soundBusy(3) then
  171.                             go(the frame)
  172.                           else
  173.                             playFlashAnimationPair(gAniPairWon, 14, 13, gSoundEnabled)
  174.                             setGameState(#gameOver)
  175.                             pEndOfGame = 4
  176.                           end if
  177.                         3:
  178.                           if soundBusy(3) then
  179.                             go(the frame)
  180.                           else
  181.                             playFlashAnimationPair(gAniPairLost, 14, 13, gSoundEnabled)
  182.                             setGameState(#gameOver)
  183.                             pEndOfGame = 4
  184.                           end if
  185.                       end case
  186.                     end if
  187.                   end if
  188.                 end if
  189.               end if
  190.             end if
  191.           end if
  192.         end if
  193.       end if
  194.     end if
  195.   end if
  196.   numP1 = goGetNumPieces(1)
  197.   if numP1 <> gScorePlayer1 then
  198.     gScorePlayer1 = numP1
  199.     member("t_Score1").text = string(gScorePlayer1)
  200.   end if
  201.   numP2 = goGetNumPieces(2)
  202.   if numP2 <> gScorePlayer2 then
  203.     gScorePlayer2 = numP2
  204.     member("t_Score2").text = string(gScorePlayer2)
  205.   end if
  206.   if the shiftDown = 1 then
  207.     theKey = the keyPressed
  208.     if (theKey <> EMPTY) and (gOldKey = EMPTY) then
  209.       case theKey of
  210.         "x":
  211.           gCheater = 1
  212.           setGameState(#Endgame)
  213.         "!":
  214.           playFlashAnimationPair(gAniPairBlue, 14, 13, 1, 1)
  215.         "@":
  216.           playFlashAnimationPair(gAniPairWon, 14, 13, 1)
  217.         "#":
  218.           playFlashAnimationPair(gAniPairLost, 14, 13, 1)
  219.         "$":
  220.           playFlashAnimationOne("bored", 14, 1)
  221.         "%":
  222.           playFlashAnimationOne("didnt", 14, 1)
  223.         "^":
  224.           playFlashAnimationPair(gAniPairRed, 13, 14, 1, 1)
  225.       end case
  226.     end if
  227.     gOldKey = theKey
  228.   end if
  229. end
  230.  
  231. on exitFrame
  232.   if gGameState = #gameOver then
  233.     num1Pieces = goGetNumPieces(1)
  234.     num2Pieces = goGetNumPieces(2)
  235.     numTotalPieces = num1Pieces + num2Pieces
  236.     if num2Pieces >= num1Pieces then
  237.       if num1Pieces = 0 then
  238.         gameError("YOU SKUNKED 'EM!" & RETURN & RETURN & "Click to play" & RETURN & "the next round.")
  239.       else
  240.         if numTotalPieces = NUM_SQUARES then
  241.           gameError("YOU WON!" & RETURN & RETURN & "Click to play" & RETURN & "the next round.")
  242.         else
  243.           gameError("YOU WON!" & RETURN & RETURN & "There are no more possible moves for either player.  Click to play the next round.")
  244.         end if
  245.       end if
  246.       gPlayerWon = 1
  247.       if pSetNextLevel = 1 then
  248.         setNewLevel()
  249.         pSetNextLevel = 0
  250.       end if
  251.       go(the frame)
  252.     else
  253.       if num2Pieces = 0 then
  254.         gameError("YOU GOT SKUNKED..." & RETURN & RETURN & "Why not play again?")
  255.       else
  256.         if numTotalPieces = NUM_SQUARES then
  257.           gameError("YOU LOST..." & RETURN & RETURN & "Why not play again?")
  258.         else
  259.           gameError("YOU LOST..." & RETURN & RETURN & "There are no more possible moves for either player.  Why not play again?")
  260.         end if
  261.       end if
  262.       gPlayerWon = 0
  263.       go(the frame)
  264.     end if
  265.   else
  266.     if gGameState = #player1BadMove then
  267.       gameErrorBig("INVALID MOVE" & RETURN & RETURN & "You can only place your red Frendz on a square that causes one or more of the blue Frendz to be surrounded - either horizontally, vertically, or diagonally.")
  268.       go(the frame)
  269.     else
  270.       if gGameState = #player2BadMove then
  271.         gameErrorBig("INVALID MOVE" & RETURN & RETURN & "You can only place your blue Frendz on a square that causes one or more of the computer's red Frendz to be surrounded - either horizontally, vertically, or diagonally.")
  272.         go(the frame)
  273.       else
  274.         if gGameState = #player1Passing then
  275.           gameError("WELL DONE!" & RETURN & RETURN & "The Computer has no moves." & RETURN & RETURN & "It's your turn again.")
  276.           go(the frame)
  277.         else
  278.           if gGameState = #player2Passing then
  279.             gameError("OOPS!" & RETURN & RETURN & "You have no moves." & RETURN & RETURN & "It's the computer's turn again.")
  280.             go(the frame)
  281.           else
  282.             go(the frame)
  283.           end if
  284.         end if
  285.       end if
  286.     end if
  287.   end if
  288. end
  289.  
  290. on setNewLevel
  291.   case gStartLevel of
  292.     "Easy":
  293.       if gLevel = 2 then
  294.         gDifficulity = "Medium"
  295.         gPoints = 250
  296.         gBonus = 2500
  297.       else
  298.         if gLevel = 4 then
  299.           gDifficulity = "Hard"
  300.           gPoints = 500
  301.           gBonus = 5000
  302.         else
  303.           if gLevel = 6 then
  304.             gDifficulity = "Harder"
  305.             gPoints = 750
  306.             gBonus = 7500
  307.           else
  308.             if gLevel > 8 then
  309.               gDifficulity = "Hardest"
  310.               gPoints = 1000
  311.               gBonus = 10000
  312.             end if
  313.           end if
  314.         end if
  315.       end if
  316.     "Medium":
  317.       if gLevel = 2 then
  318.         gDifficulity = "Hard"
  319.         gPoints = 500
  320.         gBonus = 5000
  321.       else
  322.         if gLevel = 4 then
  323.           gDifficulity = "Harder"
  324.           gPoints = 750
  325.           gBonus = 7500
  326.         else
  327.           if gLevel > 6 then
  328.             gDifficulity = "Hardest"
  329.             gPoints = 1000
  330.             gBonus = 10000
  331.           end if
  332.         end if
  333.       end if
  334.     "Hard":
  335.       if gLevel = 2 then
  336.         gDifficulity = "Harder"
  337.         gPoints = 750
  338.         gBonus = 7500
  339.       else
  340.         if gLevel > 4 then
  341.           gDifficulity = "Hardest"
  342.           gPoints = 1000
  343.           gBonus = 10000
  344.         end if
  345.       end if
  346.   end case
  347.   gLevel = gLevel + 1
  348. end
  349.