SpelunkyFan wiki

objects/oTreasure/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.

oTreasure's step event, 80 lines of GML.

// treasure only active within viewif (x > view_xview[0]-16 and x < view_xview[0] + view_wview[0]+16 and        y > view_yview[0]-16 and y < view_yview[0] + view_hview[0]+16 and        state == ACTIVE){    colLeft = false;    colRight = false;    colBot = false;    if (isCollisionLeft(1)) colLeft = true;    if (isCollisionRight(1)) colRight = true;    if (isCollisionBottom(1)) colBot = true;    moveTo(xVel, yVel);    if (not colBot) yVel += myGrav;    if (yVel > 8) yVel = 8;        if (isCollisionTop(1))    {        if (yVel < 0) yVel = -yVel * 0.8;        else y += 1;    }        if (colLeft or colRight)    {        xVel = -xVel * 0.5;    }        if (colBot)    {        /*        // bounce        if (yVel > 1) yVel = -yVel * 0.5;        else yVel = 0;        */                // friction        if (abs(xVel) < 0.1) xVel = 0;        else if (abs(xVel) != 0) xVel *= 0.3;                y -= 1;                if (not isCollisionBottom(1))        {            y += 1;            status = STATIC;        }        yVel = 0;    }    // else status = STATIC;        if (colLeft)    {        if (not colRight) x += 1;        //yVel = 0;    }    else if (colRight)    {        x -= 1;        //yVel = 0;    }    if (global.hasSpectacles or global.hasUdjatEye)    {        depth = 0;    }    else depth = 101;        if (collision_rectangle(x-3, y-3, x+3, y+3, oLava, 0, 0))    {        myGrav = 0;        xVel = 0;        yVel = 0;        y += 0.05;    }    if (collision_point(x, y-5, oLava, 0, 0))    {        instance_destroy();    }}