|
|
Follow the leader
Added on 4/19/2000
|
Instructions: Designate one sprite to be the LEADER.
Put as many other sprites in adjacent channels which will be the FOLLOWERS. Make sure the LEADER sprite is in the highest sprite channel.Drop this behavior on all FOLLOWERS. Move the leader through your own lingo, or by setting it as MOVEABLE in the score.
Download PC Source Download Mac Source
property pLeader -- Which sprite to follow.
property pVLag -- How much to "lag" behind the leader vertically
property pHLag -- How much to "lag" behind the leader horizontally
property pActive -- This turns on or off the pVLag and the pHLag
on beginSprite me
me.pLeader = me.spriteNum + 1 -- Which sprite to follow.
me.pVLag = (random(2) + 1) * .1 -- How much to "lag" behind the leader vertically
me.pHLag = (random(2) + 1) * .1 -- How much to "lag" behind the leader horizontally
me.pActive = [1,1] -- This turns on or off the pVLag and the pHLag
end beginSprite
on exitFrame me
vLeaderLoc = sprite(me.pLeader).loc -- Find your leader"s position
vMyLoc = sprite(me.spriteNum).loc -- Get your position
vHDif = vLeaderLoc[1] - vMyLoc[1] -- Find the horizontal difference from the leader
vVDif = vLeaderLoc[2] - vMyLoc[2] -- Find the vertical difference from the leader
-- Follow the leaders" position with a horizontal lag
if me.pActive[1] then sprite(me.spriteNum).locH = vMyLoc[1] + (vHDif * me.pHLag)
-- Follow the leaders" position with a vertical lag
if me.pActive[2] then sprite(me.spriteNum).locV = vMyLoc[2] + (vVDif * me.pVLag)
end exitFrame
on getBehaviorDescription me
vDesc = ¬
"Description: This behavior will make an unlimited number of sprites follow a LEADER sprite, with¬
a definable LAG, which can make for some interesting effects, such as a snake, or a¬
streamer, or a kite. " & RETURN & RETURN & ¬
"Instructions: Designate one sprite to be the LEADER.¬
Put as many other sprites in adjacent channels which will be the FOLLOWERS.¬
Make sure the LEADER sprite is in the highest sprite channel.¬
Drop this behavior on all FOLLOWERS. Move the leader through your own lingo,¬
or by setting it as MOVEABLE in the score. Demo and source at: ¬
http://www.mindspring.com/~alqueen/FollowTheLeader.dir"
return vDesc
end getBehaviorDescription
|
|