diff --git a/chameleonic.p8 b/chameleonic.p8 index 0c176b5..abd61e5 100644 --- a/chameleonic.p8 +++ b/chameleonic.p8 @@ -1056,6 +1056,38 @@ function rope:draw(artificial_dx,artificial_dy) rectfill(x,y-1,x-1,y-3,color) end end + local n1=self.src + local sy=0 + while true do + if (n1==nil) break + local x=n1.ax*8 + local y=n1.ay*8 + rectfill(x-1,y-1,x+1,y+1,12) + --print("ax="..n1.ax..",ay="..n1.ay,0,sy) + sy+=7 + + local n0=n1.prev + local n2=n1.next + if n0!=nil and n2!=nil then + if n1.associated_with then + local _,_,_,adx,ady=would_stick(n0.ax,n0.ay,n1.associated_with,n2.ax,n2.ay) + assert(adx==-1 or adx==0 or adx==1) + assert(ady==-1 or ady==0 or ady==1) + --assert(not (adx==0 and ady==0)) + + rectfill(x+2,y+2,x+4,y+4,3) + pset(x+adx*2,y,9) + pset(x,y+ady*2,9) + else + rectfill(x+2,y+2,x+4,y+4,2) + end + else + rectfill(x+2,y+2,x+4,y+4,4) + end + + n1=n1.next + end + for _,p in pairs(level._anch) do pset(p.ax*8,p.ay*8,11) pset(p.ax*8+p.adx,p.ay*8,11) @@ -1063,13 +1095,6 @@ function rope:draw(artificial_dx,artificial_dy) end --[[ - for i=0,#self.ancs+1 do - p=self:_anc(i) - local c=12 - if (p.dirty) c=13 - rectfill(p.x-1,p.y-1,p.x+1,p.y+1,c) - print(tostr(p.id)..":"..p.x..","..p.y..","..#p.todo,0,i*8,12) - end print("dirty:"..tostr(self.dirty),32,0,9) print("busy:"..tostr(self:busy()),32,7,9) print("state:"..tostr(self.state.name),32,14,9) @@ -1111,31 +1136,9 @@ function rope:_relax() local x1,y1=n1.ax,n1.ay local x2,y2=n2.ax,n2.ay - if (x0>x2) x0,y0,x2,y2=x2,y2,x0,y0 - - local dx=x2-x0 - local dy=y2-y0 - - local adx,ady - local x1_new,y1_new - if abs(dx)>abs(dy) then - local dprop=(x1-x0)/dx - x1_new,y1_new=x1,y0+dprop*(y2-y0) - ady=sgn0(y1_new-y1) - adx=0 - if (y0>y2) adx=ady - if (y0y2) ady=adx - if (y0x2) x0,y0,x2,y2=x2,y2,x0,y0 + + local dx=x2-x0 + local dy=y2-y0 + + local adx,ady + local x1_new,y1_new + if abs(dx)>abs(dy) then + local dprop=(x1-x0)/dx + x1_new,y1_new=x1,y0+dprop*(y2-y0) + ady=sgn0(y1_new-y1) + adx=0 + if (y0>y2) adx=ady + if (y0y2) ady=adx + if (y0