home *** CD-ROM | disk | FTP | other *** search
/ VCD Film, Television & An…on Creation Encyclopedia / mycd.iso / Direct5 / DATA.Z / MECH.DIR / 00076_aPegBoard.ls < prev    next >
Encoding:
Text File  |  1996-03-15  |  4.0 KB  |  174 lines

  1. property PEG_columns, PEG_rows, myHPegs, myVPegs, myAnimator, myButtons
  2. global gMyPegBoard, gConstrainSprite, gIsRunning, gHandCursor, gSpeedCntrSprite
  3.  
  4. on new me
  5.   set PEG_columns to 16
  6.   set PEG_rows to 11
  7.   set myButtons to 28
  8.   puppetSprite(myButtons, 1)
  9.   set myHPegs to []
  10.   set count to 2
  11.   setAt(myHPegs, 1, 48)
  12.   repeat while count < PEG_columns
  13.     set pos to 48 + ((count - 1) * 30)
  14.     setAt(myHPegs, count, pos)
  15.     set count to count + 1
  16.   end repeat
  17.   setAt(myHPegs, count, pos)
  18.   set myVPegs to []
  19.   set count to 2
  20.   setAt(myVPegs, 1, 50)
  21.   repeat while count < PEG_rows
  22.     set pos to 50 + ((count - 1) * 30)
  23.     setAt(myVPegs, count, pos)
  24.     set count to count + 1
  25.   end repeat
  26.   setAt(myVPegs, count, pos)
  27.   puppetSprite(gSpeedCntrSprite, 1)
  28.   set the immediate of sprite gSpeedCntrSprite to 1
  29.   set myAnimator to new(script "aAnimator")
  30.   return me
  31. end
  32.  
  33. on mClearPegs me
  34.   mClearActors(myAnimator)
  35.   set myAnimator to 0
  36.   set myHPegs to 0
  37.   set myVPegs to 0
  38. end
  39.  
  40. on mSnapTo me, thePart
  41.   global gConstrainSprite
  42.   set aSprite to the clickOn
  43.   if (aSprite > 4) and (aSprite < 22) then
  44.     set the constraint of sprite aSprite to gConstrainSprite
  45.     mFindNearestHPeg(me, aSprite)
  46.     mFindNearestVPeg(me, aSprite)
  47.     mBroadCastParts(myAnimator)
  48.     if aSprite <= 8 then
  49.       mSetAtributes(myAnimator, aSprite)
  50.     end if
  51.   end if
  52. end
  53.  
  54. on mFindNearestHPeg me, aSprite
  55.   global gConstrainSprite
  56.   set continueSearch to 1
  57.   set aHloc to the locH of sprite aSprite
  58.   set count to PEG_columns - 1
  59.   set pegLocUpper to getAt(myHPegs, count)
  60.   set pegLocLower to getAt(myHPegs, count - 1)
  61.   repeat while continueSearch and (count > 0)
  62.     if (aHloc >= pegLocLower) and (aHloc <= pegLocUpper) then
  63.       set continueSearch to 0
  64.     end if
  65.     if (count = 1) and continueSearch then
  66.       set continueSearch to 0
  67.       next repeat
  68.     end if
  69.     if continueSearch then
  70.       set pegLocLower to getAt(myHPegs, count - 1)
  71.       set pegLocUpper to getAt(myHPegs, count)
  72.       set count to count - 1
  73.     end if
  74.   end repeat
  75.   if (aHloc - pegLocLower) > (pegLocUpper - aHloc) then
  76.     set the locH of sprite aSprite to pegLocUpper
  77.   else
  78.     set the locH of sprite aSprite to pegLocLower
  79.   end if
  80. end
  81.  
  82. on mFindNearestVPeg me, aSprite
  83.   set count to PEG_rows - 1
  84.   set aVloc to the locV of sprite aSprite
  85.   set continueSearch to 1
  86.   set pegLocUpper to getAt(myVPegs, count)
  87.   set pegLocLower to getAt(myVPegs, count - 1)
  88.   repeat while continueSearch and (count > 0)
  89.     if (aVloc >= pegLocLower) and (aHloc <= pegLocUpper) then
  90.       set continueSearch to 0
  91.     end if
  92.     if (count = 1) and continueSearch then
  93.       set continueSearch to 0
  94.       next repeat
  95.     end if
  96.     if continueSearch then
  97.       set pegLocLower to getAt(myVPegs, count - 1)
  98.       set pegLocUpper to getAt(myVPegs, count)
  99.       set count to count - 1
  100.     end if
  101.   end repeat
  102.   if (aVloc - pegLocLower) > (pegLocUpper - aVloc) then
  103.     set the locV of sprite aSprite to pegLocUpper
  104.   else
  105.     set the locV of sprite aSprite to pegLocLower
  106.   end if
  107. end
  108.  
  109. on mSetSpeed me
  110.   mSetSpeed(myAnimator)
  111. end
  112.  
  113. on mMakeVacChute me
  114.   mMakeVacChute(myAnimator)
  115. end
  116.  
  117. on mStartMotor me
  118.   mBroadCastParts(myAnimator)
  119.   set the castNum of sprite myButtons to 164
  120. end
  121.  
  122. on mStopMotor me
  123.   set the castNum of sprite myButtons to 168
  124. end
  125.  
  126. on mGetAnimator me
  127.   return myAnimator
  128. end
  129.  
  130. on mTestPartsPalletClick me, partNumber
  131.   mCreatPart(myAnimator, partNumber)
  132. end
  133.  
  134. on mBounceBall me
  135.   mBounceBall(myAnimator)
  136. end
  137.  
  138. on mResetCntrl me
  139.   if gIsRunning then
  140.     set the castNum of sprite myButtons to 164
  141.   else
  142.     set the castNum of sprite myButtons to 168
  143.   end if
  144.   updateStage()
  145. end
  146.  
  147. on mGetMechSim me
  148.   if gIsRunning then
  149.     set the castNum of sprite myButtons to 163
  150.   else
  151.     set the castNum of sprite myButtons to 167
  152.   end if
  153.   updateStage()
  154.   return mGetMechSim(myAnimator)
  155. end
  156.  
  157. on mSetMechSim me
  158.   if gIsRunning then
  159.     set the castNum of sprite myButtons to 162
  160.   else
  161.     set the castNum of sprite myButtons to 166
  162.   end if
  163.   updateStage()
  164.   mSetMechSim(myAnimator)
  165. end
  166.  
  167. on mRotorRotation me
  168.   stepFrame(myAnimator)
  169. end
  170.  
  171. on mClearBoard me
  172.   mClearAllParts(myAnimator)
  173. end
  174.