home *** CD-ROM | disk | FTP | other *** search
/ Shocking The Web CD-ROM / SHOCK_CD.ISO / pc / powerapp / animator.exe / mwm.dcr / 00004_AnimatorClass.ls < prev    next >
Encoding:
Text File  |  1996-05-07  |  13.1 KB  |  401 lines

  1. property pChannel, pStartLoc, pFrameDataStart, pFrameData, pPathStartLoc, pPathEndLoc, pPathData, pSoundType, pSoundName, pIterations, pFrameRate, pbEveryFrame, pbPauseState, pbBackwards, pInkEffect, pbPreload, pScalePct, pLoopAction, pCompletionAction, pbVisibleState, pCurrentTime, pCurrentFrame, pAnimationFrames, pAnimationDuration, pPathFrames, pCurrentPathFrame, pStartTicks, pOffsetTicks, pTicksPerFrame, pLoopCounter, pCurrentLoc, pPathFunctionData, pbPathFunction, pDroppedFrames, pLastProfileTime, pProfilePeriod
  2. global gAnimationObjects, gAnimationChannelStart, gDeathRow, gPathSep, cNullCast
  3.  
  4. on birth me, arguments
  5.   set the pChannel of me to the channel of arguments
  6.   if the location of arguments = #NULL then
  7.     set the pStartLoc of me to the loc of sprite the pChannel of me
  8.   else
  9.     set the pStartLoc of me to the location of arguments
  10.   end if
  11.   set the pCurrentLoc of me to the pStartLoc of me
  12.   set the pFrameDataStart of me to the frameDataStart of arguments
  13.   if listp(the frameData of arguments) then
  14.     if stringp(getAt(the frameData of arguments, 1)) then
  15.       set theCount to count(the frameData of arguments)
  16.       repeat with x = 1 to theCount
  17.         setAt(the frameData of arguments, x, the number of cast getAt(the frameData of arguments, x))
  18.       end repeat
  19.     end if
  20.     set the pFrameData of me to the frameData of arguments
  21.   else
  22.     if integerp(the frameData of arguments) then
  23.       set the pFrameData of me to []
  24.       sort(the pFrameData of me)
  25.       repeat with theCast = the pFrameDataStart of me to the pFrameDataStart of me + the frameData of arguments - 1
  26.         add(the pFrameData of me, theCast)
  27.       end repeat
  28.     else
  29.       set the pFrameData of me to [the pFrameDataStart of me]
  30.       sort(the pFrameData of me)
  31.       set nextFrame to the pFrameDataStart of me
  32.       repeat while nextFrame < the frameData of arguments
  33.         set nextFrame to nextFrame + 1
  34.         add(the pFrameData of me, nextFrame)
  35.       end repeat
  36.     end if
  37.   end if
  38.   set the pLoopCounter of me to 0
  39.   set theFrameRate to the frameRate of arguments
  40.   if theFrameRate = #NULL then
  41.     set the pFrameRate of me to the frameTempo
  42.   else
  43.     set the pFrameRate of me to theFrameRate
  44.   end if
  45.   set the pbPathFunction of me to 0
  46.   set the pPathStartLoc of me to the pathStartLoc of arguments
  47.   set the pPathEndLoc of me to the pathEndLoc of arguments
  48.   if the pathData of arguments = #NULL then
  49.     set the pPathData of me to []
  50.   else
  51.     if the pathData of arguments = #CALC then
  52.       set the pPathData of me to pathList(the pPathStartLoc of me, the pPathEndLoc of me, the animationTime of arguments * the pFrameRate of me)
  53.     else
  54.       if symbolp(the pathData of arguments) then
  55.         set the pbPathFunction of me to 1
  56.         set the pPathFunctionData of me to the pathData of arguments
  57.         set the pPathData of me to []
  58.       else
  59.         set the pPathData of me to the pathData of arguments
  60.       end if
  61.     end if
  62.   end if
  63.   set the pFrameData of me to dataList(the pFrameData of me, the animationTime of arguments * the pFrameRate of me)
  64.   set the pSoundType of me to the soundType of arguments
  65.   set the pSoundName of me to the soundName of arguments
  66.   set theIterations to the iterations of arguments
  67.   if theIterations = #INFINITE then
  68.     set the pIterations of me to the maxinteger
  69.   else
  70.     set the pIterations of me to theIterations
  71.   end if
  72.   set theEveryFrame to the everyFrame of arguments
  73.   if theEveryFrame = #NULL then
  74.     set the pbEveryFrame of me to 1
  75.   else
  76.     set the pbEveryFrame of me to theEveryFrame
  77.   end if
  78.   set thePauseState to the pauseState of arguments
  79.   if thePauseState = #NULL then
  80.     set the pbPauseState of me to 0
  81.   else
  82.     set the pbPauseState of me to thePauseState
  83.   end if
  84.   set the pbBackwards of me to 0
  85.   set theInkEffects to the inkEffect of arguments
  86.   if theInkEffects = #NULL then
  87.     set the pInkEffect of me to 0
  88.   else
  89.     set the pInkEffect of me to getaProp([#copy: 0, #MATTE: 8, #BKTRANS: 36], theInkEffects)
  90.   end if
  91.   set the ink of sprite the pChannel of me to the pInkEffect of me
  92.   set the pScalePct of me to 100
  93.   set theLoopAction to the loopAction of arguments
  94.   if theLoopAction = #NULL then
  95.     set the pLoopAction of me to #repeat
  96.   else
  97.     set the pLoopAction of me to theLoopAction
  98.   end if
  99.   set theCompletionArguments to the completionAction of arguments
  100.   if theCompletionArguments = #NULL then
  101.     set the pCompletionAction of me to #death
  102.   else
  103.     set the pCompletionAction of me to theCompletionArguments
  104.   end if
  105.   set theVisibleState to the visibleState of arguments
  106.   if theVisibleState = #NULL then
  107.     set the pbVisibleState of me to 1
  108.   else
  109.     set the pbVisibleState of me to theVisibleState
  110.   end if
  111.   SoundAnimation(me)
  112.   VisualizeAnimation(me)
  113.   set the pCurrentTime of me to 0
  114.   set the pCurrentFrame of me to 1
  115.   set the pCurrentPathFrame of me to 1
  116.   set the pStartTicks of me to the ticks
  117.   set the pOffsetTicks of me to the pStartTicks of me
  118.   set thepFrameRate to the pFrameRate of me
  119.   if thepFrameRate < 61 then
  120.     set the pTicksPerFrame of me to 60 / thepFrameRate
  121.   else
  122.     set the pTicksPerFrame of me to 60 / float(thepFrameRate)
  123.   end if
  124.   set the pAnimationFrames of me to count(the pFrameData of me)
  125.   set the pPathFrames of me to count(the pPathData of me)
  126.   if the pIterations of me < the maxinteger then
  127.     set the pAnimationDuration of me to the pAnimationFrames of me * the pTicksPerFrame of me * the pIterations of me
  128.   else
  129.     set the pAnimationDuration of me to the maxinteger
  130.   end if
  131.   return me
  132. end
  133.  
  134. on dataList dataCore, outputLength
  135.   set loopLength to count(dataCore)
  136.   set outputList to []
  137.   set iterations to outputLength / loopLength
  138.   repeat with Counter = 1 to iterations
  139.     addLists(outputList, dataCore)
  140.   end repeat
  141.   set remainder to outputLength mod loopLength
  142.   repeat with Counter = 1 to remainder
  143.     add(outputList, getAt(dataCore, Counter))
  144.   end repeat
  145.   return outputList
  146. end
  147.  
  148. on pathList startLoc, endLoc, animationFrames
  149.   set pathData to [point(0, 0)]
  150.   set H to 1.0 * the locH of startLoc
  151.   set V to 1.0 * the locV of startLoc
  152.   set dH to 1.0 * (the locH of endLoc - H) / (animationFrames - 1)
  153.   set dV to 1.0 * (the locV of endLoc - V) / (animationFrames - 1)
  154.   set lastPoint to point(H, V)
  155.   repeat with x = 1 to animationFrames - 1
  156.     set H to H + dH
  157.     set V to V + dV
  158.     set newPoint to point(integer(H), integer(V))
  159.     add(pathData, newPoint)
  160.     set lastPoint to newPoint
  161.   end repeat
  162.   return pathData
  163. end
  164.  
  165. on addUnique theList, theItem
  166.   if getOne(theList, theItem) = 0 then
  167.     add(theList, theItem)
  168.   end if
  169. end
  170.  
  171. on SoundAnimation me
  172.   set soundType to the pSoundType of me
  173.   set soundName to the pSoundName of me
  174.   if soundType <> #NULL then
  175.     if soundType = #FILE then
  176.       playSound(soundName, #animatorFile)
  177.     else
  178.       if soundType = #FILELOOPED then
  179.         playSound(soundName, #animatorFileLooped)
  180.       else
  181.         if soundType = #cast then
  182.           playSound(soundName, #animatorCast)
  183.         end if
  184.       end if
  185.     end if
  186.   end if
  187. end
  188.  
  189. on VisualizeAnimation me
  190.   if pLoopAction = #palindrome then
  191.     MakePalindromeList(me)
  192.   end if
  193.   set the castNum of sprite the pChannel of me to the pFrameDataStart of me
  194.   SizeSprite(me)
  195.   if not (the pbVisibleState of me) then
  196.     setVisibleState(me, 0)
  197.   else
  198.     set the loc of sprite the pChannel of me to the pCurrentLoc of me
  199.   end if
  200. end
  201.  
  202. on death me
  203.   set theSoundName to the pSoundName of me
  204.   if theSoundName <> #NULL then
  205.     stopSound(the pSoundName of me)
  206.   end if
  207.   set the castNum of sprite the pChannel of me to cNullCast
  208.   set the loc of sprite the pChannel of me to point(2000, 2000)
  209.   set the ink of sprite the pChannel of me to 36
  210.   deleteProp(gAnimationObjects, the pChannel of me)
  211. end
  212.  
  213. on stepAnimation me
  214.   set elapsedTicks to CheckEXITS(me)
  215.   if elapsedTicks = #exit then
  216.     exit
  217.   end if
  218.   if not (the pbEveryFrame of me) then
  219.     set missedFrames to elapsedTicks / the pTicksPerFrame of me
  220.     set the pCurrentFrame of me to the pCurrentFrame of me + missedFrames
  221.     set the pCurrentPathFrame of me to the pCurrentPathFrame of me + missedFrames
  222.   else
  223.     set the pCurrentFrame of me to the pCurrentFrame of me + 1
  224.     set the pCurrentPathFrame of me to the pCurrentPathFrame of me + 1
  225.   end if
  226.   if LoopAnimation(me) <> #exit then
  227.     set the castNum of sprite the pChannel of me to getAt(the pFrameData of me, the pCurrentFrame of me)
  228.     SizeSprite(me)
  229.     set the pCurrentLoc of me to getAt(the pPathData of me, the pCurrentPathFrame of me)
  230.     set the loc of sprite the pChannel of me to the pCurrentLoc of me
  231.   end if
  232.   set the pCurrentTime of me to the ticks - the pOffsetTicks of me
  233. end
  234.  
  235. on CheckEXITS me
  236.   if the pbPauseState of me then
  237.     return #exit
  238.   end if
  239.   if not (the pbVisibleState of me) then
  240.     return #exit
  241.   end if
  242.   set elapsedTicks to the ticks - the pOffsetTicks of me - the pCurrentTime of me
  243.   if elapsedTicks < the pTicksPerFrame of me then
  244.     return #exit
  245.   end if
  246.   return elapsedTicks
  247. end
  248.  
  249. on LoopAnimation me
  250.   if the pCurrentPathFrame of me > the pPathFrames of me then
  251.     set the pCurrentPathFrame of me to 1
  252.   end if
  253.   if (the ticks - the pStartTicks of me) > the pAnimationDuration of me then
  254.     if the pCompletionAction of me = #death then
  255.       addUnique(gDeathRow, the pChannel of me)
  256.       return #exit
  257.     else
  258.       if the pCompletionAction of me = #pause then
  259.         setPauseState(me, 1)
  260.         return #exit
  261.       else
  262.         if stringp(the pCompletionAction of me) then
  263.           do(the pCompletionAction of me)
  264.           setPauseState(me, 1)
  265.           return #exit
  266.         end if
  267.       end if
  268.     end if
  269.     return #continue
  270.   end if
  271.   if the pCurrentFrame of me > the pAnimationFrames of me then
  272.     set the pCurrentFrame of me to 1
  273.     set the pLoopCounter of me to the pLoopCounter of me + 1
  274.     if the pLoopCounter of me < the pIterations of me then
  275.       if pLoopAction = #pause then
  276.         setPauseState(me, 1)
  277.         return #exit
  278.       else
  279.         set the pOffsetTicks of me to the ticks
  280.         if not (the pbPathFunction of me) then
  281.           set the pCurrentLoc of me to the pStartLoc of me
  282.         end if
  283.         return #continue
  284.       end if
  285.     else
  286.       if the pCompletionAction of me = #death then
  287.         addUnique(gDeathRow, the pChannel of me)
  288.         return #exit
  289.       else
  290.         if the pCompletionAction of me = #pause then
  291.           setPauseState(me, 1)
  292.           return #exit
  293.         else
  294.           if stringp(the pCompletionAction of me) then
  295.             do(the pCompletionAction of me)
  296.             setPauseState(me, 1)
  297.             return #exit
  298.           end if
  299.         end if
  300.       end if
  301.     end if
  302.     return #continue
  303.   end if
  304. end
  305.  
  306. on moveSprite me
  307.   set the pCurrentLoc of me to getAt(the pPathData of me, the pCurrentPathFrame of me)
  308.   set the loc of sprite the pChannel of me to the pCurrentLoc of me
  309. end
  310.  
  311. on SizeSprite me
  312.   if the pScalePct of me = 100 then
  313.     exit
  314.   end if
  315.   set theCast to the castNum of sprite the pChannel of me
  316.   set theSourceRect to the rect of cast theCast
  317.   set width to the width of cast theCast
  318.   set height to the height of cast theCast
  319.   set adjustPct to (the pScalePct of me - 100) / 200.0
  320.   set the rect of sprite the pChannel of me to inflate(theSourceRect, width * adjustPct, height * adjustPct)
  321. end
  322.  
  323. on setCurrentLoc me, thePoint
  324.   set the pCurrentLoc of me to thePoint
  325.   set the loc of sprite the pChannel of me to the pCurrentLoc of me
  326. end
  327.  
  328. on setCurrentFrame me, frame
  329.   if frame = #START then
  330.     set the pCurrentFrame of me to 1
  331.   else
  332.     if frame = #end then
  333.       set the pCurrentFrame of me to the pAnimationFrames of me
  334.     else
  335.       set the pCurrentFrame of me to frame
  336.     end if
  337.   end if
  338. end
  339.  
  340. on setPauseState me, state
  341.   set the pbPauseState of me to state
  342. end
  343.  
  344. on pauseToggle me
  345.   set the pbPauseState of me to not (the pbPauseState of me)
  346. end
  347.  
  348. on setVisibleState me, state
  349.   set the pbVisibleState of me to state
  350.   hideUnhide(me)
  351. end
  352.  
  353. on visibleToggle me
  354.   set the pbVisibleState of me to not (the pbVisibleState of me)
  355.   hideUnhide(me)
  356. end
  357.  
  358. on hideUnhide me
  359.   if the pbVisibleState of me then
  360.     set the visible of sprite the pChannel of me to 1
  361.   else
  362.     set the visible of sprite the pChannel of me to 0
  363.   end if
  364. end
  365.  
  366. on MakePalindromeList me
  367.   set aStart to count(the pFrameData of me)
  368.   if (aStart > 2) and (pPathData = #NULL) then
  369.     repeat with frame = aStart down to 2
  370.       add(the pFrameData of me, getAt(the pFrameData of me, frame))
  371.     end repeat
  372.   else
  373.     if (aStart > 2) and (count(pPathData) = aStart) then
  374.       repeat with frame = aStart - 1 down to 2
  375.         add(the pFrameData of me, getAt(the pFrameData of me, frame))
  376.       end repeat
  377.       repeat with frame = aStart down to 2
  378.         set newdata to -getAt(the pPathData of me, frame)
  379.         add(the pPathData of me, newdata)
  380.       end repeat
  381.     end if
  382.   end if
  383. end
  384.  
  385. on reverseFrameData me
  386.   set reversedFrameData to []
  387.   repeat with frame = the pAnimationFrames of me down to 1
  388.     add(reversedFrameData, getAt(the pFrameData of me, frame))
  389.   end repeat
  390.   set the pFrameData of me to value(string(reversedFrameData))
  391.   set the pCurrentFrame of me to the pAnimationFrames of me - the pCurrentFrame of me
  392. end
  393.  
  394. on preLoadData me
  395.   if the pbPreload of me then
  396.     repeat with castOffset in the pFrameData of me
  397.       preLoadCast(castOffset)
  398.     end repeat
  399.   end if
  400. end
  401.