REM Demonstration of the Box2D (v2.2.1 or v2.3.1) Physics Engine REM by Richard Russell, http://www.rtrussell.co.uk/, 27-Jan-2013 MODE 8 : OFF INSTALL @lib$+"box2dlib" : PROC_b2Init INSTALL @lib$+"box2ddbg" ON ERROR PROCcleanup : IF ERR=17 CHAIN @lib$+"../examples/tools/touchide" ELSE ERROR 0,REPORT$+" at line "+STR$ERL ON CLOSE PROCcleanup : QUIT gravity_x = 0.0 gravity_y = -9.8 scale = 20 myWorld%% = FN_b2CreateWorld(gravity_x, gravity_y) PROC_b2DebugInit(myWorld%%, %01011, scale) ground%% = FN_b2StaticBox(myWorld%%, 16.0, 0.1, 0.0, 16.0, 0.1) n% = 16 x = 7 : y = 0.75 FOR i% = 0 TO n%-1 xx = x FOR j% = i% TO n%-1 block%% = FN_b2DynamicBody(myWorld%%, xx, y, 0, 0, 0, 0, 0, 0) fixture%% = FN_b2BoxFixture(block%%, 0, 0, 0, 0.5, 0.5, 0.1, 0, 1.0) xx += 1.125 NEXT x += 0.5625 : y += 1.25 NEXT i% pick%% = FN_b2KinematicBody(myWorld%%, 0, 0, 0, 0, 0, 0, 0, 0) sensor%% = FN_b2BoxFixture(pick%%, 0, 0, 0, 0.01, 0.01, 0.1, 0, 1.0) PROC_b2SetSensor(sensor%%, 1) timeStep = 1.0/60.0 velIterations% = 8 posIterations% = 3 joint%% = 0 GCOL 2 VDU 5 *REFRESH OFF REPEAT CLS MOUSE x%, y%, b% x = x% / 2 / scale : y = y% / 2 / scale PROC_b2SetBody(pick%%, x, y, 0) IF b% AND 4 THEN PROC_b2SetAwake(pick%%, 1) ELSE IF joint%% PROC_b2DestroyJoint(myWorld%%, joint%%) joint%% = 0 ENDIF IF joint%% PROC_b2SetTarget(joint%%, x, y) IF joint%% = 0 IF b% AND 4 THEN contact%% = FN_b2ContactListBody(pick%%) WHILE contact%% IF FN_b2IsTouching(contact%%) THEN PROC_b2GetContact(contact%%, fixture1%%, fixture2%%, child1%%, child2%%) body%% = 0 IF fixture1%% = sensor%% body%% = FN_b2GetBody(fixture2%%) IF fixture2%% = sensor%% body%% = FN_b2GetBody(fixture1%%) IF body%% THEN PROC_b2GetBody(body%%, x, y, a) joint%% = FN_b2MouseJoint(myWorld%%, pick%%, body%%, x, y, 1000, 5, 0.7) EXIT WHILE ENDIF ENDIF contact%% = FN_b2NextContact(contact%%) ENDWHILE ENDIF PROC_b2WorldStep(myWorld%%, timeStep, velIterations%, posIterations%) PROC_b2DebugDraw(myWorld%%) MOVE 432,1000 : PRINT "Move blocks with the mouse" *REFRESH WAIT 1 IF INKEY(-1) PROC_b2DebugFlags(4, 0) ELSE PROC_b2DebugFlags(4, 4) UNTIL FALSE PROCcleanup END DEF PROCcleanup myWorld%% += 0 : IF myWorld%% PROC_b2DestroyWorld(myWorld%%) : myWorld%% = 0 PROC_b2Exit ENDPROC