home *** CD-ROM | disk | FTP | other *** search
/ 100 Plus Great Games 2 / 100PLUSV2.BIN / games / Tantrix.dxr / 00003_tileScript.ls < prev    next >
Encoding:
Text File  |  2002-01-25  |  13.9 KB  |  487 lines

  1. property spriteNum, pSpritePosition, pDiffX, pDiffY, pDirection, pRect, pRow, pColomn, pOverlay, pPickUpPoint, pTileProperty
  2. global gCurrentLevel, gSelectedTile, gTileArray, gArrayWidth, gArrayHeight, gTileWidth, gTileHeight, gTopLeftPoint, gNumTiles, gColorRequired
  3.  
  4. on beginSprite me
  5.   case spriteNum of
  6.     10:
  7.       sprite(10).loc = point(139, 191)
  8.     11:
  9.       sprite(11).loc = point(426, 187)
  10.     12:
  11.       sprite(12).loc = point(245, 124)
  12.     13:
  13.       sprite(13).loc = point(415, 342)
  14.     14:
  15.       sprite(14).loc = point(320, 353)
  16.     15:
  17.       sprite(15).loc = point(358, 125)
  18.     16:
  19.       sprite(16).loc = point(283, 182)
  20.     17:
  21.       sprite(17).loc = point(205, 264)
  22.     18:
  23.       sprite(18).loc = point(67, 135)
  24.     19:
  25.       sprite(19).loc = point(68, 263)
  26.     20:
  27.       sprite(20).loc = point(282, 290)
  28.     21:
  29.       sprite(21).loc = point(182, 348)
  30.     22:
  31.       sprite(22).loc = point(363, 246)
  32.     23:
  33.       sprite(23).loc = point(88, 351)
  34.   end case
  35.   if (spriteNum - 9) > gNumTiles then
  36.     sprite(spriteNum).loc = point(800, 800)
  37.     sprite(spriteNum + 23).loc = point(800, 800)
  38.     exit
  39.   end if
  40.   setTileProperty()
  41.   pRow = 1
  42.   pColomn = 1
  43.   dropTile()
  44.   pRect = sprite(spriteNum).rect
  45.   pDirection = 1
  46.   pSpritePosition = point(sprite(spriteNum).locH, sprite(spriteNum).locV)
  47. end
  48.  
  49. on resetTile me
  50. end
  51.  
  52. on setTileProperty me
  53.   case member(sprite(spriteNum).member).name of
  54.     "hex1":
  55.       sprite(spriteNum + 23).member = "1"
  56.       pTileProperty = [2, 3, 1, 1, 3, 2]
  57.     "hex2":
  58.       sprite(spriteNum + 23).member = "2"
  59.       pTileProperty = [1, 3, 1, 2, 3, 2]
  60.     "hex3":
  61.       sprite(spriteNum + 23).member = "3"
  62.       pTileProperty = [2, 1, 3, 3, 2, 1]
  63.     "hex4":
  64.       sprite(spriteNum + 23).member = "4"
  65.       pTileProperty = [1, 2, 3, 3, 1, 2]
  66.     "hex5":
  67.       sprite(spriteNum + 23).member = "5"
  68.       pTileProperty = [2, 2, 1, 1, 3, 3]
  69.     "hex6":
  70.       sprite(spriteNum + 23).member = "6"
  71.       pTileProperty = [2, 2, 3, 3, 1, 1]
  72.     "hex7":
  73.       sprite(spriteNum + 23).member = "7"
  74.       pTileProperty = [2, 1, 3, 3, 1, 2]
  75.     "hex8":
  76.       sprite(spriteNum + 23).member = "8"
  77.       pTileProperty = [2, 1, 2, 3, 1, 3]
  78.     "hex9":
  79.       sprite(spriteNum + 23).member = "9"
  80.       pTileProperty = [2, 3, 1, 1, 2, 3]
  81.     "hex10":
  82.       sprite(spriteNum + 23).member = "10"
  83.       pTileProperty = [3, 2, 1, 1, 3, 2]
  84.     "hex11":
  85.       sprite(spriteNum + 23).member = "11"
  86.       pTileProperty = [1, 2, 3, 3, 2, 1]
  87.     "hex12":
  88.       sprite(spriteNum + 23).member = "12"
  89.       pTileProperty = [1, 2, 1, 3, 2, 3]
  90.     "hex13":
  91.       sprite(spriteNum + 23).member = "13"
  92.       pTileProperty = [1, 3, 2, 2, 1, 3]
  93.     "hex14":
  94.       sprite(spriteNum + 23).member = "14"
  95.       pTileProperty = [3, 1, 2, 2, 3, 1]
  96.   end case
  97. end
  98.  
  99. on mouseUp me
  100.   if the frame > 15 then
  101.     exit
  102.   end if
  103.   if gSelectedTile <> spriteNum then
  104.     exit
  105.   end if
  106.   dropTile()
  107. end
  108.  
  109. on mouseDown me
  110.   if the frame > 15 then
  111.     exit
  112.   end if
  113.   pPickUpPoint = point(sprite(spriteNum).locH, sprite(spriteNum).locV)
  114.   gSelectedTile = spriteNum
  115.   pDiffX = sprite(spriteNum).locH - the mouseH
  116.   pDiffY = sprite(spriteNum).locV - the mouseV
  117.   sprite(spriteNum).locZ = 50
  118.   sprite(spriteNum + 23).locZ = 51
  119.   puppetSound(3, "pickup piece")
  120. end
  121.  
  122. on moveTile
  123.   if the frame > 15 then
  124.     exit
  125.   end if
  126.   if gSelectedTile <> spriteNum then
  127.     exit
  128.   end if
  129.   pRect = rect(mouseH() - (sprite(spriteNum).width / 2) + pDiffX, mouseV() - (sprite(spriteNum).height / 2) + pDiffY, mouseH() + (sprite(spriteNum).width / 2) + pDiffX, mouseV() + (sprite(spriteNum).height / 2) + pDiffY)
  130.   revolvePenatration()
  131.   sprite(spriteNum).loc = point(pRect[1] + (sprite(spriteNum).width / 2), pRect[2] + (sprite(spriteNum).height / 2))
  132.   if sprite(spriteNum).locH < (gTopLeftPoint[1] + 2) then
  133.     sprite(spriteNum).locH = gTopLeftPoint[1] + 2
  134.   end if
  135.   if sprite(spriteNum).locV < gTopLeftPoint[2] then
  136.     sprite(spriteNum).locV = gTopLeftPoint[2]
  137.   end if
  138.   if sprite(spriteNum).locH > (gTopLeftPoint[1] + (gArrayWidth * gTileWidth) - gTileWidth - 5) then
  139.     sprite(spriteNum).locH = gTopLeftPoint[1] + (gArrayWidth * gTileWidth) - gTileWidth - 5
  140.   end if
  141.   if sprite(spriteNum).locV > (gTopLeftPoint[2] + (gArrayHeight * gTileHeight) - gTileHeight - 5) then
  142.     sprite(spriteNum).locV = gTopLeftPoint[2] + (gArrayHeight * gTileHeight) - gTileHeight - 5
  143.   end if
  144.   sprite(spriteNum + 23).loc = sprite(spriteNum).loc
  145. end
  146.  
  147. on dropTile
  148.   if the frame > 15 then
  149.     exit
  150.   end if
  151.   sprite(spriteNum).locZ = spriteNum
  152.   sprite(spriteNum + 23).locZ = spriteNum + 23
  153.   gSelectedTile = 0
  154.   diffX = (sprite(spriteNum).locH - gTopLeftPoint[1]) mod gTileWidth
  155.   if diffX > (gTileWidth / 2) then
  156.     sprite(spriteNum).locH = sprite(spriteNum).locH - diffX + gTileWidth
  157.   else
  158.     sprite(spriteNum).locH = sprite(spriteNum).locH - diffX
  159.   end if
  160.   theColomn = integer((sprite(spriteNum).locH - gTopLeftPoint[1]) / gTileWidth)
  161.   if not ((theColomn mod 2) = 0) then
  162.     diffY = (sprite(spriteNum).locV - gTopLeftPoint[2]) mod gTileHeight
  163.     if diffY > (gTileHeight / 2) then
  164.       sprite(spriteNum).locV = sprite(spriteNum).locV - diffY + gTileHeight
  165.     else
  166.       sprite(spriteNum).locV = sprite(spriteNum).locV - diffY
  167.     end if
  168.   else
  169.     diffY = (sprite(spriteNum).locV - (gTileHeight / 2) - gTopLeftPoint[2]) mod gTileHeight
  170.     if diffY > (gTileHeight / 2) then
  171.       sprite(spriteNum).locV = sprite(spriteNum).locV - diffY + gTileHeight
  172.     else
  173.       sprite(spriteNum).locV = sprite(spriteNum).locV - diffY
  174.     end if
  175.   end if
  176.   theRow = integer((sprite(spriteNum).locV - gTopLeftPoint[2]) / gTileHeight) + 1
  177.   theColomn = theColomn + 1
  178.   updateStage()
  179.   pRect = sprite(spriteNum).rect
  180.   sprite(spriteNum + 23).loc = sprite(spriteNum).loc
  181.   if (pRow = theRow) and (pColomn = theColomn) then
  182.     puppetSound(3, "rotate")
  183.     rotateHex()
  184.   else
  185.     puppetSound(3, "drop piece")
  186.     if gTileArray[theRow][theColomn] > 0 then
  187.       sprite(spriteNum).loc = pPickUpPoint
  188.       sprite(spriteNum + 23).loc = pPickUpPoint
  189.     else
  190.       gTileArray[pRow][pColomn] = 0
  191.       pRow = theRow
  192.       pColomn = theColomn
  193.       gTileArray[pRow][pColomn] = spriteNum
  194.     end if
  195.   end if
  196.   if checkIfPuzzleSolved() = 1 then
  197.     if gCurrentLevel >= 10 then
  198.       puppetSound(1, "win")
  199.       go(19)
  200.     else
  201.       puppetSound(1, "levelcomplete10")
  202.       go(34)
  203.     end if
  204.   end if
  205. end
  206.  
  207. on revolvePenatration me
  208.   if checkIfIntersection() = 1 then
  209.   end if
  210. end
  211.  
  212. on rotateHex me
  213.   pDirection = pDirection + 1
  214.   if pDirection > 6 then
  215.     pDirection = 1
  216.   end if
  217.   case pDirection of
  218.     1:
  219.       sprite(spriteNum + 23).rotation = 0
  220.     2:
  221.       sprite(spriteNum + 23).rotation = 60
  222.     3:
  223.       sprite(spriteNum + 23).rotation = 120
  224.     4:
  225.       sprite(spriteNum + 23).rotation = 180
  226.     5:
  227.       sprite(spriteNum + 23).rotation = 240
  228.     6:
  229.       sprite(spriteNum + 23).rotation = 300
  230.   end case
  231.   temp = pTileProperty[count(pTileProperty)]
  232.   deleteAt(pTileProperty, count(pTileProperty))
  233.   addAt(pTileProperty, 1, temp)
  234.   updateStage()
  235. end
  236.  
  237. on checkIfIntersection me
  238.   bool = 0
  239.   repeat with counter = 10 to 9 + gNumTiles
  240.     if myIntersection(pRect, counter) then
  241.       if spriteNum <> counter then
  242.         bool = 1
  243.       end if
  244.     end if
  245.   end repeat
  246.   return bool
  247. end
  248.  
  249. on getHexProperty
  250.   return duplicate(pTileProperty)
  251. end
  252.  
  253. on checkIfPuzzleSolved
  254.   repeat with counterX = 1 to gArrayWidth
  255.     repeat with counterY = 1 to gArrayHeight
  256.       if checkOutOfBounds(counterX, counterY) = 1 then
  257.         if gTileArray[counterY][counterX] > 0 then
  258.           firstX = counterX
  259.           firstY = counterY
  260.           checkX = counterX - 1
  261.           if not ((counterX mod 2) = 0) then
  262.             checkY = counterY
  263.           else
  264.             checkY = counterY - 1
  265.           end if
  266.           if checkOutOfBounds(checkX, checkY) = 1 then
  267.             Prop = sendSprite(gTileArray[checkY][checkX], #getHexProperty)
  268.             checkProp = sendSprite(gTileArray[counterY][counterX], #getHexProperty)
  269.             if Prop[4] <> checkProp[1] then
  270.               return 0
  271.             end if
  272.           end if
  273.           checkY = counterY - 1
  274.           checkX = counterX
  275.           if checkOutOfBounds(checkX, checkY) = 1 then
  276.             Prop = sendSprite(gTileArray[checkY][checkX], #getHexProperty)
  277.             checkProp = sendSprite(gTileArray[counterY][counterX], #getHexProperty)
  278.             if Prop[5] <> checkProp[2] then
  279.               return 0
  280.             end if
  281.           end if
  282.           checkX = counterX + 1
  283.           if not ((counterX mod 2) = 0) then
  284.             checkY = counterY
  285.           else
  286.             checkY = counterY - 1
  287.           end if
  288.           if checkOutOfBounds(checkX, checkY) = 1 then
  289.             Prop = sendSprite(gTileArray[checkY][checkX], #getHexProperty)
  290.             checkProp = sendSprite(gTileArray[counterY][counterX], #getHexProperty)
  291.             if Prop[6] <> checkProp[3] then
  292.               return 0
  293.             end if
  294.           end if
  295.           checkX = counterX + 1
  296.           if not ((counterX mod 2) = 0) then
  297.             checkY = counterY + 1
  298.           else
  299.             checkY = counterY
  300.           end if
  301.           if checkOutOfBounds(checkX, checkY) = 1 then
  302.             Prop = sendSprite(gTileArray[checkY][checkX], #getHexProperty)
  303.             checkProp = sendSprite(gTileArray[counterY][counterX], #getHexProperty)
  304.             if Prop[1] <> checkProp[4] then
  305.               return 0
  306.             end if
  307.           end if
  308.           checkY = counterY + 1
  309.           checkX = counterX
  310.           if checkOutOfBounds(checkX, checkY) = 1 then
  311.             Prop = sendSprite(gTileArray[checkY][checkX], #getHexProperty)
  312.             checkProp = sendSprite(gTileArray[counterY][counterX], #getHexProperty)
  313.             if Prop[2] <> checkProp[5] then
  314.               return 0
  315.             end if
  316.           end if
  317.           checkX = counterX - 1
  318.           if not ((counterX mod 2) = 0) then
  319.             checkY = counterY + 1
  320.           else
  321.             checkY = counterY
  322.           end if
  323.           if checkOutOfBounds(checkX, checkY) = 1 then
  324.             Prop = sendSprite(gTileArray[checkY][checkX], #getHexProperty)
  325.             checkProp = sendSprite(gTileArray[counterY][counterX], #getHexProperty)
  326.             if Prop[3] <> checkProp[6] then
  327.               return 0
  328.             end if
  329.           end if
  330.         end if
  331.       end if
  332.     end repeat
  333.   end repeat
  334.   repeat with counterX = 1 to gArrayWidth
  335.     repeat with counterY = 1 to gArrayHeight
  336.       if checkOutOfBounds(counterX, counterY) = 1 then
  337.         if gTileArray[counterY][counterX] > 0 then
  338.           firstX = counterX
  339.           firstY = counterY
  340.         end if
  341.       end if
  342.     end repeat
  343.   end repeat
  344.   wereDone = 0
  345.   tileCount = 1
  346.   Prop = sendSprite(gTileArray[firstY][firstX], #getHexProperty)
  347.   if Prop[1] = gColorRequired then
  348.     theNextSide = 1
  349.   else
  350.     if Prop[2] = gColorRequired then
  351.       theNextSide = 2
  352.     else
  353.       if Prop[3] = gColorRequired then
  354.         theNextSide = 3
  355.       else
  356.         if Prop[4] = gColorRequired then
  357.           theNextSide = 4
  358.         else
  359.           if Prop[5] = gColorRequired then
  360.             theNextSide = 5
  361.           else
  362.             if Prop[6] = gColorRequired then
  363.               theNextSide = 6
  364.             end if
  365.           end if
  366.         end if
  367.       end if
  368.     end if
  369.   end if
  370.   nextX = firstX
  371.   nextY = firstY
  372.   repeat while wereDone = 0
  373.     case theNextSide of
  374.       1:
  375.         if not ((nextX mod 2) = 0) then
  376.           nextY = nextY
  377.         else
  378.           nextY = nextY - 1
  379.         end if
  380.         nextX = nextX - 1
  381.         if checkOutOfBounds(nextX, nextY) = 0 then
  382.           return 0
  383.         end if
  384.         theNextSide = 4
  385.       2:
  386.         nextY = nextY - 1
  387.         nextX = nextX
  388.         if checkOutOfBounds(nextX, nextY) = 0 then
  389.           return 0
  390.         end if
  391.         theNextSide = 5
  392.       3:
  393.         if not ((nextX mod 2) = 0) then
  394.           nextY = nextY
  395.         else
  396.           nextY = nextY - 1
  397.         end if
  398.         nextX = nextX + 1
  399.         if checkOutOfBounds(nextX, nextY) = 0 then
  400.           return 0
  401.         end if
  402.         theNextSide = 6
  403.       4:
  404.         if not ((nextX mod 2) = 0) then
  405.           nextY = nextY + 1
  406.         else
  407.           nextY = nextY
  408.         end if
  409.         nextX = nextX + 1
  410.         if checkOutOfBounds(nextX, nextY) = 0 then
  411.           return 0
  412.         end if
  413.         theNextSide = 1
  414.       5:
  415.         nextY = nextY + 1
  416.         nextX = nextX
  417.         if checkOutOfBounds(nextX, nextY) = 0 then
  418.           return 0
  419.         end if
  420.         theNextSide = 2
  421.       6:
  422.         if not ((nextX mod 2) = 0) then
  423.           nextY = nextY + 1
  424.         else
  425.           nextY = nextY
  426.         end if
  427.         nextX = nextX - 1
  428.         if checkOutOfBounds(nextX, nextY) = 0 then
  429.           return 0
  430.         end if
  431.         theNextSide = 3
  432.     end case
  433.     if (nextX = firstX) and (nextY = firstY) then
  434.       if tileCount = gNumTiles then
  435.         return 1
  436.       else
  437.         return 0
  438.       end if
  439.     end if
  440.     Prop = sendSprite(gTileArray[nextY][nextX], #getHexProperty)
  441.     if Prop[theNextSide] <> gColorRequired then
  442.       return 0
  443.     end if
  444.     if (Prop[1] = gColorRequired) and (theNextSide <> 1) then
  445.       theNextSide = 1
  446.     else
  447.       if (Prop[2] = gColorRequired) and (theNextSide <> 2) then
  448.         theNextSide = 2
  449.       else
  450.         if (Prop[3] = gColorRequired) and (theNextSide <> 3) then
  451.           theNextSide = 3
  452.         else
  453.           if (Prop[4] = gColorRequired) and (theNextSide <> 4) then
  454.             theNextSide = 4
  455.           else
  456.             if (Prop[5] = gColorRequired) and (theNextSide <> 5) then
  457.               theNextSide = 5
  458.             else
  459.               if (Prop[6] = gColorRequired) and (theNextSide <> 6) then
  460.                 theNextSide = 6
  461.               end if
  462.             end if
  463.           end if
  464.         end if
  465.       end if
  466.     end if
  467.     tileCount = tileCount + 1
  468.   end repeat
  469.   return 1
  470. end
  471.  
  472. on checkOutOfBounds elementX, elementY
  473.   if (elementX < 1) or (elementY < 1) then
  474.     return 0
  475.   end if
  476.   if (elementY > gArrayHeight) or (elementX > gArrayWidth) then
  477.     return 0
  478.   end if
  479.   if not ((elementX mod 2) = 0) and (elementY > (gArrayHeight - 1)) then
  480.     return 0
  481.   end if
  482.   if gTileArray[elementY][elementX] = 0 then
  483.     return 0
  484.   end if
  485.   return 1
  486. end
  487.