Log In  

Cart #px_puzzle-1 | 2022-10-14 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
2

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

P#119089 2022-10-14 09:11

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.

P#119103 2022-10-14 15:58

you're right bro, I will fix it the next version

P#119450 2022-10-22 11:45

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-29 15:22:14 | 0.032s | Q:20