tutiplain wrote:
What I want is to be able to translate a sprite previously rotated with RotateSprite3D() forward or backward, but taking into account its current location. Unfortunately, I spent most of my day yesterday reading up on trigonometric functions and vector math, and I still have no idea how to achieve the desired result. This seems like a fairly standard thing to do in 2D games, so I'm guessing someone out there has to understand how it works. Any info will be greatly appreciated! Thanks!
I know this is an old post, but someone has resurrected it, so ... here an example
Code:
If InitSprite() = 0 Or InitKeyboard() = 0
MessageRequester("Error", "Sprite system can't be initialized", 0)
End
EndIf
If OpenScreen(800, 600, 32, "Sprite")
CreateSprite(0, 64,64)
StartDrawing(SpriteOutput(0))
Line(0,16,1,32, RGB(255,255,0))
LineXY(0,16,64,32, RGB(255,255,0))
LineXY(0,64-16,64,32, RGB(255,255,0))
FillArea(32,32,RGB(255,255,0),RGB(85,85,0))
StopDrawing()
Define.f Angle, x, y, DirectionX, DirectionY, Vitesse = 2
Repeat
FlipBuffers()
ClearScreen(RGB(0,0,0))
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Left)
Angle - 1
DirectionX = Cos(Radian(Angle))
DirectionY = Sin(Radian(Angle))
RotateSprite(0, Angle, #PB_Absolute)
ElseIf KeyboardPushed(#PB_Key_Right)
Angle + 1
DirectionX = Cos(Radian(Angle))
DirectionY = Sin(Radian(Angle))
RotateSprite(0, Angle, #PB_Absolute)
EndIf
If KeyboardPushed(#PB_Key_Up)
x + DirectionX * Vitesse
y + DirectionY * Vitesse
ElseIf KeyboardPushed(#PB_Key_Down)
x - DirectionX * Vitesse
y - DirectionY * Vitesse
EndIf
DisplayTransparentSprite(0,x,y)
Until KeyboardPushed(#PB_Key_Escape)
Else
MessageRequester("Error", "Can't open a 800*600 - 32 bit screen !", 0)
EndIf