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 myWorld%% = FN_b2CreateWorld(gravity_x, gravity_y) PROC_b2DebugInit(myWorld%%, %01001, 20) ground%% = FN_b2StaticBox(myWorld%%, 16.0, 0.1, 0.0, 16.0, 0.1) gear1%% = FN_b2DynamicBody(myWorld%%, 13.0, 12.8, 0, 0, 0, 0, 0, 0) wheel1%% = FN_b2CircleFixture(gear1%%, 0.0, 0.0, 1.0, 0.1, 0, 1.0) axle1%% = FN_b2RevoluteJoint(myWorld%%, ground%%, gear1%%, 13.0, 12.8, 0, 0) gear2%% = FN_b2DynamicBody(myWorld%%, 16.0, 12.8, 0, 0, 0, 0, 0, 0) wheel2%% = FN_b2CircleFixture(gear2%%, 0.0, 0.0, 2.0, 0.1, 0, 1.0) axle2%% = FN_b2RevoluteJoint(myWorld%%, ground%%, gear2%%, 16.0, 12.8, 0, 0) rack%% = FN_b2DynamicBody(myWorld%%, 18.5, 19.2, 0, 0, 0, 0, 0, 0) fixture%% = FN_b2BoxFixture(rack%%, 0, 0, 0.0, 0.5, 6.4, 0.1, 0, 1.0) slide%% = FN_b2PrismaticJoint(myWorld%%, ground%%, rack%%, 18.5, 12.8, 0.0, 1.0, -12.8, 0) PROC_b2PrismaticMotorForce(slide%%, 1000.0, 0) mesh1%% = FN_b2GearJoint(myWorld%%, gear1%%, gear2%%, axle1%%, axle2%%, 2.0) mesh2%% = FN_b2GearJoint(myWorld%%, gear2%%, rack%%, axle2%%, slide%%, -1.0) timeStep = 1.0/60.0 velIterations% = 8 posIterations% = 3 *REFRESH OFF GCOL 2 VDU 5 spacebar% = FALSE REPEAT CLS PROC_b2WorldStep(myWorld%%, timeStep, velIterations%, posIterations%) PROC_b2DebugDraw(myWorld%%) MOVE 330,60 : PRINT "Hold SPACE BAR or touch to drive upwards" *REFRESH WAIT 1 MOUSE x%, y%, b% IF (INKEY(-99) OR b% <> 0) <> spacebar% THEN spacebar% = NOT spacebar% CASE spacebar% OF WHEN TRUE: PROC_b2PrismaticMotorSpeed(slide%%, 10.0, 1) WHEN FALSE: PROC_b2PrismaticMotorSpeed(slide%%, 0, 0) ENDCASE ENDIF 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