#12001/12/8 22:14:58
--------------------------------------------------------------------------------
property pSprite -- sprite reference
property pSpeed -- integer, speed of the rock
property pAngRad -- float, angle rock is moving (in radians)
property pRotateAmt -- float, the amount the rock rotates each prepareFrame
on new me, aMember
pSprite = sprite(me.spriteNum)
pSpeed = Random(5) -- a random speed
pAngRad = pi()*Random(360)/180 -- a random angle
pRotateAmt = 1.1-(Random(10)*.2) -- a random rotation amount
return me
end
on prepareFrame me
-- rotate the sprite
pSprite.rotation = pSprite.rotation + pRotateAmt
-- move the sprite
pSprite.loc = pSprite.loc + point(pSpeed*cos(pAngRad), \
pSpeed*sin(pAngRad))
-- make sure it's on the stage
me.CheckBounds((the stage).sourceRect.width, \
(the stage).sourceRect.height)
end
on CheckBounds me, h, v
-- Checks to see if the sprite is off the stage,
-- if it is, it is moved to the side opposite it went off.
if pSprite.locH > h then
pSprite.locH = pSprite.locH - h
else if pSprite.locH < 0 then
pSprite.locH = pSprite.locH + h
end if
if pSprite.locV > v then
pSprite.locV = pSprite.locV - v
else if pSprite.locV < 0 then
pSprite.locV = pSprite.locV + v
end if
end
这是一个比较常见的游戏里的算法,这个Behaviour脚本控制精灵移动,原来在学flash actionscript时在flashkit上见过,没想到现在学lingo又看到了。有一地方我想搞清楚它。就是
-- rotate the sprite
pSprite.rotation = pSprite.rotation + pRotateAmt
-- move the sprite
pSprite.loc = pSprite.loc + point(pSpeed*cos(pAngRad), \
pSpeed*sin(pAngRad))
这里关于三角函数的算法哪位高手能把它解释一下吗?我数学不好,有些想不过来。
谢谢。