Hi,
unfortunately I had to create a WORKING EXAMPLE first.
Code:
EnableExplicit
#ScrWidth = 800
#ScrHeight = 600
Structure Vector
X.f
Y.f
EndStructure
Structure Car
Position.Vector
frontTire.Vector
backTire.Vector
speed.f
angle.f
wheelbase.f
direction.f
Sprite.i
EndStructure
Define.i Event
Define.f elapsed
NewList Playercar.Car()
;-main
InitSprite()
InitKeyboard()
InitMouse()
OpenWindow(0, 0, 0, #Scrwidth, #ScrHeight, "Test", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, #Scrwidth, #ScrHeight)
AddElement(Playercar())
Playercar()\Position\X = #ScrWidth / 2
Playercar()\Position\Y = #ScrHeight / 2
Playercar()\wheelbase = 32
Playercar()\Sprite = CreateSprite(#PB_Any, 20, 20)
StartDrawing(SpriteOutput(Playercar()\Sprite))
Box(0, 0, 5, 5, #Red)
Box(16, 1, 4, 4, #Red)
Box(0, 5, 20, 10, #Red)
Box(16, 15, 4, 4, #Red)
Box(0, 15, 5, 5, #Red)
StopDrawing()
elapsed = 0.1
Repeat
ClearScreen(0)
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Up)
Playercar()\speed + 1
ElseIf KeyboardPushed(#PB_Key_Down)
Playercar()\speed - 1
EndIf
If KeyboardPushed(#PB_Key_Left)
Playercar()\angle - 0.03
ElseIf KeyboardPushed(#PB_Key_Right)
Playercar()\angle + 0.03
EndIf
If Playercar()\speed < 0
Playercar()\speed = 0
ElseIf Playercar()\speed > 30
Playercar()\speed = 30
EndIf
Debug ""
Debug Playercar()\angle
Debug Playercar()\speed
;//frontTire = position + wheelBase / 2 * new Vector2((float)Math.Cos(direction), (float)Math.Sin(direction));
PlayerCar()\frontTire\x = PlayerCar()\Position\X + PlayerCar()\wheelbase / 2 * Cos(PlayerCar()\direction)
PlayerCar()\frontTire\y = PlayerCar()\Position\Y + PlayerCar()\wheelbase / 2 * Sin(PlayerCar()\direction)
;//backTire = position - wheelBase / 2 * new Vector2((float)Math.Cos(direction), (float)Math.Sin(direction));
PlayerCar()\backTire\x = PlayerCar()\Position\X - PlayerCar()\wheelbase / 2 * Cos(PlayerCar()\direction)
PlayerCar()\backTire\y = PlayerCar()\Position\Y - PlayerCar()\wheelbase / 2 * Sin(PlayerCar()\direction)
;//backTire += speed * elapsed * new Vector2((float)Math.Cos(direction), (float)Math.Sin(direction));
PlayerCar()\backTire\X + (PlayerCar()\speed * elapsed * Cos(PlayerCar()\direction))
PlayerCar()\backTire\Y + (PlayerCar()\speed * elapsed * Sin(PlayerCar()\direction))
;//frontTire += speed * elapsed * new Vector2((float)Math.Cos(direction + angle), (float)Math.Sin(direction + angle));
PlayerCar()\frontTire\X + (PlayerCar()\speed * elapsed * Cos(PlayerCar()\direction + PlayerCar()\angle))
PlayerCar()\frontTire\Y + (PlayerCar()\speed * elapsed * Sin(PlayerCar()\direction + PlayerCar()\angle))
;// position = (frontTire + backTire) / 2;
PlayerCar()\Position\X = (PlayerCar()\frontTire\X + PlayerCar()\backTire\X) / 2
PlayerCar()\Position\Y = (PlayerCar()\frontTire\Y + PlayerCar()\backTire\Y) / 2
;direction = (float)Math.Atan2(frontTire.Y - backTire.Y, frontTire.X - backTire.X);
PlayerCar()\direction = ATan2(PlayerCar()\frontTire\x - PlayerCar()\backTire\x, PlayerCar()\frontTire\Y - PlayerCar()\backTire\Y)
Debug StrF(PlayerCar()\Position\X, 2) + " " + StrF(Playercar()\Position\Y, 2)
DisplaySprite(PlayerCar()\Sprite, PlayerCar()\Position\X, Playercar()\Position\Y)
FlipBuffers()
Event = WindowEvent()
Until KeyboardPushed(#PB_Key_Escape) Or Event = #PB_Event_CloseWindow
I also changed already the Atan2() parameters, but still funny results.
Bernd