Quote: "I'm working on a collision shape editor to make it super easy to make accurate collision shapes for your objects"
Oh, cool, I was about to make one for myself but I guess it's no use reinventing the wheel
. Thanks again for this plugin, it's exactly what I needed for my latest project!
On another note, for anyone interested, I tweaked the car example a little bit. You'll need to copy the crate image into the car example's directory.
sync on
load image "Car.png",1,1
load image "Tire.png",2,1
sprite 1,-200,-200,1
sprite 2,-200,-200,2
stretch sprite 2, 200, 200
offset sprite 1,68,22
offset sprite 2,12,12
global boxSpr: boxSpr = 5
load image "crate.png",5,1
sprite boxSpr,-100,-100,5
set sprite boxSpr,0,0
offset sprite boxSpr,25,25
global maxBoxes:maxBoxes = 100
global numBoxes:numBoxes = 0
dim boxes(maxBoxes)
b2SetUnits 0.1,0.017453292519943295769236907684886
MyWorld = b2CreateWorld(-2000,-2000,2000,2000,0,50,1)
MyFloor = b2CreateBoxBody(MyWorld, 200, 50, 0, 0.3, 5)
MyFloor2 = b2CreateBoxBody(MyWorld, 1024, 50, 0, 0.3, 5)
MyFloor3 = b2CreateBoxBody(MyWorld, 1024, 50, 0, 0.3, 5)
MyFloor4 = b2CreateBoxBody(MyWorld, 1024, 50, 0, 0.3, 5)
carbase = b2CreateBoxShape(135,10)
cartop = b2CreateBoxShape(80,25)
cartemplate = b2CreateBodyTemplate()
b2AddShapeToBodyTemplate cartemplate,carbase,2,8,0,1,0.3
b2AddShapeToBodyTemplate cartemplate,cartop,-10,-5,0,1,0.3
MyCar = b2CreateBody(MyWorld, cartemplate)
MyWheel1 = b2CreateCircleBody(MyWorld, 24, 1, 0.3, 2500)
MyWheel2 = b2CreateCircleBody(MyWorld, 24, 1, 0.3, 2500)
b2PositionBody MyFloor,512,670
b2PositionBody MyFloor2,512,700
b2PositionBody MyFloor3,974,600
b2PositionBody MyFloor4,50,600
b2RotateBody MyFloor,-20
b2RotateBody MyFloor3,-70
b2RotateBody MyFloor4,70
b2PositionBody MyCar,512,335
b2PositionBody MyWheel1,460,382
b2PositionBody MyWheel2,564,382
MyAxel1 = b2CreateRevoluteJoint(MyWorld, MyCar, MyWheel1, 460,382)
MyAxel2 = b2CreateRevoluteJoint(MyWorld, MyCar, MyWheel2, 564,382)
b2SetJointMotorSpeed MyAxel1,1000
load image "Plain.png",3,1
sprite 3,-2000,-2000,3
offset sprite 3,50,50
set sprite diffuse 3,150,150,150
do
rem add boxes
if mouseclick() and hold = 0
hold = 1
inc numBoxes: if numBoxes > maxBoxes then goto nomore
boxes(numBoxes) = b2CreateBoxBody(myworld,50,50,1,0.2,0.5)
b2positionbody boxes(numBoxes), mousex(), mousey()
nomore:
endif
if mouseclick() = 0 then hold = 0
if upkey()
b2SetJointMotorSpeed MyAxel1,1000
b2SetJointMotorForce MyAxel1,1000
else
if downkey()
b2SetJointMotorSpeed MyAxel1,-1000
b2SetJointMotorForce MyAxel1,500
else
b2SetJointMotorForce MyAxel1,0
endif
endif
if spacekey()
b2SetBodyLinearVelocity MyCar,b2GetBodyLinearVelocityX(MyCar),-100
endif
torque = rightkey()-leftkey()
b2ApplyTorque MyCar,torque*50000
b2Step MyWorld
rotate sprite 1,b2GetBodyAngle(MyCar)
paste sprite 1,b2GetBodyX(MyCar),b2GetBodyY(MyCar)
rotate sprite 2,b2GetBodyAngle(MyWheel1)
paste sprite 2,b2GetBodyX(MyWheel1),b2GetBodyY(MyWheel1)
rotate sprite 2,b2GetBodyAngle(MyWheel2)
paste sprite 2,b2GetBodyX(MyWheel2),b2GetBodyY(MyWheel2)
if a
box 100,100,110,110
endif
a = 1-a
stretch sprite 3,200,50
rotate sprite 3,-20
paste sprite 3,512,670
stretch sprite 3,1024,50
rotate sprite 3,0
paste sprite 3,512,700
stretch sprite 3,1024,50
rotate sprite 3,-70
paste sprite 3,974,600
stretch sprite 3,1024,50
rotate sprite 3,70
paste sprite 3,50,600
rem draw box sprites
for loopBoxes = 1 to numBoxes
rotate sprite boxSpr, b2GetBodyAngle(boxes(loopBoxes))
paste sprite boxSpr, b2GetBodyX(boxes(loopBoxes)), b2GetBodyY(boxes(loopBoxes))
next
sync
cls 0
loop