objects/oArrow/step.gml
From spelunky.gmk, Spelunky Classic 1.1's source, © 2008, 2009 Derek Yu and Mossmouth, LLC, shown whole under the Spelunky User License v1.1b. Extracted by spelunky.ai's tools, an unofficial fan project, one file per script or event; the // ==== lines are the extractor's, naming each action of the event. Some scripts are others' work that Derek Yu credits in the source's readme.txt: Martin Piecyk's platform engine, ChevyRay's view scaling scripts and tsg1zzn's Super Sound System.
oArrow's step event, 37 lines of GML.
// ==== action 0: lib 1 id 604: action_inherited() ====// ==== action 1: lib 1 id 603: code ====if (xVel > 0 and yVel < 0){ direction = radtodeg(arctan(-yVel/xVel));}else if (xVel < 0 and yVel < 0){ direction = 180 - radtodeg(arctan(-yVel/-xVel));}else if (xVel > 0 and yVel > 0){ direction = radtodeg(arctan(yVel/xVel));}else if (xVel < 0 and yVel > 0){ direction = 180 + radtodeg(arctan(yVel/-xVel));}else if (xVel < 0) direction = 180;else if (not stuck) direction = 0;image_angle = direction;// ensure the arrow does not shoot through the target in the Moon challengeif (isRoom("rMoon")){ if (instance_exists(oTarget)) { if (x > oTarget.x and y > oTarget.y-16 and y < oTarget.y+16 and distance_to_object(oTarget) < 4) { x = oTarget.x+4; xVel = 0; yVel = 0; } }}