examples\control\Box2D\worlds\boxOfShapes.ck
if(me.args() == 0)
{
    <<<"This script is intended for use by Box2D. Bailing...", me.id()>>>;
    1::second => now;
    me.exit();
}

class eHandler extends EventHandler
{
    int stepCounter;
    fun void OnEvent(string type, Object ctx)    
    {
        if(type == "step")
        {
            this.stepCounter++;
            if((this.stepCounter % 200) == 0)
                <<<"BoxOfShapes count", this.stepCounter>>>;
        }
        // else type == "contact"
    }
};

eHandler myHandler;

// we use the first argument to find our Box2D context.
me.arg(0).toInt() => int boxId;
Box2D.Boxes[boxId] @=> Box2D boxO;
boxO.SetEventHandler(myHandler);
boxO.dbBox2D @=> DbBox2D box2D; // handle onto chugin

// define our world
box2D.worldBegin(#(0, -20));  // gravity points down
box2D.newEdge(#(-40, 0), #(40, 0)); // floor: p1, p2
box2D.newEdge(#(-40, 0), #(-40, 30)); // left wall
box2D.newEdge(#(40, 0), #(40, 30)); // right wall
box2D.newCircle(#(0, 25), 2, 2, box2D.dynamicType) => int c1; // p, radius, density
box2D.newCircle(#(-5, 20), 10, 2, box2D.dynamicType) => int c2; // p, radius, density
box2D.newTriangle(#(-5, 0), #(5, 0), #(0, -5), #(10,10), 1, box2D.dynamicType) => int t1;
box2D.setRestitution(c1, .75); // bounciness
box2D.setRestitution(c2, .85); 
box2D.setRestitution(t1, .85);
box2D.setDensity(c2, 100);
box2D.worldEnd();


<<<"boxOfShapes created",  box2D.getNumBodies(), "bodies">>>;
home .. topics .. interface .. reference .. examples .. tipjar