forked from pyrex/chameleonic
main #12
126
chameleonic.p8
126
chameleonic.p8
@ -1087,7 +1087,6 @@ function rope:draw(artificial_px,artificial_py)
|
||||
end
|
||||
|
||||
-- debug
|
||||
--[[
|
||||
local n1=self.src
|
||||
local sy=0
|
||||
while true do
|
||||
@ -1134,7 +1133,6 @@ function rope:draw(artificial_px,artificial_py)
|
||||
pset(x+p.adx,y,11)
|
||||
pset(x,y+p.ady,11)
|
||||
end
|
||||
]]
|
||||
end
|
||||
|
||||
function rope:drag_dst(x,y)
|
||||
@ -1153,18 +1151,6 @@ function rope:drag(n1,ax_new,ay_new)
|
||||
end
|
||||
|
||||
function rope:relax()
|
||||
local n=self.src
|
||||
|
||||
while true do
|
||||
if (n==nil) break
|
||||
|
||||
if (n.associated_with) then
|
||||
self:_drag(n,n.associated_with.ax,n.associated_with.ay)
|
||||
end
|
||||
|
||||
n=n.next
|
||||
end
|
||||
|
||||
local n0=self.src
|
||||
while true do
|
||||
local n1=n0.next
|
||||
@ -1173,7 +1159,7 @@ function rope:relax()
|
||||
|
||||
if n0.ax==n1.ax and n0.ay==n1.ay then
|
||||
n0.next=n2
|
||||
n2.prev=n0
|
||||
if (n2!=nil) n2.prev=n0
|
||||
else
|
||||
n0=n0.next
|
||||
end
|
||||
@ -1193,9 +1179,14 @@ function rope:relax()
|
||||
local x1,y1=n1.ax,n1.ay
|
||||
local x2,y2=n2.ax,n2.ay
|
||||
|
||||
if x1!=n1.associated_with.ax or y1!=n1.associated_with.ay then
|
||||
-- printh("dragging home: "..tostring{n1.ax,n1.ay}.."->"..tostring(n1.associated_with))
|
||||
self:_drag(n1,n1.associated_with.ax,n1.associated_with.ay)
|
||||
end
|
||||
|
||||
local would,x1_new,y1_new=would_stick(x0,y0,n1.associated_with,x2,y2)
|
||||
if not would and not (n1.ax==x1_new and n1.ay==y1_new) then
|
||||
--printh("relaxing: "..tostring(n0.associated_with).."->"..tostring(n1.associated_with).."->"..tostring(n2.associated_with))
|
||||
-- printh("relaxing: "..tostring(n0.associated_with).."->"..tostring(n1.associated_with).."->"..tostring(n2.associated_with))
|
||||
self:_drag(n1,x1_new,y1_new)
|
||||
n0=n1.prev
|
||||
n2=n1.next
|
||||
@ -1379,7 +1370,7 @@ function rope:_drag(n1,ax1_new,ay1_new)
|
||||
for anchor in level:anchor_points() do
|
||||
if
|
||||
not (anchor.ax==ax_pivot and anchor.ay==ay_pivot) and
|
||||
not (anchor.ax==ax_far0 and anchor.ay==ay_far0) and
|
||||
-- not (anchor.ax==ax_far0 and anchor.ay==ay_far0) and
|
||||
not (anchor.ax==ax_far1 and anchor.ay==ay_far1) and
|
||||
(ax0<=anchor.ax and anchor.ax<=ax1) and
|
||||
would_stick(ax_pivot,ay_pivot,anchor,ax_far,ay_far_new) and
|
||||
@ -1402,7 +1393,7 @@ function rope:_drag(n1,ax1_new,ay1_new)
|
||||
for anchor in level:anchor_points() do
|
||||
if
|
||||
not (anchor.ax==ax_pivot and anchor.ay==ay_pivot) and
|
||||
not (anchor.ax==ax_far0 and anchor.ay==ay_far0) and
|
||||
-- not (anchor.ax==ax_far0 and anchor.ay==ay_far0) and
|
||||
not (anchor.ax==ax_far1 and anchor.ay==ay_far1) and
|
||||
would_stick(ax_pivot,ay_pivot,anchor,ax_far_new,ay_far) and
|
||||
(ay0<=anchor.ay and anchor.ay<=ay1) and
|
||||
@ -1429,7 +1420,7 @@ function rope:_drag(n1,ax1_new,ay1_new)
|
||||
local anch=_sweep_radar(n0.ax,n0.ay,ax1_old,ay1_old,ax1_new,ay1_new)
|
||||
if (anch==nil) break
|
||||
local n05={ax=anch.ax,ay=anch.ay,associated_with=anch,prev=n0,next=n1}
|
||||
--printh("creating post: "..tostring(n0.associated_with).."->"..tostring(n05.associated_with).."->"..tostring(n1.associated_with))
|
||||
-- printh("creating pre: "..tostring(n0.associated_with).."->"..tostring(n05.associated_with).."->"..tostring(n1.associated_with))
|
||||
n0.next=n05
|
||||
n1.prev=n05
|
||||
n0=n05
|
||||
@ -1441,7 +1432,7 @@ function rope:_drag(n1,ax1_new,ay1_new)
|
||||
local anch=_sweep_radar(n2.ax,n2.ay,ax1_old,ay1_old,ax1_new,ay1_new)
|
||||
if (anch==nil) break
|
||||
local n15={ax=anch.ax,ay=anch.ay,associated_with=anch,prev=n1,next=n2}
|
||||
--printh("creating post: "..tostring(n1.associated_with).."->"..tostring(n15.associated_with).."->"..tostring(n2.associated_with))
|
||||
-- printh("creating post: "..tostring(n1.associated_with).."->"..tostring(n15.associated_with).."->"..tostring(n2.associated_with))
|
||||
n1.next=n15
|
||||
n2.prev=n15
|
||||
n2=n15
|
||||
@ -1503,31 +1494,30 @@ function rope:collide_mrect(mx0,my0,mw,mh,exclude_src,exclude_dst)
|
||||
if (nd==nil) return false
|
||||
end
|
||||
|
||||
local x1,y1,x2,y2=n0.ax,n0.ay,n1.ax,n1.ay
|
||||
local function _line_line(x3,y3,x4,y4)
|
||||
local denom=((y4-y3)*(x2-x1)-(x4-x3)*(y2-y1))
|
||||
|
||||
local ua=
|
||||
((x4-x3)*(y1-y3)-(y4-y3)*(x1-x3))/denom
|
||||
if (ua<0 or ua>1) return false
|
||||
|
||||
local ub=
|
||||
((x2-x1)*(y1-y3)-(y2-y1)*(x1-x3))/denom
|
||||
if (ub<0 or ub>1) return false
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
if exclude_src<=0 then
|
||||
if (_line_line(n0.ax,n0.ay,n1.ax,n1.ay,mx0,my0,mx1,my0)) return true
|
||||
if (_line_line(n0.ax,n0.ay,n1.ax,n1.ay,mx0,my0,mx0,my1)) return true
|
||||
if (_line_line(n0.ax,n0.ay,n1.ax,n1.ay,mx0,my1,mx1,my1)) return true
|
||||
if (_line_line(n0.ax,n0.ay,n1.ax,n1.ay,mx1,my0,mx1,my1)) return true
|
||||
if (_line_line(mx0,my0,mx1,my0) or _line_line(mx0,my0,mx0,my1) or _line_line(mx0,my1,mx1,my1) or _line_line(mx1,my0,mx1,my1)) return true
|
||||
end
|
||||
exclude_src-=1
|
||||
n0=n1
|
||||
end
|
||||
end
|
||||
|
||||
function _line_line(x1,y1,x2,y2,x3,y3,x4,y4)
|
||||
local denom=((y4-y3)*(x2-x1)-(x4-x3)*(y2-y1))
|
||||
|
||||
local ua=
|
||||
((x4-x3)*(y1-y3)-(y4-y3)*(x1-x3))/denom
|
||||
if (ua<0 or ua>1) return false
|
||||
|
||||
local ub=
|
||||
((x2-x1)*(y1-y3)-(y2-y1)*(x1-x3))/denom
|
||||
if (ub<0 or ub>1) return false
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
-->8
|
||||
-- moved here because it's complicated
|
||||
|
||||
@ -1728,20 +1718,20 @@ function rope:_anchors_simplified()
|
||||
x=flr(a.ax*8+0.5),y=flr(a.ay*8+0.5),
|
||||
ax=a.ax,ay=a.ay
|
||||
}
|
||||
if a.associated_with then
|
||||
if (a.associated_with.adx==1) point.x-=1
|
||||
if (a.associated_with.ady==1) point.y-=1
|
||||
elseif a.prev==nil and self.latch then
|
||||
if (self.latch.ax_offset<0) point.x-=1
|
||||
if (self.latch.ay_offset<0) point.y-=1
|
||||
local aw=a.associated_with
|
||||
local l=self.latch
|
||||
if aw then
|
||||
if (aw.adx==1) point.x-=1
|
||||
if (aw.ady==1) point.y-=1
|
||||
elseif a.prev==nil and l then
|
||||
if (l.ax_offset<0) point.x-=1
|
||||
if (l.ay_offset<0) point.y-=1
|
||||
end
|
||||
|
||||
if #points<=1 then
|
||||
local p0,p1=points[#points-1],points[#points]
|
||||
if p0==nil then
|
||||
add(points,point)
|
||||
elseif abs(
|
||||
_slope(points[#points-1],points[#points])-
|
||||
_slope(points[#points],point)
|
||||
)==0 then -- epsilon?
|
||||
elseif _slope(p0,p1)==_slope(p1,point) then -- epsilon?
|
||||
points[#points]=point
|
||||
else
|
||||
add(points,point)
|
||||
@ -1789,14 +1779,14 @@ function level_text:init()
|
||||
for i=0,32 do level_text.by_lvl[i]={} end
|
||||
for row in all(level_text_raw) do
|
||||
if row then
|
||||
lvl,x,y,s=unpack(split(row,"`"))
|
||||
add(level_text.by_lvl[lvl],{x,y,s})
|
||||
lvlxys=split(row,"`")
|
||||
add(level_text.by_lvl[lvlxys[1]],lvlxys)
|
||||
end
|
||||
end
|
||||
end
|
||||
function level_text:draw()
|
||||
for xys in all(level_text.by_lvl[level.ix]) do
|
||||
print(xys[3],xys[1],xys[2],6)
|
||||
print(xys[4],xys[2],xys[3],6)
|
||||
end
|
||||
end
|
||||
__gfx__
|
||||
@ -1974,22 +1964,22 @@ __gff__
|
||||
000000000808080808080808c00000000000000008080808080808080000000040400000080808080808080800000000404000000808080808080808c0c0c0c000000000080808080808080800000000000000000808080808080808000000000000000008080808080808080000000000000000080808080808080800000000
|
||||
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||
__map__
|
||||
0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e
|
||||
0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000e0000000000000000000000000000000e0000000000000000000000000000000e0000000000000000000000000000000e0000000000000000000000000000000e000000000000000000000000000000
|
||||
0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000e0000000000000000000000000000000e0000000000000000000000000000000e0000000000000000000000000000000e0000000000000000000000000000000e000000000000000000000000000000
|
||||
0c000000000044000c0c0c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000e0000000000000000000000000000000e0000000000000000000000000000000e0000000000000000000000000000000e0000000000000000000000000000000e000000000000000000000000000000
|
||||
0c0000000000000000000000000000000c00000000000000000000000000000c000000000000000000000000000000000e00000000000e0e0e0e0000000000000e000000000e000000000000000000000e0000000000000000000000000000000e0000000000000000000000000000000e000000000000000000000000000000
|
||||
3d1c000000001c0000000000000000000000000000000000000000000000000c000000000000000000000000000000000e00000000000000000e0000000000000e000000000e000e00000000000000000e0000000000000000000000000000000e0000000000000e0e000000000000000e00000000000e0e0e0e000000000000
|
||||
0c0000000000000000000000000000410000000000000000000000000000000c0000000000000e0e0e000000000000000e00000000000000000e0000000000000e000000000e000e00000000000000000e00000000000e0e0e000000000000000e00000000000e0000000000000000000e00000000000000000e000000000000
|
||||
0c000000000000000c0c0c0c0c0c0c0c0c00000000000020210000000000000c00000000000e00000e0e0000000000000e0000000000000e0e0e0000000000000e000000000e0e0e0e0e0000000000000e00000000000e0000000000000000000e00000000000e0e0e000000000000000e000000000000000e00000000000000
|
||||
0c0c0c0c0c0c00000000000c0c0c0c0c0c00000000000030310000000000000c000000000000000e0e000000000000000e00000000000000000e0000000000000e0000000000000e00000000000000000e00000000000e0e0e000000000000000e00000000000e00000e0000000000000e0000000000000e0000000000000000
|
||||
0c00000000000c0c004f000c0c0c0c0c0c00000000000000000000000000000c0000000000000e0e00000000000000000e00000000000e0e0e0e0000000000000e0000000000000e00000000000000000e000000000000000e000000000000000e0000000000000e0e000000000000000e0000000000000e0000000000000000
|
||||
0c00000c4f00000000000000000000120100000000000000000000000000000c00000000000e0e0e0e0e0000000000000e0000000000000000000000000000000e0000000000000e00000000000000000e00000000000e0e0e000000000000000e0000000000000000000000000000000e000000000000000000000000000000
|
||||
3d0000000000003f0c000c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000e0000000000000000000000000000000e0000000000000000000000000000000e0000000000000000000000000000000e0000000000000000000000000000000e000000000000000000000000000000
|
||||
0c0000000000000000000c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000e0000000000000000000000000000000e0000000000000000000000000000000e0000000000000000000000000000000e0000000000000000000000000000000e000000000000000000000000000000
|
||||
010000000000000c0c0c0c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000e0000000000000000000000000000000e0000000000000000000000000000000e0000000000000000000000000000000e0000000000000000000000000000000e000000000000000000000000000000
|
||||
0c0c0c0c00000c0c0c0c0c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000e0000000000000000000000000000000e0000000000000000000000000000000e0000000000000000000000000000000e0000000000000000000000000000000e000000000000000000000000000000
|
||||
0c0c0c0c00410c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c000000000000000000000000000000000e0000000000000000000000000000000e0000000000000000000000000000000e0000000000000000000000000000000e0000000000000000000000000000000e000000000000000000000000000000
|
||||
0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e
|
||||
0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c00000000000000000000000000000c0c00000000000000000000000000000c0e0000000000000000000000000000000e0000000000000000000000000000000e0000000000000000000000000000000e0000000000000000000000000000000e000000000000000000000000000000
|
||||
0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c00000000000000000000000000000c0c0000000000000c001c1c000c0c000c0e0000000000000000000000000000000e0000000000000000000000000000000e0000000000000000000000000000000e0000000000000000000000000000000e000000000000000000000000000000
|
||||
0c000000000044000c0c0c0c0c0c0c0c0c00000000000000000000000000000c0c0000000000000000000000000c000c0e0000000000000000000000000000000e0000000000000000000000000000000e0000000000000000000000000000000e0000000000000000000000000000000e000000000000000000000000000000
|
||||
0c0000000000000000000000000000000c00000000000000000000000000000c0c00004f0c0c0000000c000000001c120e00000000000e0e0e0e0000000000000e000000000e000000000000000000000e0000000000000000000000000000000e0000000000000000000000000000000e000000000000000000000000000000
|
||||
3d1c000000001c0000000000000000000000000000000000000000000000000c3d000c000c0c0000003f0c0c0000000c0e00000000000000000e0000000000000e000000000e000e00000000000000000e0000000000000000000000000000000e0000000000000e0e000000000000000e00000000000e0e0e0e000000000000
|
||||
0c0000000000000000000000000000410000000000000000000000000000000c0c000c0000000000000000000000000c0e00000000000000000e0000000000000e000000000e000e00000000000000000e00000000000e0e0e000000000000000e00000000000e0000000000000000000e00000000000000000e000000000000
|
||||
0c000000000000000c0c0c0c0c0c0c0c0c00000000000020210000000000000c01000c0c00000000000c0c004f00000c0e0000000000000e0e0e0000000000000e000000000e0e0e0e0e0000000000000e00000000000e0000000000000000000e00000000000e0e0e000000000000000e000000000000000e00000000000000
|
||||
0c0c0c0c0c0c00000000000c0c0c0c0c0c00000000000030310000000000000c0c0000000000000c00000c000000000c0e00000000000000000e0000000000000e0000000000000e00000000000000000e00000000000e0e0e000000000000000e00000000000e00000e0000000000000e0000000000000e0000000000000000
|
||||
0c00000000000c0c004f000c0c0c0c0c0c00000000000000000000000000000c0c00004f0000000c0c000c0000000c0c0e00000000000e0e0e0e0000000000000e0000000000000e00000000000000000e000000000000000e000000000000000e0000000000000e0e000000000000000e0000000000000e0000000000000000
|
||||
0c00000c4f00000000000000000000120100000000000000000000000000000c0c00000000000000000000000000000c0e0000000000000000000000000000000e0000000000000e00000000000000000e00000000000e0e0e000000000000000e0000000000000000000000000000000e000000000000000000000000000000
|
||||
3d0000000000003f0c000c0c0c0c0c0c0c00000000000000000000000000000c0c00000c00000000000000000000000c0e0000000000000000000000000000000e0000000000000000000000000000000e0000000000000000000000000000000e0000000000000000000000000000000e000000000000000000000000000000
|
||||
0c0000000000000000000c0c0c0c0c0c0c00000000000000000000000000000c0c000c0c0c0000000c0c0c004f00000c0e0000000000000000000000000000000e0000000000000000000000000000000e0000000000000000000000000000000e0000000000000000000000000000000e000000000000000000000000000000
|
||||
010000000000000c0c0c0c0c0c0c0c0c0c00000000000000000000000000000c0c00000c00000000000000000000000c0e0000000000000000000000000000000e0000000000000000000000000000000e0000000000000000000000000000000e0000000000000000000000000000000e000000000000000000000000000000
|
||||
0c0c0c0c00000c0c0c0c0c0c0c0c0c0c0c00000000000000000000000000000c0c00000000001c00000000000000000c0e0000000000000000000000000000000e0000000000000000000000000000000e0000000000000000000000000000000e0000000000000000000000000000000e000000000000000000000000000000
|
||||
0c0c0c0c00410c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0e0000000000000000000000000000000e0000000000000000000000000000000e0000000000000000000000000000000e0000000000000000000000000000000e000000000000000000000000000000
|
||||
0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e0e
|
||||
0c00000000000000000000000000000c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0000000c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0e0000000000000000000000000000000e000000000000000000000000000000
|
||||
0c004f000000000c001c1c000c0c000c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0000000000000c0c0c0c0c0c0c0c0c0c0c0c00000c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c3e0c0c0c0c0c0e0000000000000000000000000000000e000000000000000000000000000000
|
||||
|
Loading…
Reference in New Issue
Block a user