//...dog_initcanvas();dog_initsound();dog_events();//mouse and keyboarddog_initworld();dog_setupcollisions();dog_initdraw();dog_update();//...
Collisions
1234567891011121314
//...functiondog_setupcollisions(){varlistener=newBox2D.Dynamics.b2ContactListener;listener.BeginContact=function(contact){//if the dog touch the line we add a flag//...listener.PreSolve=function(contact){//if the dog eats a bone there's no collision//...listener.PostSolve=function(contact,impulse){//if the dog touch his house//and sounds...//...
Main loop
123456789101112131415161718192021222324
//...functiondog_update(){window.requestAnimationFrame(dog_update);world.Step(1/60,//frame-rate10,//velocity iterations10//position iterations);world.ClearForces();canvas_draw();//graphics}//...functioncanvas_draw()//...//we iterate through all the bodiesfor(body=world.GetBodyList();body;body=body.GetNext()){//...//we use the User Data field to know what to drawswitch(body.GetUserData()){case'line'://...
I used Box2DWeb, a javascript port of box2d 2.1. It lacks features like rope joint but I realized it too late…
More up to date ports i didn’t try :