CodeBase - Move To Point

Return to the CodeBase listing

Category: Graphics

Version: 1.0

0
0

Information

Uploaded: 16th Mar 2014 11:02

Modified: 13th Jan 2017 08:58

Author:  Blendman

Summary

Sprite move to a point

Full Description

With this code, a sprite is moving to a point (x,y) until this sprite is near the point. Code updated : 13 jan 2017

Comments

Blendman
Posted: 13th Jan 2017 08:59
/*
Sprite move to point
AGK : v1 & 2
Date : updated 13 jan 2017
*/


SetVirtualResolution(480,480)

global spr
spr = CreateSprite(0)

global x, y, mx, my as float

do

if GetRawKeyPressed(27) = 1
exit
endif

if GetPointerstate() = 1
mx = GetPointerX()
my = GetPointerY()
endif

MoveToward(mx, my, 6)
print(str(mx) +"/" +str(my))
print(str(x) +"/" +str(y))

sync( )
loop

function GetAngle(x1#, y1#, x2#, y2#)
result# = ATanFull(x1# - x2#, y1# - y2#)
endfunction result#

function MoveToward(ciblx as float, cibly as float, speed as float)

if x ciblx or y cibly
angle = GetAngle(ciblx, cibly, GetSpriteX(spr), GetSpriteY(spr))
SetSpriteAngle(spr, angle)
if x ciblx
x = x + cos(ATan2((cibly - y),(ciblx - x)))* speed
if abs(x - ciblx)
mangue
Posted: 25th Jun 2016 07:06
main.agc:39: error: Function "getangle" must return a value to be used here