I am trying to maipulat a script for a car to work for something I doing.
I have car and I want it to stop when it intersects other sprites. ie walls.
This script is a bit too complicated for me so would somebody take a look
and tell me what they think would work...
here goes:
-- Steering Behavior with Momentum
-- copyright C MM, ZZP Online LLC
-- free use for DOUG readers
property pRotation
property pSpeed, pTopSpeed, pThrust
property pDrag, pBrakePower
property pSprite
property pAngle
property pAngleSegments
property pTrigList
property pLoc
property pDeltaLoc
property pConstraintRect
on getPropertyDescriptionList me
stageWidth = the stageRight - the stageLeft
stageHeight = the stageBottom - the stageTop
stageRect = rect(0,0,stageWidth, stageHeight)
set pdlist to [:]
addprop pdlist, #pTopSpeed, [#comment:"Speed limit:", #format:#integer,
#default:15]
addprop pdlist, #pThrust, [#comment:"Acceleration Power:", #format:#float,
#default:1.5]
addprop pdlist, #pDrag, [#comment:"Drag:", #format:#float, #default:0.75]
addprop pdlist, #pBrakePower, [#comment:"Braking Power", #format:#integer,
#default:2.0]
addprop pdlist, #pAngle, [#comment:"Steering sensitivity (degrees per
frame):", #format:#integer, #default:10]
addprop pdlist, #pRotation, [#comment:"Starting rotation (degrees)",
#format:#integer, #default:0]
addprop pdlist, #pConstraintRect, [#comment:"Constraining rect:",
#format:#rect, #default: stageRect]
return pdlist
end getPropertyDescriptionList
on beginSprite me
pAngleSegments = 360.00/pAngle
pSprite = sprite(me.spriteNum)
pLoc = pSprite.loc
pDeltaLoc = [0,0]
if pRotation mod pAngle <> 0 then
pRotation = (pRotation/pAngle) * pAngle
put "Starting rotation must be an even multiple of steering
sensitivity."
end if
pSprite.rotation = pRotation
makeTrigList me
end beginSprite
on makeTrigList me
pTrigList = []
increment = (pi * 2)/pAngleSegments
f = 0.0
angle = 0
repeat while f < (pi * 2)
hFactor = sin(f)
vFactor = cos(f) * - 1
hvList = [hFactor,vFactor]
add pTrigList, hvList
f = f + increment
end repeat
-- put pTrigList
end makeTrigList
on exitFrame me
-- rotation controls
if keyPressed(124) then
rotate me, #clockwise
else if keyPressed(123) then
rotate me, #counterclockwise
end if
-- thrust, brake, coast, thrustBack controls
if keyPressed(125) then
moveSprite me, #thrustBack
else if keyPressed(126) then
moveSprite me, #thrust
else if keyPressed(126) then
moveSprite me, #brake
else
moveSprite me, #coast
end if
repeat with i = 120 down to 100
if sprite i intersects sprite (me.spritenum) then
exit
end if
end repeat
end exitFrame
on rotate me, whichWay
if whichWay = #clockwise then
pRotation = pRotation + pAngle
else
pRotation = pRotation - pAngle
end if
-- keep pRotation between 0 and 359
if pRotation > 359 then pRotation = pRotation - 360
if pRotation < 0 then pRotation = pRotation + 360
pSprite.rotation = pRotation
end rotate
on moveSprite me, whichCommand
-- convert angle to list index
whichIndex = (pRotation/pAngle) + 1
thisMoveXY = pTrigList[whichIndex]
-- adjust speed
case whichCommand of
#thrust: pSpeed = min(pSpeed + pThrust, pTopSpeed)
#thrustBack: pSpeed = max(pSpeed - pThrust, pTopSpeed * - 0.5)
#brake:
if pSpeed > 0 then pSpeed = max(pSpeed - pBrakePower,0)
else if pSpeed < 0 then pSpeed = min(pSpeed + pBrakePower, 0)
#coast:
if pSpeed > 0 then pSpeed = max(0, pSpeed - pDrag)
else if pSpeed < 0 then pSpeed = min(0, pSpeed + pDrag)
end case
-- apply speed to direction vector
thisMove = thisMoveXY * pSpeed
tempDeltaLoc = pDeltaLoc + thisMove
newLoc = pLoc + tempDeltaLoc
-- check new location & move sprite
if inside(newLoc, pConstraintRect) then
pDeltaLoc = tempDeltaLoc
pSprite.loc = newLoc
end if
end moveSprite
[To remove yourself from this list, or to change to digest mode, go to
http://www.penworks.com/LUJ/lingo-l.cgi To post messages to the list,
email [EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED])
Lingo-L is for learning and helping with programming Lingo. Thanks!]