Log In  

can someone tell me why this always fails?
it isn't garenteed to always reach 63,63 even through i floor it.

function main()
    domain=true

    while domain do
     cls()
        spr(16,4,0,15,2)

        for i=0,8 do star() end
        yield()

    end
end

function star()
 dostar=true
 inst  =
 {
  sx=rnd(127),
  sy=127,
  ex=63,
  ey=63,
 }

    while dostar do
        local dx=flr(inst.sx)==flr(inst.ex)
        local dy=flr(inst.sy)==flr(inst.ey)
        rectfill(0,0,127,24,0)
        print(tostr(dx)..","..tostr(dy),0,0,7)
        if dx and dy then   
            dostar=false
        else
         pset (inst.sx,inst.sy,7)
         print(flr(inst.sx).."/"..flr(inst.ex),0,8,7)
         print(flr(inst.sy).."/"..flr(inst.ey),0,16,7)
            inst.sx+=(inst.ex-inst.sx)*mainstarspd
            inst.sy+=(inst.ey-inst.sy)*mainstarspd
        end
        yield()
    end
end
P#73746 2020-03-07 22:26

Try printing out these two values:

print((inst.ex-inst.sx)*mainstarspd)
print((inst.ey-inst.sy)*mainstarspd)

I suspect one of the values is small enough that the multiply underflows and the result is a 0 offset that keeps you from arriving at the end value.

Remember (or discover now) that PICO-8 uses signed 16.16-bit fixed point math. You only have 16 bits of fractional precision. If you were, for instance, to square any number less than than 1/256 (0x.01), you'd get 0.

P#73748 2020-03-08 00:27 ( Edited 2020-03-08 00:29)

@Felice i can't print it out without it flowing offscreen or clearing over the previus number.

it updates too fast.

P#73751 2020-03-08 02:49 ( Edited 2020-03-08 02:56)

[Please log in to post a comment]

Follow Lexaloffle:          
Generated 2024-03-29 05:45:43 | 0.009s | Q:13