Hi
I'm trying to move a sprite to a point, but I don't know why it doesn't work (it work on my purebasic code, but not with AppGameKit code ^^)
Do you know how I can move a sprite to a point (x,y) ?
Thank you.
SetVirtualResolution(600, 800)
global spr
spr = CreateSprite(0)
global x, y
do
if GetRawKeyPressed(27) = 1
exit
endif
if GetPointerPressed() = 1
mx = GetPointerX()
my = GetPointerY()
endif
MoveToward(mx, my, 2)
print(str(mx) +"/" +str(my))
print(str(x) +"/" +str(y))
/*
aa = 1
If (not aa = 2)
PRINT("this will not print")
endif
*/
sync( )
loop
function GetAngle(x1, y1, x2, y2)
result = ATanFull(x1 - x2, y1 - y2)
endfunction result
function MargeEntre(a, b, n)
if a >= b - n and a <= b + n
a = b
endif
endfunction
function MoveToward(ciblx,cibly,speed)
// methode 1
if (x = ciblx)
else
x = x + Sin(ATan2((cibly - y),(ciblx- x)))* speed
endif
if (y = cibly)
else
y = y + sin(ATan2((cibly - y),(ciblx- x)))* speed
// I have tried that, but it doesn't work better
//y = y + Cos(ATan2((cibly - y),(ciblx- x)))* speed
endif
// methode 2
// Another technic, but the result isn't fine
/*
If y < cibly And x = ciblx
y = y + speed
direction = 0
ElseIf y > cibly And x = ciblx
y = y - speed
direction = 4
ElseIf x < ciblx And y < cibly
y = y + speed
x = x + speed
direction = 1
ElseIf x < ciblx And y > cibly
y = y - speed
x = x + speed
direction = 3
ElseIf x < ciblx And y = cibly
x = x + speed
direction = 2
ElseIf x > ciblx And y < cibly
y = y + speed
x = x - speed
direction = 7
ElseIf x > ciblx And y > cibly
y = y - speed : x = x - speed
direction = 5
ElseIf x > ciblx And y = cibly
x = x - speed
direction = 6
EndIf
*/
MargeEntre(x, ciblx, 2)
MargeEntre(y, cibly, 2)
angle = GetAngle(ciblx, cibly, GetSpriteX(spr), GetSpriteY(spr))
SetSpriteAngle(spr, angle)
SetSpritePosition(spr, x, y)
endfunction
Another question : I don't understand how does work the "not" code.
In that code, it could be print the line, isn't it ?
aa = 1
If not (aa = 2)
PRINT("this will not print")
endif
So why it doesn't print ?
Thank you for your answer
.
http://www.dracaena-studio.com