First I load my image to a table,
final positions in x,y and random position in (a,b)
function load_image() --load the image me = {} for j=0,8 do row={} for i=0,8 do add(row,{ spr=j*16+i, x=i*8+30, y=j*8+20, a=rnd(150), b=130, }) end add(me, row) end end |
then I call a magnet() function to move a=>x and b=>y
function magnet() local step=1 for j=1,8 do for i=1,8 do local p = me[j][i] x= p.a y= p.b if p.a > p.x then p.a-=step end if p.a < p.x then p.a+=step end if p.b > p.y then p.b-=step end if p.b < p.y then p.b+=step end end |
Happy Coding



Nice, @peymanx, but it is not getting the side of his head.

You see that small sliver to the right of his head ? The ball goes straight through there.
[Please log in to post a comment]