Director Collision Script
property mySprite property xSide property ySide
on getPropertyDescriptionList description = [:] addProp description,#xSide, [#default:"", #format:#string, #comment:"Horizontal Direction that diagonal faces", range:[#none,#left,#right]] addProp description,#ySide, [#default:"", #format:#string, #comment:"Vertical Direction that diagonal faces:", range:[#none,#top,#bottom]] return description end
on new me mySprite = sprite(me.spriteNum) return me end
on cameraMove me, theAmount, theDirection if theDirection = #panLeft then mySprite.locH = mySprite.locH + theAmount if theDirection = #panRight then mySprite.locH = mySprite.locH - theAmount if theDirection = #panUp then mySprite.locV = mySprite.locV + theAmount if theDirection = #panDown then mySprite.locV = mySprite.locV - theAmount end
on goLeft me, character, speed, cameraAction, distanceFromEdge cl = character.left cr = character.right ct = character.top cb = character.bottom ml = mySprite.left mr = mySprite.right mt = mySprite.top mb = mySprite.bottom if xSide = #none and cl - speed < mr and cr - speed > ml and ct < mb and cb > mt then return #stop
if ySide = #bottom then if xSide = #right and cl - speed < mr and cr - speed > ml and ct < mt and ct < mb and cb > mt then return "stop" else if xSide = #right and cl - speed < mr and cr - speed > ml and ct < mb and cb > mt then if keypressed(126) then return #stop else if (cl - ml) - (mb - ct) < speed then if cl - speed < distanceFromEdge then sendAllSprites(#cameraMove, speed, #panDown) else character.locV = character.locV + speed end if end if end if if xSide = #left and cr - speed > mr and cl - speed < mr and ct < mb and cb > mt then return #stop
else -- goLeft top -- if xSide = #right and cl - speed < mr and cr - speed > ml and ct < mb and cb > mb and cb > mt then return #stop else if xSide = #right and cl - speed < mr and cr - speed > ml and ct < mb and cb > mt then if keypressed(125) then return #stop else if (cl - ml) - (cb - mt) < speed then if cl - speed < distanceFromEdge then sendAllSprites(#cameraMove, speed, #panUp) else character.locV = character.locV - speed end if end if end if if xSide = #left and cr - speed > mr and cl - speed <mr and ct < mb and cb > mt then return #stop end if end
on goRight me, character, speed, cameraAction, distanceFromEdge cl = character.left cr = character.right ct = character.top cb = character.bottom ml = mySprite.left mr = mySprite.right mt = mySprite.top mb = mySprite.bottom
if xSide = #none and cr + speed > ml and cl + speed < mr and cb > mt and ct < mb then return #stop
if ySide = #bottom then if xSide = #right and cr + speed > ml and cl + speed < ml and ct < mb and cb > mt then return "stop" if xSide = #left and cl + speed < mr and cr + speed > ml and ct < mb and ct < mt and cb > mt then return #stop else if xSide = #left and cl + speed < mr and cr + speed > ml and ct < mb and cb > mt then if keypressed(126) then return #stop else if (mr - cr) - (mb - ct) < speed then sw = the stageright - the stageleft if cr + speed > sw - distanceFromEdge then sendAllSprites(#cameraMove, speed, #panDown) else character.locV = character.locV + speed end if end if end if
else -- goRight top -- if xSide = #right and cr + speed > ml and cl + speed < ml and character.top < mb and cb > mySprite.top then return #stop if xSide = #left and cl + speed < mr and cr + speed > ml and ct < mb and cb > mb and cb > mt then return #stop else if xSide = #left and cl + speed < mr and cr + speed > ml and ct < mb and cb > mt then if keypressed(125) then return #stop else if (mr - cr) - (cb - mt) < speed then sw = the stageright - the stageleft if cr + speed > sw - distanceFromEdge then sendAllSprites(#cameraMove, speed, #panUp) else character.locV = character.locV - speed end if end if end if end if end if end on goDown me, character, speed, cameraAction, distanceFromEdge cl = character.left cr = character.right ct = character.top cb = character.bottom ml = mySprite.left mr = mySprite.right mt = mySprite.top mb = mySprite.bottom
if xSide = #none and cl < mr and cr > ml and cb + speed > mt and ct + speed < mb then return #stop
if ySide = #bottom then if xSide = #left and cl < mr and cr > ml and ct + speed < mb and ct + speed < mt and cb + speed > mt then return #stop if xSide = #right and cl < mr and cr > ml and ct + speed < mt and cb + speed > mt then return #stop
else -- goDown top if xSide = #right and cl < ml and cr > ml and cb + speed > mt and ct + speed < mb then return #stop else if xSide = #right and cl < mr and cr > ml and ct + speed < mb and cb + speed > mt then if keypressed(123) then return #stop else if (cl - ml) - (cb - mt) < speed then sh = the stageBottom - the stageTop if cb + speed > sh - distanceFromEdge then sendAllSprites(#cameraMove, speed, #panRight) else character.locH = character.locH + speed end if end if end if if xSide = #left and cl < mr and cr > ml and ct + speed < mb and cb + speed > mt and cr > mr then return #stop else if xSide = #left and cl < mr and cr > ml and ct + speed< mb and cb + speed > mt then if keypressed(124) then return #stop else if mr - cr - cb - mt < speed then sh = the stageBottom - the stageTop if cb + speed > sh - distanceFromEdge then sendAllSprites(#cameraMove, speed, #panLeft) else character.locH = character.locH - speed end if end if end if end if end
on goUp me, character, speed, cameraAction, distanceFromEdge cl = character.left cr = character.right ct = character.top cb = character.bottom ml = mySprite.left mr = mySprite.right mt = mySprite.top mb = mySprite.bottom if xSide = #none and cl < mr and cr > ml and ct - speed < mb and cb - speed > mt then return #stop
if ySide = #bottom then if xSide = #right and cl < mr and cr > ml and cl < ml and ct - speed < mb and cb - speed > mt then return #stop if xSide = #right and cl < mr and cr > ml and ct - speed < mb and cb - speed > mt then if keypressed(123) then return #stop else if (cl - ml) - (mb - ct) < speed then if ct - speed < distanceFromEdge then sendAllSprites(#cameraMove, speed, #panRight) else character.locH = character.locH + speed end if end if end if if xSide = #left and cl < mr and cr > ml and ct - speed < mb and cr > mr and cb - speed > mt then return #stop else if xSide = #left and cl < mr and cr > ml and ct - speed < mb and cb - speed > mt then if keypressed(124) then return #stop else if (ct - mt) - (cr - ml) < speed then if ct - speed < distanceFromEdge then sendAllSprites(#cameraMove, speed, #panLeft) else character.locH = character.locH - speed end if end if end if
else -- goUp top if xSide = #right and cl < mr and cr > ml and ct - speed < mb and cb > mb and cb - speed > mt then return #stop if xSide = #left and cr > ml and cl < mr and ct - speed < mb and cb > mb and cb - speed > mt then return #stop end if end |