I have used my path editor from
https://forum.thegamecreators.com/thread/221096
To create the following path file
4
1
-64.000000
-1.000000
-65.000000
255.000000
-1.000000
255.000000
-1.000000
-2.000000
-512.000000
-384.000000
I am using it with an array of up to 50 moveable sprites
firstly I position them like
function load_level(level)
enemyNum=1
f$=""
f$="level"
f$=f$+str(level)
f$=f$+".lev"
if GetFileExists(f$)
clear_level()
myfile=opentoread(f$)
for n=1 to objectlimit
objnum = readinteger(myfile)
xpos=readinteger(myfile)
ypos=readinteger(myfile)
gr=readinteger(myfile)
im=readinteger(myfile)
if objnum>0
if gr<1
createsprite(objnum,im)
setspritesize(objnum,GetImageWidth(im),GetImageHeight(im))
setspriteposition(objnum,xpos,ypos)
SetSpriteDepth(objnum,10)
SetSpriteGroup(objnum,gr)
object[n].id=objnum
object[n].x=xpos
object[n].y=ypos
object[n].image=im
object[n].group=gr
inc objectcount
endif
if gr=1
createsprite(objnum,im)
setspritesize(objnum,GetImageWidth(im),GetImageHeight(im))
setspriteposition(objnum,xpos,ypos)
SetSpriteDepth(objnum,10)
SetSpriteGroup(objnum,gr)
enemySprite[enemyNum,0].id=objnum
enemySprite[enemyNum,0].x=xpos
enemySprite[enemyNum,0].y=ypos
enemySprite[enemyNum,0].image=im
enemySprite[enemyNum,0].group=gr
enemySprite[enemyNum,0].count=1
inc objectcount:inc enemyNum
endif
endif
next n
closefile(myfile)
else
e$="Error... File does not exist!"
createtext(10,e$)
settextsize(10,20)
settextposition(10,50,50)
sync()
sleep(2000)
deletetext(10)
endif
endfunction
they were created using my tested tile editor available here
https://forum.thegamecreators.com/thread/219932
then i load my path for each enemy in the arrray
function loadArrayPath()
for num = 1 to 50
Path$="arrayPath"+str(1)+".txt"
If GetFileExists(Path$)
read = OpenToRead(Path$)
String1$ = ReadLine(read)
length=val(String1$)
String2$ = ReadLine(read)
enemySprite[num,0].length=length
enemySprite[num,0].count=1
enemySprite[num,0].closed=val(String2$)
//dim path[length] as object
for n =1 to length
//enemySprite[num,n].id=2001
enemySprite[num,n].length=length
enemySprite[num,n].closed=val(String2$)
StringX$ = ReadLine(read)
StringY$ = ReadLine(read)
enemySprite[num,n].x=val(StringX$) //+enemySprite[num,0].x
enemySprite[num,n].y=val(StringY$) //+enemySprite[num,0].y
enemySprite[num,n].count=length
next n
Closefile(read)
endif
next num
endfunction
here is where i beleive i have the problem
when movepath is called they move very jittery
enemySprite[num,0].x holds the original x location of the sprite
enemySprite[num,0].y holds the original y location
function movePath(speed#)
for num=1 to 50
count=enemySprite[num,0].count
if GetSpriteExists(enemySprite[num,0].id)
x=enemySprite[num,0].x
y=enemySprite[num,0].y
xx=(enemySprite[num,count].x)+x
yy=(enemySprite[num,count].y)+y
if enemySprite[num,0].count<enemySprite[num,0].length
if getDistance(x,y,xx,yy)>=5 then inc enemySprite[num,0].count
angle#=getAngle(x,y,xx,yy)
enemySprite[num,0].x=x-sin(angle#)*speed#
enemySprite[num,0].y=y+cos(angle#)*speed#
SetSpritePositionByOffset(enemySprite[num,0].id,enemySprite[num,0].x,enemySprite[num,0].y)
else
if getDistance(enemySprite[num,0].x,enemySprite[num,0].y,xx,yy)<5 then enemySprite[num,0].count=1
angle#=getAngle(x,y,xx,yy)
enemySprite[num,0].x=x-sin(angle#)*speed#
enemySprite[num,0].y=y+cos(angle#)*speed#
SetSpritePositionByOffset(enemySprite[num,0].id,enemySprite[num,0].x,enemySprite[num,0].y)
endif
endif
next num
endfunction
function getAngle(x1#, y1#, x2#, y2#)
result# = ATanFull(x1# - x2#, y1# - y2#)
endfunction result#
function getDistance (x1#,y1#,x2#,y2#)
dx#=x1#-x2#
dy#=y1#-y2#
distance#=sqrt((dx#*dx#)+(dy#*dy#)):rem distance object to path point
endfunction distance#
I'm sure there is something crazy ive done and there is some simple logic problem but they dont even seem to follow the path
as it steps through the array ive stopped the background movement to debug it as that changes the original location but still is very
Jittery. I haven't sent the whole code as it really needs the graphics to get it to work as they were positioned in each location by the tile
editor and because of copyrights but I can place the full code if that helps without the sprites if that helps
and the count should hold the value of which path item should be applied
fubar