|
|
|
Curve Sprite - Move a sprite along a curved path.
Added on 7/30/2002
|
Based on a Lissajous curve algorithm, this behavior is extremely versatile, and can produce an amazing variety of results. You can create curves of all sorts with the option to add loops so sprites can "swim" around all sorts of ways.
-- Moves a sprite on a definable Lissajous curve
-- Behavior by Ken Loge - kenl@ori.org
-- 06-01-02
-- Algorithm based on Lissajous Lab from Stormsky
property pWidthRange -- the width "spread" of the curve description
property pHeightRange -- the height "spread" of the curve description
property pOffsetValue -- if > 0 the curve appears to rotate on its X-axis
property pCurveLoops -- the number of "loops" the curve will make
property pIncrementAmount -- the "speed" the curve is drawn. A lower number produces a smoother curve, but is slower to draw.
property pHalfStageWidth -- use to store half of the stage width
property pHalfStageHeight -- use to store half of the stage height
property pCurveIncrementer -- use to add the increment amount for curve smoothness and draw speed
on getPropertyDescriptionList me
list = [:]
addProp list, #pWidthRange, [#comment: "Curve Width Area:", #format: #integer, #default: 100, #range: [#min: 0, #max: 500]]
addProp list, #pHeightRange, [#comment: "Curve Height Area:", #format: #integer, #default: 100, #range: [#min: 0, #max: 500]]
addProp list, #pOffsetValue, [#comment: "Curve X Offset Value:", #format: #float, #default: 0.0, #range: [#min: 0, #max: 10]]
addProp list, #pCurveLoops, [#comment: "Number of Curve Loops:", #format: #integer, #default: 1, #range: [#min: 0, #max: 100]]
addProp list, #pIncrementAmount, [#comment: "Curve Resolution:", #format: #float, #default: 0.02, #range: [#min: 0, #max: 5]]
return list
end
on beginSprite me
pHalfStageWidth = (the stageRight - the stageLeft) / 2
pHalfStageHeight = (the stageBottom - the stageTop) / 2
end
on exitFrame me
pCurveIncrementer = pCurveIncrementer + pIncrementAmount
sprite(me.spriteNum).locH = (pWidthRange * sin((pCurveLoops * pCurveIncrementer) + pOffsetValue)) + pHalfStageWidth
sprite(me.spriteNum).locV = (pHeightRange * sin(pCurveIncrementer)) + pHalfStageHeight
end
|
|