home *** CD-ROM | disk | FTP | other *** search
/ Shocking The Web CD-ROM / SHOCK_CD.ISO / pc / powerapp / animator.exe / ANIMATOR.DXR / 00037_AnimatorClass.ls < prev    next >
Encoding:
Text File  |  1996-05-07  |  13.1 KB  |  405 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 divisor to animationFrames - 1
  153.   if divisor < 1 then
  154.     set divisor to 1
  155.   end if
  156.   set dH to 1.0 * (the locH of endLoc - H) / divisor
  157.   set dV to 1.0 * (the locV of endLoc - V) / divisor
  158.   set lastPoint to point(H, V)
  159.   repeat with x = 1 to animationFrames - 1
  160.     set H to H + dH
  161.     set V to V + dV
  162.     set newPoint to point(integer(H), integer(V))
  163.     add(pathData, newPoint)
  164.     set lastPoint to newPoint
  165.   end repeat
  166.   return pathData
  167. end
  168.  
  169. on addUnique theList, theItem
  170.   if getOne(theList, theItem) = 0 then
  171.     add(theList, theItem)
  172.   end if
  173. end
  174.  
  175. on SoundAnimation me
  176.   set soundType to the pSoundType of me
  177.   set soundName to the pSoundName of me
  178.   if soundType <> #NULL then
  179.     if soundType = #FILE then
  180.       playSound(soundName, #animatorFile)
  181.     else
  182.       if soundType = #FILELOOPED then
  183.         playSound(soundName, #animatorFileLooped)
  184.       else
  185.         if soundType = #cast then
  186.           playSound(soundName, #animatorCast)
  187.         end if
  188.       end if
  189.     end if
  190.   end if
  191. end
  192.  
  193. on VisualizeAnimation me
  194.   if pLoopAction = #palindrome then
  195.     MakePalindromeList(me)
  196.   end if
  197.   set the castNum of sprite the pChannel of me to the pFrameDataStart of me
  198.   SizeSprite(me)
  199.   if not (the pbVisibleState of me) then
  200.     setVisibleState(me, 0)
  201.   else
  202.     set the loc of sprite the pChannel of me to the pCurrentLoc of me
  203.   end if
  204. end
  205.  
  206. on death me
  207.   set theSoundName to the pSoundName of me
  208.   if theSoundName <> #NULL then
  209.     stopSound(the pSoundName of me)
  210.   end if
  211.   set the castNum of sprite the pChannel of me to cNullCast
  212.   set the loc of sprite the pChannel of me to point(2000, 2000)
  213.   set the ink of sprite the pChannel of me to 36
  214.   deleteProp(gAnimationObjects, the pChannel of me)
  215. end
  216.  
  217. on stepAnimation me
  218.   set elapsedTicks to CheckEXITS(me)
  219.   if elapsedTicks = #exit then
  220.     exit
  221.   end if
  222.   if not (the pbEveryFrame of me) then
  223.     set missedFrames to elapsedTicks / the pTicksPerFrame of me
  224.     set the pCurrentFrame of me to the pCurrentFrame of me + missedFrames
  225.     set the pCurrentPathFrame of me to the pCurrentPathFrame of me + missedFrames
  226.   else
  227.     set the pCurrentFrame of me to the pCurrentFrame of me + 1
  228.     set the pCurrentPathFrame of me to the pCurrentPathFrame of me + 1
  229.   end if
  230.   if LoopAnimation(me) <> #exit then
  231.     set the castNum of sprite the pChannel of me to getAt(the pFrameData of me, the pCurrentFrame of me)
  232.     SizeSprite(me)
  233.     set the pCurrentLoc of me to getAt(the pPathData of me, the pCurrentPathFrame of me)
  234.     set the loc of sprite the pChannel of me to the pCurrentLoc of me
  235.   end if
  236.   set the pCurrentTime of me to the ticks - the pOffsetTicks of me
  237. end
  238.  
  239. on CheckEXITS me
  240.   if the pbPauseState of me then
  241.     return #exit
  242.   end if
  243.   if not (the pbVisibleState of me) then
  244.     return #exit
  245.   end if
  246.   set elapsedTicks to the ticks - the pOffsetTicks of me - the pCurrentTime of me
  247.   if elapsedTicks < the pTicksPerFrame of me then
  248.     return #exit
  249.   end if
  250.   return elapsedTicks
  251. end
  252.  
  253. on LoopAnimation me
  254.   if the pCurrentPathFrame of me > the pPathFrames of me then
  255.     set the pCurrentPathFrame of me to 1
  256.   end if
  257.   if (the ticks - the pStartTicks of me) > the pAnimationDuration of me then
  258.     if the pCompletionAction of me = #death then
  259.       addUnique(gDeathRow, the pChannel of me)
  260.       return #exit
  261.     else
  262.       if the pCompletionAction of me = #pause then
  263.         setPauseState(me, 1)
  264.         return #exit
  265.       else
  266.         if stringp(the pCompletionAction of me) then
  267.           do(the pCompletionAction of me)
  268.           setPauseState(me, 1)
  269.           return #exit
  270.         end if
  271.       end if
  272.     end if
  273.     return #continue
  274.   end if
  275.   if the pCurrentFrame of me > the pAnimationFrames of me then
  276.     set the pCurrentFrame of me to 1
  277.     set the pLoopCounter of me to the pLoopCounter of me + 1
  278.     if the pLoopCounter of me < the pIterations of me then
  279.       if pLoopAction = #pause then
  280.         setPauseState(me, 1)
  281.         return #exit
  282.       else
  283.         set the pOffsetTicks of me to the ticks
  284.         if not (the pbPathFunction of me) then
  285.           set the pCurrentLoc of me to the pStartLoc of me
  286.         end if
  287.         return #continue
  288.       end if
  289.     else
  290.       if the pCompletionAction of me = #death then
  291.         addUnique(gDeathRow, the pChannel of me)
  292.         return #exit
  293.       else
  294.         if the pCompletionAction of me = #pause then
  295.           setPauseState(me, 1)
  296.           return #exit
  297.         else
  298.           if stringp(the pCompletionAction of me) then
  299.             do(the pCompletionAction of me)
  300.             setPauseState(me, 1)
  301.             return #exit
  302.           end if
  303.         end if
  304.       end if
  305.     end if
  306.     return #continue
  307.   end if
  308. end
  309.  
  310. on moveSprite me
  311.   set the pCurrentLoc of me to getAt(the pPathData of me, the pCurrentPathFrame of me)
  312.   set the loc of sprite the pChannel of me to the pCurrentLoc of me
  313. end
  314.  
  315. on SizeSprite me
  316.   if the pScalePct of me = 100 then
  317.     exit
  318.   end if
  319.   set theCast to the castNum of sprite the pChannel of me
  320.   set theSourceRect to the rect of cast theCast
  321.   set width to the width of cast theCast
  322.   set height to the height of cast theCast
  323.   set adjustPct to (the pScalePct of me - 100) / 200.0
  324.   set the rect of sprite the pChannel of me to inflate(theSourceRect, width * adjustPct, height * adjustPct)
  325. end
  326.  
  327. on setCurrentLoc me, thePoint
  328.   set the pCurrentLoc of me to thePoint
  329.   set the loc of sprite the pChannel of me to the pCurrentLoc of me
  330. end
  331.  
  332. on setCurrentFrame me, frame
  333.   if frame = #START then
  334.     set the pCurrentFrame of me to 1
  335.   else
  336.     if frame = #end then
  337.       set the pCurrentFrame of me to the pAnimationFrames of me
  338.     else
  339.       set the pCurrentFrame of me to frame
  340.     end if
  341.   end if
  342. end
  343.  
  344. on setPauseState me, state
  345.   set the pbPauseState of me to state
  346. end
  347.  
  348. on pauseToggle me
  349.   set the pbPauseState of me to not (the pbPauseState of me)
  350. end
  351.  
  352. on setVisibleState me, state
  353.   set the pbVisibleState of me to state
  354.   hideUnhide(me)
  355. end
  356.  
  357. on visibleToggle me
  358.   set the pbVisibleState of me to not (the pbVisibleState of me)
  359.   hideUnhide(me)
  360. end
  361.  
  362. on hideUnhide me
  363.   if the pbVisibleState of me then
  364.     set the visible of sprite the pChannel of me to 1
  365.   else
  366.     set the visible of sprite the pChannel of me to 0
  367.   end if
  368. end
  369.  
  370. on MakePalindromeList me
  371.   set aStart to count(the pFrameData of me)
  372.   if (aStart > 2) and (pPathData = #NULL) then
  373.     repeat with frame = aStart down to 2
  374.       add(the pFrameData of me, getAt(the pFrameData of me, frame))
  375.     end repeat
  376.   else
  377.     if (aStart > 2) and (count(pPathData) = aStart) then
  378.       repeat with frame = aStart - 1 down to 2
  379.         add(the pFrameData of me, getAt(the pFrameData of me, frame))
  380.       end repeat
  381.       repeat with frame = aStart down to 2
  382.         set newdata to -getAt(the pPathData of me, frame)
  383.         add(the pPathData of me, newdata)
  384.       end repeat
  385.     end if
  386.   end if
  387. end
  388.  
  389. on reverseFrameData me
  390.   set reversedFrameData to []
  391.   repeat with frame = the pAnimationFrames of me down to 1
  392.     add(reversedFrameData, getAt(the pFrameData of me, frame))
  393.   end repeat
  394.   set the pFrameData of me to value(string(reversedFrameData))
  395.   set the pCurrentFrame of me to the pAnimationFrames of me - the pCurrentFrame of me
  396. end
  397.  
  398. on preLoadData me
  399.   if the pbPreload of me then
  400.     repeat with castOffset in the pFrameData of me
  401.       preLoadCast(castOffset)
  402.     end repeat
  403.   end if
  404. end
  405.