Thanks ElijahNomad!
I didn't know about the Box2D manual. That should help alot.
My code is in a bit of disarray while trying to figure out what each command does, so I'm not sure it would help, but here it is:
SetVirtualResolution(1024, 768)
speed = 5000
Dim m$[768]
LoadImage(1, "bTank.png")
CreateSprite(1, 1): SetSpritePosition(1, 40, 50): SetSpriteShape(1, 3)
LoadImage(2, "wall.png")
SetPhysicsDebugOn()
SetSpritePhysicsOn( 1, 2 )
SetPhysicsGravity( 0, 0 )
`SetSpritePhysicsCanRotate(1, 0)
SetSpritePhysicsRestitution(1, 0)
SetSpritePhysicsFriction(1, 100)
SetSpritePhysicsDamping(1, 1)
Gosub level1
Gosub create_level
do
Gosub moveTank
SetSpritePhysicsAngularDamping(1, 15)
if getrawkeypressed(27) then end
sync()
loop
moveTank:
if getrawkeypressed(38) ` Up
SetSpritePhysicsImpulse(1, GetSpriteX(1), GetSpriteY(1), 0, -speed)
endif
if getrawkeypressed(40) ` Down
SetSpritePhysicsImpulse(1, GetSpriteX(1), GetSpriteY(1), 0, speed)
endif
if getrawkeypressed(37) ` Left
SetSpritePhysicsAngularVelocity(1, .01)
SetSpritePhysicsAngularImpulse(1, -speed)
`SetSpritePhysicsImpulse(1, GetSpriteX(1), GetSpriteY(1), -speed, 0)
endif
if getrawkeypressed(39) ` Right
SetSpritePhysicsImpulse(1, GetSpriteX(1), GetSpriteY(1), speed, 0)
endif
Return
create_level:
` Reads Map data from m$[] and builds the level
wx = 0: wy = 0: loc = 0: wSpr = 999
for row = 1 to 24
for col = 1 to 32
if mid(m$[loc], col, 1) = "1"
inc wSpr
CreateSprite(wSpr, 2)
SetSpritePosition(wSpr, wx, wy)
SetSpriteDepth(wSpr, 10)
SetSpritePhysicsOn( wSpr, 1 )
endif
inc wx, 32
next col
inc loc
inc wy, 32
wx = 0
next row
Return
level1:
m$[0] = "11111111111111111111111111111111"
m$[1] = "10000000000000010000000000000001"
m$[2] = "10000000000000010000000000000001"
m$[3] = "10000000000000000000000000000001"
m$[4] = "10000000000000000000000000000001"
m$[5] = "10000000000000000000000000000001"
m$[6] = "10000000000000000000000000000001"
m$[7] = "10000000000000000000000000000001"
m$[8] = "10000000000000000000000000000001"
m$[9] = "10000000000000000000000000000001"
m$[10] = "10001100000000010000000000110001"
m$[11] = "10000110000000101000000001100001"
m$[12] = "10000110000000010000000001100001"
m$[13] = "10001100000000000000000000110001"
m$[14] = "10000000000000000000000000000001"
m$[15] = "10000000000000000000000000000001"
m$[16] = "10000000000000000000000000000001"
m$[17] = "10000000000000000000000000000001"
m$[18] = "10000000000000000000000000000001"
m$[19] = "10000000000000000000000000000001"
m$[20] = "10000000000000000000000000000001"
m$[21] = "10000000000000010000000000000001"
m$[22] = "10000000000000010000000000000001"
m$[23] = "11111111111111111111111111111111"
Return
I have attached the 2 images I'm using for my test program, which is just a portion of my main program, so I can get a hold of the physics before implementing it.
Here is what I am trying to do, at the moment:
Up Arrow: Move Tank Forward according to the angle it is heading.
Down Arrow: Stop
Left Arrow: Turn Left and if in motion, keep moving in the new direction.
Right Arrow: Turn Right and if in motion, keep moving in the new direction.
If the tank is not current moving, then I need it to just rotate in place.
I guess I just need to know how to calculate the new direction of the tank and change the Impulse / Force to the new direction. I want the change in Velocity to be immediate and not have any acceleration. Maybe I don't need Impulse or Force at all and should just use the Velocity commands ....
Thanks for the help!
JHA