Progress thus far.
Rem Project: StickSuicide3
Rem Created: 20/06/2009 00:04:01
Rem ***** Main Source File *****
`Disable autosync because it's a CPU hog
sync rate 0 : sync on
sync on : sync rate 60
offsetx = screen width() / 2.0
offsety = screen height() / 2.0
myworld = b2CreateWorld( -100, -100, 100, 100, 0, 10 )
ShapeTemplateHead = b2CreateCircleShapeTemplate( 1, 1, 0.5, 0.1 )
b2SetShapeTemplateMaskBits ShapeTemplateHead, %00000000000000000000000000000001
BodyTemplateHead = b2CreateBodyTemplate( 0, 0, 0 )
BodyHead = b2CreateDynamicBody( myworld, BodyTemplateHead )
ShapeHead = b2CreateShape( BodyHead, ShapeTemplateHead )
b2CalculateBodyMass BodyHead
ShapeTemplateTorso = b2CreateBoxShapeTemplate( 0.25, 1.4, 1, 0.5, 0.1 )
b2SetShapeTemplateMaskBits ShapeTemplateTorso, %00000000000000000000000000000010
BodyTemplateTorso = b2CreateBodyTemplate( 0, 0, 0 )
BodyTorso = b2CreateDynamicBody( myworld, BodyTemplateTorso )
ShapeTorso = b2CreateShape( BodyTorso, ShapeTemplateTorso )
b2CalculateBodyMass BodyTorso
JointTemplateNeck = b2CreateRevoluteJointTemplate( BodyHead, BodyTorso, 0, 1, 0, -0.7 )
b2SetRevoluteJointTemplateLowerLimit JointTemplateNeck, -1.3962634
b2SetRevoluteJointTemplateUpperLimit JointTemplateNeck, 1.04719755
b2SetRevoluteJointTemplateEnableLimit JointTemplateNeck, 1
JointNeck = b2CreateJoint( myworld, JointTemplateNeck )
ShapeTemplateStomach = b2CreateBoxShapeTemplate( 0.25, 1.2, 1, 0.5, 0.1 )
b2SetShapeTemplateMaskBits ShapeTemplateStomach, %00000000000000000000000000000100
BodyTemplateStomach = b2CreateBodyTemplate( 0, 0, 0 )
BodyStomach = b2CreateDynamicBody( myworld, BodyTemplateStomach )
ShapeStomach = b2CreateShape( BodyStomach, ShapeTemplateStomach )
b2CalculateBodyMass BodyStomach
JointTemplateStomach = b2CreateRevoluteJointTemplate( BodyTorso, BodyStomach, 0,0.7, 0, -0.6 )
b2SetRevoluteJointTemplateLowerLimit JointTemplateStomach, -0.436332313
b2SetRevoluteJointTemplateUpperLimit JointTemplateStomach, 0.174532925
b2SetRevoluteJointTemplateEnableLimit JointTemplateStomach, 1
JointStomach = b2CreateJoint( myworld, JointTemplateStomach )
ShapeTemplateUpperRightLeg = b2CreateBoxShapeTemplate( 0.25, 1.8, 1, 0.5, 0.1 )
b2SetShapeTemplateMaskBits ShapeTemplateUpperRightLeg, %00000000000000000000000000001000
BodyTemplateUpperRightLeg = b2CreateBodyTemplate( 0, 0, 0 )
BodyUpperRightLeg = b2CreateDynamicBody( myworld, BodyTemplateUpperRightLeg )
ShapeUpperRightLeg = b2CreateShape( BodyUpperRightLeg, ShapeTemplateUpperRightLeg )
b2CalculateBodyMass BodyUpperRightLeg
JointTemplateUpperRightLeg = b2CreateRevoluteJointTemplate( BodyStomach, BodyUpperRightLeg, 0,0.6, 0, -0.9 )
b2SetRevoluteJointTemplateLowerLimit JointTemplateUpperRightLeg, -1.04719755
b2SetRevoluteJointTemplateUpperLimit JointTemplateUpperRightLeg, 1.91986218
b2SetRevoluteJointTemplateEnableLimit JointTemplateUpperRightLeg, 1
JointUpperRightLeg = b2CreateJoint( myworld, JointTemplateUpperRightLeg )
ShapeTemplateLowerRightLeg = b2CreateBoxShapeTemplate( 0.25, 1.4, 1, 0.5, 0.1 )
b2SetShapeTemplateMaskBits ShapeTemplateLowerRightLeg, %00000000000000000000000000010000
BodyTemplateLowerRightLeg = b2CreateBodyTemplate( 0, 0, 0 )
BodyLowerRightLeg = b2CreateDynamicBody( myworld, BodyTemplateLowerRightLeg )
ShapeLowerRightLeg = b2CreateShape( BodyLowerRightLeg, ShapeTemplateLowerRightLeg )
b2CalculateBodyMass BodyLowerRightLeg
JointTemplateLowerRightLeg = b2CreateRevoluteJointTemplate( BodyUpperRightLeg, BodyLowerRightLeg, 0,0.9, 0, -0.7 )
b2SetRevoluteJointTemplateLowerLimit JointTemplateLowerRightLeg, -1.74532925
b2SetRevoluteJointTemplateUpperLimit JointTemplateLowerRightLeg, 0.174532925
b2SetRevoluteJointTemplateEnableLimit JointTemplateLowerRightLeg, 1
JointLowerRightLeg = b2CreateJoint( myworld, JointTemplateLowerRightLeg )
ShapeTemplateUpperLeftLeg = b2CreateBoxShapeTemplate( 0.25, 1.8, 1, 0.5, 0.1 )
b2SetShapeTemplateMaskBits ShapeTemplateUpperLeftLeg, %00000000000000000000000000100000
BodyTemplateUpperLeftLeg = b2CreateBodyTemplate( 0, 0, 0 )
BodyUpperLeftLeg = b2CreateDynamicBody( myworld, BodyTemplateUpperLeftLeg )
ShapeUpperLeftLeg = b2CreateShape( BodyUpperLeftLeg, ShapeTemplateUpperLeftLeg )
b2CalculateBodyMass BodyUpperLeftLeg
JointTemplateUpperLeftLeg = b2CreateRevoluteJointTemplate( BodyStomach, BodyUpperLeftLeg, 0,0.6, 0, -0.9 )
b2SetRevoluteJointTemplateLowerLimit JointTemplateUpperLeftLeg, -1.04719755
b2SetRevoluteJointTemplateUpperLimit JointTemplateUpperLeftLeg, 1.91986218
b2SetRevoluteJointTemplateEnableLimit JointTemplateUpperLeftLeg, 1
JointUpperLeftLeg = b2CreateJoint( myworld, JointTemplateUpperLeftLeg )
ShapeTemplateLowerLeftLeg = b2CreateBoxShapeTemplate( 0.25, 1.4, 1, 0.5, 0.1 )
b2SetShapeTemplateMaskBits ShapeTemplateLowerLeftLeg, %00000000000000000000000001000000
BodyTemplateLowerLeftLeg = b2CreateBodyTemplate( 0, 0, 0 )
BodyLowerLeftLeg = b2CreateDynamicBody( myworld, BodyTemplateLowerLeftLeg )
ShapeLowerLeftLeg = b2CreateShape( BodyLowerLeftLeg, ShapeTemplateLowerLeftLeg )
b2CalculateBodyMass BodyLowerLeftLeg
JointTemplateLowerLeftLeg = b2CreateRevoluteJointTemplate( BodyUpperLeftLeg, BodyLowerLeftLeg, 0,0.9, 0, -0.7 )
b2SetRevoluteJointTemplateLowerLimit JointTemplateLowerLeftLeg, -1.74532925
b2SetRevoluteJointTemplateUpperLimit JointTemplateLowerLeftLeg, 0.174532925
b2SetRevoluteJointTemplateEnableLimit JointTemplateLowerLeftLeg, 1
JointLowerLeftLeg = b2CreateJoint( myworld, JointTemplateLowerLeftLeg )
ShapeTemplateUpperLeftArm = b2CreateBoxShapeTemplate( 0.25, 1.8, 1, 0.5, 0.1 )
b2SetShapeTemplateMaskBits ShapeTemplateUpperLeftArm, %00000000000000000000000010000000
BodyTemplateUpperLeftArm = b2CreateBodyTemplate( 0, 0, 0 )
BodyUpperLeftArm = b2CreateDynamicBody( myworld, BodyTemplateUpperLeftArm )
ShapeUpperLeftArm = b2CreateShape( BodyUpperLeftArm, ShapeTemplateUpperLeftArm )
b2CalculateBodyMass BodyUpperLeftArm
JointTemplateUpperLeftArm = b2CreateRevoluteJointTemplate( BodyTorso, BodyUpperLeftArm, 0,-0.25, 0, -0.9 )
b2SetRevoluteJointTemplateLowerLimit JointTemplateUpperLeftArm, -1.04719755
b2SetRevoluteJointTemplateUpperLimit JointTemplateUpperLeftArm, 1.91986218
b2SetRevoluteJointTemplateEnableLimit JointTemplateUpperLeftArm, 1
JointUpperLeftArm = b2CreateJoint( myworld, JointTemplateUpperLeftArm )
ShapeTemplateLowerLeftArm = b2CreateBoxShapeTemplate( 0.25, 1.4, 1, 0.5, 0.1 )
b2SetShapeTemplateMaskBits ShapeTemplateLowerLeftArm, %00000000000000000000000100000000
BodyTemplateLowerLeftArm = b2CreateBodyTemplate( 0, 0, 0 )
BodyLowerLeftArm = b2CreateDynamicBody( myworld, BodyTemplateLowerLeftArm )
ShapeLowerLeftArm = b2CreateShape( BodyLowerLeftArm, ShapeTemplateLowerLeftArm )
b2CalculateBodyMass BodyLowerLeftArm
JointTemplateLowerLeftArm = b2CreateRevoluteJointTemplate( BodyUpperLeftArm, BodyLowerLeftArm, 0,0.9, 0, -0.7 )
b2SetRevoluteJointTemplateLowerLimit JointTemplateLowerLeftArm, -0.174532925
b2SetRevoluteJointTemplateUpperLimit JointTemplateLowerLeftArm, 1.74532925
b2SetRevoluteJointTemplateEnableLimit JointTemplateLowerLeftArm, 1
JointLowerLeftArm = b2CreateJoint( myworld, JointTemplateLowerLeftArm )
ShapeTemplateUpperRightArm = b2CreateBoxShapeTemplate( 0.25, 1.8, 1, 0.5, 0.1 )
b2SetShapeTemplateMaskBits ShapeTemplateUpperRightArm, %00000000000000000000001000000000
BodyTemplateUpperRightArm = b2CreateBodyTemplate( 0, 0, 0 )
BodyUpperRightArm = b2CreateDynamicBody( myworld, BodyTemplateUpperRightArm )
ShapeUpperRightArm = b2CreateShape( BodyUpperRightArm, ShapeTemplateUpperRightArm )
b2CalculateBodyMass BodyUpperRightArm
JointTemplateUpperRightArm = b2CreateRevoluteJointTemplate( BodyTorso, BodyUpperRightArm, 0,-0.25, 0, -0.9 )
b2SetRevoluteJointTemplateLowerLimit JointTemplateUpperRightArm, -1.04719755
b2SetRevoluteJointTemplateUpperLimit JointTemplateUpperRightArm, 1.91986218
b2SetRevoluteJointTemplateEnableLimit JointTemplateUpperRightArm, 1
JointUpperRightArm = b2CreateJoint( myworld, JointTemplateUpperRightArm )
ShapeTemplateLowerRightArm = b2CreateBoxShapeTemplate( 0.25, 1.4, 1, 0.5, 0.1 )
b2SetShapeTemplateMaskBits ShapeTemplateLowerRightArm, %00000000000000000000010000000000
BodyTemplateLowerRightArm = b2CreateBodyTemplate( 0, 0, 0 )
BodyLowerRightArm = b2CreateDynamicBody( myworld, BodyTemplateLowerRightArm )
ShapeLowerRightArm = b2CreateShape( BodyLowerRightArm, ShapeTemplateLowerRightArm )
b2CalculateBodyMass BodyLowerRightArm
JointTemplateLowerRightArm = b2CreateRevoluteJointTemplate( BodyUpperRightArm, BodyLowerRightArm, 0,0.9, 0, -0.7 )
b2SetRevoluteJointTemplateLowerLimit JointTemplateLowerRightArm, -0.174532925
b2SetRevoluteJointTemplateUpperLimit JointTemplateLowerRightArm, 1.74532925
b2SetRevoluteJointTemplateEnableLimit JointTemplateLowerRightArm, 1
JointLowerRightArm = b2CreateJoint( myworld, JointTemplateLowerRightArm )
myfloordef = b2CreateBodyTemplate(0,0,0)
myfloor = b2CreateStaticBody(myworld,myfloordef)
myfloorshapetemp = b2CreateBoxShapeTemplate(50,1,0,0.5,0.5)
b2SetShapeTemplateMaskBits myfloorshapetemp, %111111111111111111
b2SetShapeTemplateCategoryBits myfloorshapetemp, %111111111111111111
myfloorshape = b2CreateShape( myfloor, myfloorshapetemp )
b2CalculateBodyMass myfloor
b2SetBodyPosition myfloor,0,9
f1 = 1
miny = 1000
b2SetWorldDebug myworld,1
b2SetDebugTransform offsetx,offsety,20,20
b2SetDebugFlags f1,f2,f3,f4,f5,f6,f7
do
b2BodyApplyTorque BodyLowerLeftLeg, b2GetBodyAngle( BodyLowerLeftLeg ) * -72
b2BodyApplyTorque BodyUpperLeftLeg, b2GetBodyAngle( BodyUpperLeftLeg ) * -80
b2BodyApplyTorque BodyLowerRightLeg, b2GetBodyAngle( BodyLowerRightLeg ) * -72
b2BodyApplyTorque BodyUpperRightLeg, b2GetBodyAngle( BodyUpperRightLeg ) * -80
b2BodyApplyTorque BodyStomach, b2GetBodyAngle( BodyStomach ) * -95
b2BodyApplyTorque BodyTorso, b2GetBodyAngle( BodyTorso ) * -128
b2BodyApplyTorque BodyHead, b2GetBodyAngle( BodyHead ) * -96
deviation as float
deviation = 0
inc deviation, b2GetBodyPositionX( BodyHead )
inc deviation, b2GetBodyPositionX( BodyTorso )
inc deviation, b2GetBodyPositionX( BodyStomach )
inc deviation, b2GetBodyPositionX( BodyUpperLeftLeg )
inc deviation, b2GetBodyPositionX( BodyUpperRightLeg )
deviation = deviation / 5.0
dec deviation, ( b2GetBodyPositionX( BodyLowerLeftLeg ) + b2GetBodyPositionX( BodyLowerRightLeg ) ) / 2.0
print "Deviation: " + str$( deviation )
deviation = deviation * 0.5
b2BodyApplyTorque BodyLowerLeftArm, ( b2GetBodyAngle( BodyLowerLeftArm ) - deviation ) * -32
b2BodyApplyTorque BodyUpperLeftArm, ( b2GetBodyAngle( BodyUpperLeftArm ) - deviation ) * -48
b2BodyApplyTorque BodyLowerRightArm, ( b2GetBodyAngle( BodyLowerRightArm ) - deviation ) * -32
b2BodyApplyTorque BodyUpperRightArm, ( b2GetBodyAngle( BodyUpperRightArm ) - deviation ) * -48
k$ = inkey$()
if k$ <> ""
if pressing = 0
pressing = 1
if k$ = "1" then f1 = 1-f1
if k$ = "2" then f2 = 1-f2
if k$ = "3" then f3 = 1-f3
if k$ = "4" then f4 = 1-f4
if k$ = "5" then f5 = 1-f5
if k$ = "6" then f6 = 1-f6
if k$ = "7" then f7 = 1-f7
b2SetDebugFlags f1,f2,f3,f4,f5,f6,f7
endif
else
pressing = 0
endif
omc = msc
msc = mouseclick()
msd = msc-omc `Get the difference between the old mouse click and the new
if msd = 1 `If user just pressed left mouse button
`Find shapes under the mouse
num = b2QueryWorld(myworld,(mousex()-offsetx)*0.05,(mousey()-offsety)*0.05,(mousex()+1-offsetx)*0.05,(mousey()+1-offsety)*0.05,1)
if num `If any were found
dragbody = b2GetShapeBody(b2GetShapeArrayItem(0)) `Get the shape's body
`Create a mouse joint and attach it to the body
jt = b2CreateMouseJointTemplate(b2GetWorldGroundBody(myworld),dragbody,(mousex()-offsetx)*0.05,(mousey()-offsety)*0.05,1000,1.0/60.0)
mjoint = b2CreateJoint(myworld,jt)
b2DeleteJointTemplate jt `Delete the template
endif
endif
if msc = 1 and mjoint <> 0 `If user is dragging, and the mouse joint has been created
b2SetMouseJointTarget mjoint,(mousex()-offsetx)*0.05,(mousey()-offsety)*0.05 `Set the joint's target to the mouse position
endif
if msd = -1 and mjoint <> 0 `If user releases mouse
b2DeleteJoint mjoint `Delete the joint
mjoint = 0 `Nullify the pointer
endif
b2WorldStep myworld
sync
cls 0
loop
EDIT: Updated, now balances self using arms when its body is misaligned (deviated from feet)