I'm maths challenged, and I need some kind soul to instruct me how to to have a sprite move across the screen according to its angle and speed. I know the sprite's current x, y, angle, and the distance I want it to travel.
Here's what I've tried...
// virtual resolution
SetVirtualResolution (1024,768)
// some colors
colorWhite = MakeColor(255,255,255)
// make sprite
DrawLine(0,0,30,10,colorWhite,colorWhite)
Drawline(30,10,0,20,colorWhite,colorWhite)
DrawLine(0,20,10,10,colorWhite,colorWhite)
DrawLine(10,10,0,0,colorWhite,colorWhite)
shipImg = GetImage(0,0,30,20)
spr=CreateSprite(shipImg)
SetSpritePosition (spr,512,768/2)
SetSpriteAngle(spr,0)
sprForce = 1.0
do
sprAngle = GetSpriteAngle(spr)
sprX = GetSpriteXByOffset(spr)
sprY = GetSpriteYByOffset(spr)
sprCosine = Cos(sprAngle) * sprForce
sprSine = Sin(sprAngle) * sprForce
sprX = sprX + sprCosine
sprY = sprY + sprSine
SetSpritePositionByOffset(spr,SprX,SprY)
print(sprAngle)
sync()
loop
end
But when I try to change the angle as it moves, it doesn't do what I expect.
Any help would be appreciated!