home *** CD-ROM | disk | FTP | other *** search
- 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
- global gAnimationObjects, gAnimationChannelStart, gDeathRow, gPathSep, cNullCast
-
- on birth me, arguments
- set the pChannel of me to the channel of arguments
- if the location of arguments = #NULL then
- set the pStartLoc of me to the loc of sprite the pChannel of me
- else
- set the pStartLoc of me to the location of arguments
- end if
- set the pCurrentLoc of me to the pStartLoc of me
- set the pFrameDataStart of me to the frameDataStart of arguments
- if listp(the frameData of arguments) then
- if stringp(getAt(the frameData of arguments, 1)) then
- set theCount to count(the frameData of arguments)
- repeat with x = 1 to theCount
- setAt(the frameData of arguments, x, the number of cast getAt(the frameData of arguments, x))
- end repeat
- end if
- set the pFrameData of me to the frameData of arguments
- else
- if integerp(the frameData of arguments) then
- set the pFrameData of me to []
- sort(the pFrameData of me)
- repeat with theCast = the pFrameDataStart of me to the pFrameDataStart of me + the frameData of arguments - 1
- add(the pFrameData of me, theCast)
- end repeat
- else
- set the pFrameData of me to [the pFrameDataStart of me]
- sort(the pFrameData of me)
- set nextFrame to the pFrameDataStart of me
- repeat while nextFrame < the frameData of arguments
- set nextFrame to nextFrame + 1
- add(the pFrameData of me, nextFrame)
- end repeat
- end if
- end if
- set the pLoopCounter of me to 0
- set theFrameRate to the frameRate of arguments
- if theFrameRate = #NULL then
- set the pFrameRate of me to the frameTempo
- else
- set the pFrameRate of me to theFrameRate
- end if
- set the pbPathFunction of me to 0
- set the pPathStartLoc of me to the pathStartLoc of arguments
- set the pPathEndLoc of me to the pathEndLoc of arguments
- if the pathData of arguments = #NULL then
- set the pPathData of me to []
- else
- if the pathData of arguments = #CALC then
- set the pPathData of me to pathList(the pPathStartLoc of me, the pPathEndLoc of me, the animationTime of arguments * the pFrameRate of me)
- else
- if symbolp(the pathData of arguments) then
- set the pbPathFunction of me to 1
- set the pPathFunctionData of me to the pathData of arguments
- set the pPathData of me to []
- else
- set the pPathData of me to the pathData of arguments
- end if
- end if
- end if
- set the pFrameData of me to dataList(the pFrameData of me, the animationTime of arguments * the pFrameRate of me)
- set the pSoundType of me to the soundType of arguments
- set the pSoundName of me to the soundName of arguments
- set theIterations to the iterations of arguments
- if theIterations = #INFINITE then
- set the pIterations of me to the maxinteger
- else
- set the pIterations of me to theIterations
- end if
- set theEveryFrame to the everyFrame of arguments
- if theEveryFrame = #NULL then
- set the pbEveryFrame of me to 1
- else
- set the pbEveryFrame of me to theEveryFrame
- end if
- set thePauseState to the pauseState of arguments
- if thePauseState = #NULL then
- set the pbPauseState of me to 0
- else
- set the pbPauseState of me to thePauseState
- end if
- set the pbBackwards of me to 0
- set theInkEffects to the inkEffect of arguments
- if theInkEffects = #NULL then
- set the pInkEffect of me to 0
- else
- set the pInkEffect of me to getaProp([#copy: 0, #MATTE: 8, #BKTRANS: 36], theInkEffects)
- end if
- set the ink of sprite the pChannel of me to the pInkEffect of me
- set the pScalePct of me to 100
- set theLoopAction to the loopAction of arguments
- if theLoopAction = #NULL then
- set the pLoopAction of me to #repeat
- else
- set the pLoopAction of me to theLoopAction
- end if
- set theCompletionArguments to the completionAction of arguments
- if theCompletionArguments = #NULL then
- set the pCompletionAction of me to #death
- else
- set the pCompletionAction of me to theCompletionArguments
- end if
- set theVisibleState to the visibleState of arguments
- if theVisibleState = #NULL then
- set the pbVisibleState of me to 1
- else
- set the pbVisibleState of me to theVisibleState
- end if
- SoundAnimation(me)
- VisualizeAnimation(me)
- set the pCurrentTime of me to 0
- set the pCurrentFrame of me to 1
- set the pCurrentPathFrame of me to 1
- set the pStartTicks of me to the ticks
- set the pOffsetTicks of me to the pStartTicks of me
- set thepFrameRate to the pFrameRate of me
- if thepFrameRate < 61 then
- set the pTicksPerFrame of me to 60 / thepFrameRate
- else
- set the pTicksPerFrame of me to 60 / float(thepFrameRate)
- end if
- set the pAnimationFrames of me to count(the pFrameData of me)
- set the pPathFrames of me to count(the pPathData of me)
- if the pIterations of me < the maxinteger then
- set the pAnimationDuration of me to the pAnimationFrames of me * the pTicksPerFrame of me * the pIterations of me
- else
- set the pAnimationDuration of me to the maxinteger
- end if
- return me
- end
-
- on dataList dataCore, outputLength
- set loopLength to count(dataCore)
- set outputList to []
- set iterations to outputLength / loopLength
- repeat with Counter = 1 to iterations
- addLists(outputList, dataCore)
- end repeat
- set remainder to outputLength mod loopLength
- repeat with Counter = 1 to remainder
- add(outputList, getAt(dataCore, Counter))
- end repeat
- return outputList
- end
-
- on pathList startLoc, endLoc, animationFrames
- set pathData to [point(0, 0)]
- set H to 1.0 * the locH of startLoc
- set V to 1.0 * the locV of startLoc
- set dH to 1.0 * (the locH of endLoc - H) / (animationFrames - 1)
- set dV to 1.0 * (the locV of endLoc - V) / (animationFrames - 1)
- set lastPoint to point(H, V)
- repeat with x = 1 to animationFrames - 1
- set H to H + dH
- set V to V + dV
- set newPoint to point(integer(H), integer(V))
- add(pathData, newPoint)
- set lastPoint to newPoint
- end repeat
- return pathData
- end
-
- on addUnique theList, theItem
- if getOne(theList, theItem) = 0 then
- add(theList, theItem)
- end if
- end
-
- on SoundAnimation me
- set soundType to the pSoundType of me
- set soundName to the pSoundName of me
- if soundType <> #NULL then
- if soundType = #FILE then
- playSound(soundName, #animatorFile)
- else
- if soundType = #FILELOOPED then
- playSound(soundName, #animatorFileLooped)
- else
- if soundType = #cast then
- playSound(soundName, #animatorCast)
- end if
- end if
- end if
- end if
- end
-
- on VisualizeAnimation me
- if pLoopAction = #palindrome then
- MakePalindromeList(me)
- end if
- set the castNum of sprite the pChannel of me to the pFrameDataStart of me
- SizeSprite(me)
- if not (the pbVisibleState of me) then
- setVisibleState(me, 0)
- else
- set the loc of sprite the pChannel of me to the pCurrentLoc of me
- end if
- end
-
- on death me
- set theSoundName to the pSoundName of me
- if theSoundName <> #NULL then
- stopSound(the pSoundName of me)
- end if
- set the castNum of sprite the pChannel of me to cNullCast
- set the loc of sprite the pChannel of me to point(2000, 2000)
- set the ink of sprite the pChannel of me to 36
- deleteProp(gAnimationObjects, the pChannel of me)
- end
-
- on stepAnimation me
- set elapsedTicks to CheckEXITS(me)
- if elapsedTicks = #exit then
- exit
- end if
- if not (the pbEveryFrame of me) then
- set missedFrames to elapsedTicks / the pTicksPerFrame of me
- set the pCurrentFrame of me to the pCurrentFrame of me + missedFrames
- set the pCurrentPathFrame of me to the pCurrentPathFrame of me + missedFrames
- else
- set the pCurrentFrame of me to the pCurrentFrame of me + 1
- set the pCurrentPathFrame of me to the pCurrentPathFrame of me + 1
- end if
- if LoopAnimation(me) <> #exit then
- set the castNum of sprite the pChannel of me to getAt(the pFrameData of me, the pCurrentFrame of me)
- SizeSprite(me)
- set the pCurrentLoc of me to getAt(the pPathData of me, the pCurrentPathFrame of me)
- set the loc of sprite the pChannel of me to the pCurrentLoc of me
- end if
- set the pCurrentTime of me to the ticks - the pOffsetTicks of me
- end
-
- on CheckEXITS me
- if the pbPauseState of me then
- return #exit
- end if
- if not (the pbVisibleState of me) then
- return #exit
- end if
- set elapsedTicks to the ticks - the pOffsetTicks of me - the pCurrentTime of me
- if elapsedTicks < the pTicksPerFrame of me then
- return #exit
- end if
- return elapsedTicks
- end
-
- on LoopAnimation me
- if the pCurrentPathFrame of me > the pPathFrames of me then
- set the pCurrentPathFrame of me to 1
- end if
- if (the ticks - the pStartTicks of me) > the pAnimationDuration of me then
- if the pCompletionAction of me = #death then
- addUnique(gDeathRow, the pChannel of me)
- return #exit
- else
- if the pCompletionAction of me = #pause then
- setPauseState(me, 1)
- return #exit
- else
- if stringp(the pCompletionAction of me) then
- do(the pCompletionAction of me)
- setPauseState(me, 1)
- return #exit
- end if
- end if
- end if
- return #continue
- end if
- if the pCurrentFrame of me > the pAnimationFrames of me then
- set the pCurrentFrame of me to 1
- set the pLoopCounter of me to the pLoopCounter of me + 1
- if the pLoopCounter of me < the pIterations of me then
- if pLoopAction = #pause then
- setPauseState(me, 1)
- return #exit
- else
- set the pOffsetTicks of me to the ticks
- if not (the pbPathFunction of me) then
- set the pCurrentLoc of me to the pStartLoc of me
- end if
- return #continue
- end if
- else
- if the pCompletionAction of me = #death then
- addUnique(gDeathRow, the pChannel of me)
- return #exit
- else
- if the pCompletionAction of me = #pause then
- setPauseState(me, 1)
- return #exit
- else
- if stringp(the pCompletionAction of me) then
- do(the pCompletionAction of me)
- setPauseState(me, 1)
- return #exit
- end if
- end if
- end if
- end if
- return #continue
- end if
- end
-
- on moveSprite me
- set the pCurrentLoc of me to getAt(the pPathData of me, the pCurrentPathFrame of me)
- set the loc of sprite the pChannel of me to the pCurrentLoc of me
- end
-
- on SizeSprite me
- if the pScalePct of me = 100 then
- exit
- end if
- set theCast to the castNum of sprite the pChannel of me
- set theSourceRect to the rect of cast theCast
- set width to the width of cast theCast
- set height to the height of cast theCast
- set adjustPct to (the pScalePct of me - 100) / 200.0
- set the rect of sprite the pChannel of me to inflate(theSourceRect, width * adjustPct, height * adjustPct)
- end
-
- on setCurrentLoc me, thePoint
- set the pCurrentLoc of me to thePoint
- set the loc of sprite the pChannel of me to the pCurrentLoc of me
- end
-
- on setCurrentFrame me, frame
- if frame = #START then
- set the pCurrentFrame of me to 1
- else
- if frame = #end then
- set the pCurrentFrame of me to the pAnimationFrames of me
- else
- set the pCurrentFrame of me to frame
- end if
- end if
- end
-
- on setPauseState me, state
- set the pbPauseState of me to state
- end
-
- on pauseToggle me
- set the pbPauseState of me to not (the pbPauseState of me)
- end
-
- on setVisibleState me, state
- set the pbVisibleState of me to state
- hideUnhide(me)
- end
-
- on visibleToggle me
- set the pbVisibleState of me to not (the pbVisibleState of me)
- hideUnhide(me)
- end
-
- on hideUnhide me
- if the pbVisibleState of me then
- set the visible of sprite the pChannel of me to 1
- else
- set the visible of sprite the pChannel of me to 0
- end if
- end
-
- on MakePalindromeList me
- set aStart to count(the pFrameData of me)
- if (aStart > 2) and (pPathData = #NULL) then
- repeat with frame = aStart down to 2
- add(the pFrameData of me, getAt(the pFrameData of me, frame))
- end repeat
- else
- if (aStart > 2) and (count(pPathData) = aStart) then
- repeat with frame = aStart - 1 down to 2
- add(the pFrameData of me, getAt(the pFrameData of me, frame))
- end repeat
- repeat with frame = aStart down to 2
- set newdata to -getAt(the pPathData of me, frame)
- add(the pPathData of me, newdata)
- end repeat
- end if
- end if
- end
-
- on reverseFrameData me
- set reversedFrameData to []
- repeat with frame = the pAnimationFrames of me down to 1
- add(reversedFrameData, getAt(the pFrameData of me, frame))
- end repeat
- set the pFrameData of me to value(string(reversedFrameData))
- set the pCurrentFrame of me to the pAnimationFrames of me - the pCurrentFrame of me
- end
-
- on preLoadData me
- if the pbPreload of me then
- repeat with castOffset in the pFrameData of me
- preLoadCast(castOffset)
- end repeat
- end if
- end
-