Fix more rope bugs

This commit is contained in:
Pyrex 2022-12-18 18:14:15 -08:00
parent 456796beca
commit 64ef489c2a

View File

@ -686,15 +686,10 @@ function player:_fall()
end end
function player:_rope_pos() function player:_rope_pos()
local px=self.x*8+self.px local px=self.x*8+self.px+4
local px2=px+4 local px2=px
if self.orientx==-1 then local py=self.y*8+self.py+3
px+=2 local py2=py
else
px+=6
end
local py=self.y*8+self.py+2
local py2=py+1
return px,py,px2,py2 return px,py,px2,py2
end end
@ -747,13 +742,13 @@ function player:draw()
setpal() setpal()
spr(16,px+6,py-2,1,1) spr(16,px+6,py-2,1,1)
spr(17,px+1,py,1,1) spr(17,px+1,py,1,1)
if (self.rope and invis_level<=0.25) pal() self.rope:draw() setpal() if (self.rope and invis_level<=0.25) pal() self.rope:draw(-2,-1) setpal()
spr(head,px-3,py-3,1,1) spr(head,px-3,py-3,1,1)
else else
setpal() setpal()
spr(16,px-6,py-2,1,1,true) spr(16,px-6,py-2,1,1,true)
spr(17,px-1,py,1,1,true) spr(17,px-1,py,1,1,true)
if (self.rope and invis_level<=0.25) pal() self.rope:draw() setpal() if (self.rope and invis_level<=0.25) pal() self.rope:draw(2,-1) setpal()
spr(head,px+3,py-3,1,1,true) spr(head,px+3,py-3,1,1,true)
end end
pal() pal()
@ -874,13 +869,15 @@ function rope:_reindex()
end end
end end
function rope:draw() function rope:draw(artificial_dx,artificial_dy)
local points,highlight=self:_tug(true) local points,highlight=self:_tug(true)
if (self:busy()) highlight=nil if (self:busy()) highlight=nil
if (self.state.name=="done") return if (self.state.name=="done") return
local perc_to_show=1.0 local perc_to_show=1.0
if (self.state.name=="destroy") perc_to_show=(1.0-self.state.frame/5)^2 if (self.state.name=="destroy") perc_to_show=(1.0-self.state.frame/5)^2
points[#points]={x=points[#points].x+artificial_dx,y=points[#points].y+artificial_dy}
local len=0 local len=0
for i=1,#points-1 do for i=1,#points-1 do
len+=distance(points[i],points[i+1]) len+=distance(points[i],points[i+1])
@ -1400,26 +1397,19 @@ function rope:_tug(hypothetically)
local touched={} local touched={}
for i=#ancs-1,2,-1 do for i=#ancs-1,2,-1 do
local ops_before_trash=self:_calc_push(ancs[i+1],ancs[i],ancs[i-1],ancs[i-2]) local ops_before_trash,hit_end1=self:_calc_push(ancs[i+1],ancs[i],ancs[i-1],ancs[i-2])
local ops_after_trash=self:_calc_push(ancs[i-2],ancs[i-1],ancs[i],ancs[i+1]) local ops_after_trash,hit_end2=self:_calc_push(ancs[i-2],ancs[i-1],ancs[i],ancs[i+1])
local ops_to_do={} local ops_to_do,corners={},{}
if #ops_before_trash>0 then if #ops_before_trash>0 then
ops_to_do=ops_before_trash ops_to_do=ops_before_trash
corners[i-1]=true
else else
ops_to_do=ops_after_trash ops_to_do=ops_after_trash
end corners[i]=true
local _is=function(x1,x2)
return x1.mx==x2.mx and x1.my==x2.my
end
local _caps=function(x,lst)
return #lst>0 and (_is(x,lst[1]) or _is(x,lst[#lst]))
end end
local corners={} local corners={}
if (_caps(ops_to_do[1],ops_before_trash)) corners[i-1]=true if (hit_end1 and hit_end2) corners[i-1],corners[i]=true,true
if (_caps(ops_to_do[#ops_to_do],ops_after_trash)) corners[i]=true
local ops=ops_to_do local ops=ops_to_do
@ -1487,7 +1477,7 @@ function rope:_tug(hypothetically)
(dmx!=0 and sgn0(pull_dx)!=dmx) or (dmx!=0 and sgn0(pull_dx)!=dmx) or
(dmy!=0 and sgn0(pull_dy)!=dmy) or (dmy!=0 and sgn0(pull_dy)!=dmy) or
_vec_ang_diff(pull_anc.x\8-mx0,pull_anc.y\8-my0,dmx,dmy) >= 0.185 or _vec_ang_diff(pull_anc.x\8-mx0,pull_anc.y\8-my0,dmx,dmy) >= 0.135 or
sgn0(mx0-mxa)!= sgn0(mx0-mxa)!=
sgn0(mx0+dmx-mxa) or sgn0(mx0+dmx-mxa) or
@ -1538,14 +1528,14 @@ function rope:_calc_push(
local mx,dmx local mx,dmx
if a0.x%8==0 and a0.x>an.x+7 then if a0.x%8==0 and a0.x>an.x+7 then
needs_good_pull=needs_good_pull or af.x>=a1.x needs_good_pull=needs_good_pull or af.x>=a1.x
if (needs_good_pull and _ang_diff(pull_ang,0.0)>=0.185) return {} if (needs_good_pull and _ang_diff(pull_ang,0.0)>=0.165) return {}
-- push left -- push left
mx=(a0.x-1)\8 mx=(a0.x-1)\8
dmx=-1 dmx=-1
elseif a0.x%8==7 and a0.x<an.x-7 then elseif a0.x%8==7 and a0.x<an.x-7 then
needs_good_pull=needs_good_pull or af.x<=a1.x needs_good_pull=needs_good_pull or af.x<=a1.x
if (needs_good_pull and _ang_diff(pull_ang,0.5)>=0.185) return {} if (needs_good_pull and _ang_diff(pull_ang,0.5)>=0.165) return {}
-- push right -- push right
mx=(a0.x+1)\8 mx=(a0.x+1)\8
@ -1570,7 +1560,7 @@ function rope:_calc_push(
local my,dmy local my,dmy
if a0.y%8==0 and a0.y>an.y+6 then if a0.y%8==0 and a0.y>an.y+6 then
needs_good_pull=needs_good_pull or af.y>=a1.y needs_good_pull=needs_good_pull or af.y>=a1.y
if (needs_good_pull and _ang_diff(pull_ang,0.75)>=0.185) return {} if (needs_good_pull and _ang_diff(pull_ang,0.75)>=0.135) return {}
-- push up -- push up
my=(a0.y-1)\8 my=(a0.y-1)\8
@ -1578,7 +1568,7 @@ function rope:_calc_push(
elseif a0.y%8==7 and a0.y<an.y-6 then elseif a0.y%8==7 and a0.y<an.y-6 then
needs_good_pull=needs_good_pull or af.y<=a1.y needs_good_pull=needs_good_pull or af.y<=a1.y
if (needs_good_pull and _ang_diff(pull_ang,0.25)>=0.185) return {} if (needs_good_pull and _ang_diff(pull_ang,0.25)>=0.135) return {}
-- push down -- push down
my=(a0.y+1)\8 my=(a0.y+1)\8
@ -1592,6 +1582,7 @@ function rope:_calc_push(
end end
end end
local hit_end=true
local ops2={} local ops2={}
for o in all(ops) do for o in all(ops) do
if not level:mcoll(o.mx,o.my) then if not level:mcoll(o.mx,o.my) then
@ -1599,16 +1590,18 @@ function rope:_calc_push(
else else
local crate=level:get_crate(o.mx,o.my) local crate=level:get_crate(o.mx,o.my)
if crate==nil then if crate==nil then
hit_end=false
break break
else else
if not level:can_move(false,o.mx,o.my,o.dmx,o.dmy,0,0) then if not level:can_move(false,o.mx,o.my,o.dmx,o.dmy,0,0) then
hit_end=false
break break
end end
end end
add(ops2,o) add(ops2,o)
end end
end end
return ops2 return ops2,hit_end
end end
function rope:_anchors_simplified() function rope:_anchors_simplified()
@ -1821,7 +1814,7 @@ __map__
0c0000000000000000000000000000410000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0c0000000000000000000000000000410000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0c000000000000000c0c0c0c0c0c0c0c0c00000000000020210000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0c000000000000000c0c0c0c0c0c0c0c0c00000000000020210000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0c0c0c0c0c0c00000000000c0c0c0c0c0c00000000000030310000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0c0c0c0c0c0c00000000000c0c0c0c0c0c00000000000030310000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0c00000000000c0c0000000c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0c00000000000c0c004f000c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0c00000c4f00000c00000000000000120100000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0c00000c4f00000c00000000000000120100000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
3d0000000000003f0c000c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 3d0000000000003f0c000c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0c0000000000000000000c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0c0000000000000000000c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000