home *** CD-ROM | disk | FTP | other *** search
/ Shocking The Web CD-ROM / SHOCK_CD.ISO / pc / tutorial / devglry / zoetek / shockwav / files / dcr / cyber15.dcr / 00018.ls < prev    next >
Encoding:
Text File  |  1996-02-18  |  3.1 KB  |  198 lines

  1. on startMovie
  2.   global started
  3.   set started to 0
  4.   startTimer()
  5.   updateStage()
  6. end
  7.  
  8. on startUp
  9.   global started
  10.   if not started then
  11.     puppet16(1)
  12.     set started to 1
  13.   end if
  14. end
  15.  
  16. on keyDown
  17.   if the key = "s" then
  18.     scramble()
  19.   end if
  20.   if the key = "r" then
  21.     cheat()
  22.   end if
  23. end
  24.  
  25. on puppet16 value
  26.   repeat with x = 1 to 16
  27.     set the puppet of sprite x to value
  28.     recast(x, x)
  29.   end repeat
  30. end
  31.  
  32. on goback
  33.   go(1)
  34. end
  35.  
  36. on regap x
  37.   global gap, rgap, cgap
  38.   set gap to x
  39.   row(gap)
  40.   set rgap to the result
  41.   column(gap)
  42.   set cgap to the result
  43. end
  44.  
  45. on recast x, y
  46.   set the castNum of sprite x to y
  47.   if y = 1 then
  48.     regap(x)
  49.   end if
  50. end
  51.  
  52. on cheat
  53.   go("start")
  54.   repeat with x = 1 to 16
  55.     recast(x, x)
  56.   end repeat
  57.   updateStage()
  58. end
  59.  
  60. on scramble
  61.   go("start")
  62.   set done to 0
  63.   set x to 1
  64.   repeat while not done or (x < 100)
  65.     move(random(16))
  66.     set x to x + the result
  67.     contig()
  68.     set done to not (the result)
  69.     if not (x mod 10) then
  70.       updateStage()
  71.     end if
  72.   end repeat
  73.   updateStage()
  74. end
  75.  
  76. on row x
  77.   return ((x - 1) / 4) + 1
  78. end
  79.  
  80. on column x
  81.   return ((x - 1) mod 4) + 1
  82. end
  83.  
  84. on horiz x
  85.   global rgap, cgap
  86.   row(x)
  87.   set rx to the result
  88.   column(x)
  89.   set cx to the result
  90.   set loc to 0
  91.   if rgap = rx then
  92.     if cx < cgap then
  93.       set loc to 1
  94.     end if
  95.     if cx > cgap then
  96.       set loc to -1
  97.     end if
  98.   end if
  99.   return loc
  100. end
  101.  
  102. on vert x
  103.   global rgap, cgap
  104.   row(x)
  105.   set rx to the result
  106.   column(x)
  107.   set cx to the result
  108.   set loc to 0
  109.   if cgap = cx then
  110.     if rx < rgap then
  111.       set loc to 1
  112.     end if
  113.     if rx > rgap then
  114.       set loc to -1
  115.     end if
  116.   end if
  117.   return loc
  118. end
  119.  
  120. on move x
  121.   global gap, rgap
  122.   horiz(x)
  123.   set h to the result
  124.   vert(x)
  125.   set v to the result
  126.   row(x)
  127.   move1(x, v, the result, rgap, 4)
  128.   move1(x, h, x, gap, 1)
  129.   return h or v
  130. end
  131.  
  132. on move1 x, v, xrow, rgap, mult
  133.   global gap
  134.   set range to rgap - xrow - 1
  135.   if v < 0 then
  136.     set range to xrow - rgap - 1
  137.   end if
  138.   repeat with z = 0 to range
  139.     recast(gap + (-1 * v * z * mult), the castNum of sprite (gap + (-1 * v * z * mult) + (-1 * v * mult)))
  140.   end repeat
  141.   if v then
  142.     recast(x, 1)
  143.   end if
  144. end
  145.  
  146. on contig
  147.   set adj to 0
  148.   repeat with x = 1 to 4
  149.     repeat with y = 0 to 3
  150.       set loc to x + (4 * y)
  151.       set a to the castNum of sprite loc
  152.       if x < 4 then
  153.         set b to the castNum of sprite (loc + 1)
  154.         if (a + 1) = b then
  155.           set adj to 1
  156.         end if
  157.       end if
  158.       if y < 3 then
  159.         set c to the castNum of sprite (loc + 4)
  160.         if (a + 4) = c then
  161.           set adj to 1
  162.         end if
  163.       end if
  164.       if adj then
  165.         exit repeat
  166.       end if
  167.     end repeat
  168.     if adj then
  169.       exit repeat
  170.     end if
  171.   end repeat
  172.   return adj
  173. end
  174.  
  175. on done
  176.   set same to 1
  177.   repeat with x = 1 to 16
  178.     if the castNum of sprite x <> x then
  179.       set same to 0
  180.       exit repeat
  181.     end if
  182.   end repeat
  183.   if same then
  184.     repeat with a = 1 to 5
  185.       ink(4)
  186.       updateStage()
  187.       ink(0)
  188.       updateStage()
  189.     end repeat
  190.   end if
  191. end
  192.  
  193. on ink x
  194.   repeat with y = 2 to 16
  195.     set the ink of sprite y to x
  196.   end repeat
  197. end
  198.