Lets see, as more I want to understand this I can't make it right. In the following code I made a sprite move from point A to Point B, but what I want its to Move it infinite to the direction of Point B.
Yep, bullet trajectory... I don't know Why I can't get it!!!
When It reach point B it stops moving. And I can't figure how to make it continue. Any help that help me understand this would be appreciated.
Thanks in advance.
Here's the complete code:
type Data
pointAX as float
pointAY as float
pointBY as float
pointBX as float
speed as float
endtype
type System
flagA as integer
flagB as integer
wait as integer
move as integer
endType
white = MakeColor(255,255,255)
data as Data
flag as System
flag.flagA = 1
flag.flagB = 0
flag.wait = 0
flag.move = 0
data.speed = 0.5
test = createSprite(0)
SetSpriteColor(test, 0,255, 0,255)
SetSpriteVisible(test,0)
do
if GetRawKeyPressed(13) // ENTER Pressed
flag.flagA = 1
flag.flagB = 0
flag.wait = 0
flag.move = 0
SetSpriteVisible(test,0)
endIf
if(flag.flagA = 1)
print("Move Mouse to position A and press A Key to Plot")
if (GetRawKeyPressed(65))
flag.wait = 1
data.pointAX = GetPointerX()
data.pointAY = GetPointerY()
flag.flagA = 0
flag.flagB = 1
endif
endIf
if( flag.flagB = 1)
print("Move Mouse to position B and press B Key to Plot")
if (GetRawKeyPressed(66))
data.pointBX = GetPointerX()
data.pointBY = GetPointerY()
flag.flagB = 0
endif
endIf
if flag.flagA=0 then DrawEllipse( data.pointAX, data.pointAY, 0.4, 0.5, white, white, 0)
if flag.flagB=0 then DrawEllipse( data.pointBX, data.pointBY, 0.4, 0.5, white, white, 0)
if( flag.flagA=0 and flag.flagB = 0 and flag.move=0)
print("Press SpaceBar to move from point A to B")
DrawLine(data.pointAX, data.pointAY, data.pointBX, data.pointBY, white, white)
SetSpritePositionByOffset(test,data.PointAX,data.pointAY)
SetSpriteVisible(test,1)
endif
if GetRawKeyPressed(32) then flag.move = 1
if(flag.move = 1)
Print("Press ENTER to Reset" )
currentX# = GetSpriteX(test)
currentY# = GetSpriteY(test)
Print(str(currentX#) + "<-->" + str(currentY#))
// Calculate direction towards player
targetX# = data.pointBX - currentX#
targetY# = data.pointBY - currentY#
// Normalize or Distance
distance# = sqrt( ( targetX# * targetX#) + (targetY# * targetY#) )
targetX# = targetX# / distance#
targetY# = targetY# / distance#
// Move towards the player
SetSpritePosition(test, currentX# + (targetX# * data.speed), currentY# + (targetY# * data.speed) )
// Rotate us to face the player
SetSpriteAngle(test, ATanFull(targetY#, targetX#))
endif
sync()
loop