forked from pyrex/chameleonic
Fix misc other rope bugs
This commit is contained in:
parent
97e580e7db
commit
d2e1e9274c
120
chameleonic.p8
120
chameleonic.p8
@ -800,21 +800,6 @@ function rope:update()
|
|||||||
self.latch_frame=10
|
self.latch_frame=10
|
||||||
end
|
end
|
||||||
|
|
||||||
if (not is_busy) self:_make_consistent()
|
|
||||||
elseif self.state.name=="destroy" then -- destroy
|
|
||||||
self.state.frame+=1
|
|
||||||
if (self.state.frame>=5) self.state={name="done"}
|
|
||||||
else
|
|
||||||
-- done state
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function rope:destroy()
|
|
||||||
if (self.state.name=="destroy" or self.state.name=="done") return
|
|
||||||
self.state={name="destroy",frame=0}
|
|
||||||
end
|
|
||||||
|
|
||||||
function rope:_make_consistent()
|
|
||||||
if (self.latch==nil) self:destroy() return
|
if (self.latch==nil) self:destroy() return
|
||||||
|
|
||||||
if
|
if
|
||||||
@ -832,16 +817,21 @@ function rope:_make_consistent()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
self:_tidy_up_gen()
|
|
||||||
for i=0,#self.ancs do
|
if (not is_busy) self:_tidy_up_gen()
|
||||||
local a0=self:_anc(i)
|
elseif self.state.name=="destroy" then -- destroy
|
||||||
local a1=self:_anc(i+1)
|
self.state.frame+=1
|
||||||
if not self:_can_stretch(a0,a1) then
|
if (self.state.frame>=5) self.state={name="done"}
|
||||||
self:destroy()
|
else
|
||||||
end
|
-- done state
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function rope:destroy()
|
||||||
|
if (self.state.name=="destroy" or self.state.name=="done") return
|
||||||
|
self.state={name="destroy",frame=0}
|
||||||
|
end
|
||||||
|
|
||||||
function rope:continue_cast()
|
function rope:continue_cast()
|
||||||
local dx,dy=self.state.dx,self.state.dy
|
local dx,dy=self.state.dx,self.state.dy
|
||||||
local x0=self.src.x
|
local x0=self.src.x
|
||||||
@ -909,11 +899,12 @@ function rope:draw()
|
|||||||
circfill(x+dx+0.5,y+dy+0.5,1.0,color)
|
circfill(x+dx+0.5,y+dy+0.5,1.0,color)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
for i,p in ipairs(self.ancs) do
|
for i=0,#self.ancs+1 do
|
||||||
|
p=self:_anc(i)
|
||||||
local c=12
|
local c=12
|
||||||
if (p.dirty) c=13
|
if (p.dirty) c=13
|
||||||
rectfill(p.x-1,p.y-1,p.x+1,p.y+1,c)
|
rectfill(p.x-1,p.y-1,p.x+1,p.y+1,c)
|
||||||
print(p.id..":"..p.x..","..p.y..","..#p.todo,0,-8+i*8,9)
|
print(tostr(p.id)..":"..p.x..","..p.y..","..#p.todo,0,-8+i*8,9)
|
||||||
end
|
end
|
||||||
for _,p in pairs(level._anch) do
|
for _,p in pairs(level._anch) do
|
||||||
pset(p.x,p.y,11)
|
pset(p.x,p.y,11)
|
||||||
@ -982,6 +973,7 @@ function rope:_tidy_up_gen()
|
|||||||
end
|
end
|
||||||
if (invalid) self:make_dirty()
|
if (invalid) self:make_dirty()
|
||||||
|
|
||||||
|
local busy=self:busy()
|
||||||
if (not self:latched()) return
|
if (not self:latched()) return
|
||||||
if (not self.dirty) return
|
if (not self.dirty) return
|
||||||
|
|
||||||
@ -993,7 +985,7 @@ function rope:_tidy_up_gen()
|
|||||||
local anc=self:_anc(a)
|
local anc=self:_anc(a)
|
||||||
if anc.dirty then
|
if anc.dirty then
|
||||||
anc.seen=true
|
anc.seen=true
|
||||||
if self[f](self,a) then
|
if self[f](self,a,busy) then
|
||||||
settled=false anc.changed=true
|
settled=false anc.changed=true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -1042,6 +1034,16 @@ function rope:_tidy_up_gen()
|
|||||||
if (settled) break
|
if (settled) break
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if (self:busy()) return
|
||||||
|
|
||||||
|
for i=0,#self.ancs do
|
||||||
|
local a0=self:_anc(i)
|
||||||
|
local a1=self:_anc(i+1)
|
||||||
|
if not self:_can_stretch(a0,a1) then
|
||||||
|
self:destroy()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
self.dirty=false
|
self.dirty=false
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1105,7 +1107,7 @@ function rope:_find_touched_anchors(i)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
function rope:_elide_point(i)
|
function rope:_elide_point(i,busy)
|
||||||
if (i<=0) return false
|
if (i<=0) return false
|
||||||
if (#self.ancs<i) return false
|
if (#self.ancs<i) return false
|
||||||
|
|
||||||
@ -1114,10 +1116,10 @@ function rope:_elide_point(i)
|
|||||||
local a2=self:_anc(i+1)
|
local a2=self:_anc(i+1)
|
||||||
|
|
||||||
local level_anc=level:point_anchor(a1.x,a1.y)
|
local level_anc=level:point_anchor(a1.x,a1.y)
|
||||||
if _point_eq(a0,a1) or _point_eq(a1,a2) or level_anc==nil then
|
if _point_eq(a0,a1) or _point_eq(a1,a2) or (not busy and level_anc==nil) then
|
||||||
-- do it unconditionally
|
-- do it unconditionally
|
||||||
else
|
else
|
||||||
if _linedist(a0,a1,a2) < 0.1 then
|
if _linedist(a0,a1,a2) < 0.01 then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1136,8 +1138,8 @@ function rope:_elide_point(i)
|
|||||||
end
|
end
|
||||||
|
|
||||||
deli(self.ancs,i)
|
deli(self.ancs,i)
|
||||||
--self:_anc(i-1).dirty=true
|
a0.dirty=true a0.changed=true
|
||||||
--self:_anc(i).dirty=true
|
a2.dirty=true a2.changed=true
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1345,10 +1347,10 @@ function rope:tug_orientxy()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function rope:tug()
|
function rope:tug()
|
||||||
self:_make_consistent()
|
self:_tidy_up_gen()
|
||||||
if (not self:latched()) return
|
if (not self:latched()) return
|
||||||
self:_tug()
|
self:_tug()
|
||||||
self:_make_consistent()
|
self:_tidy_up_gen()
|
||||||
end
|
end
|
||||||
|
|
||||||
function rope:_tug(hypothetically)
|
function rope:_tug(hypothetically)
|
||||||
@ -1361,8 +1363,10 @@ function rope:_tug(hypothetically)
|
|||||||
add(self.all_ops,o)
|
add(self.all_ops,o)
|
||||||
end
|
end
|
||||||
|
|
||||||
local ops_to_do={}
|
local find_all=function(lhs,rhs,di)
|
||||||
for o in all(ops) do
|
local ops2do={}
|
||||||
|
for i=lhs,rhs,di do
|
||||||
|
local o=ops[i]
|
||||||
if not level:mcoll(o.mx,o.my) then
|
if not level:mcoll(o.mx,o.my) then
|
||||||
-- great!
|
-- great!
|
||||||
else
|
else
|
||||||
@ -1374,12 +1378,28 @@ function rope:_tug(hypothetically)
|
|||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
add(ops_to_do,o)
|
add(ops2do,o)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
return ops2do
|
||||||
|
end
|
||||||
|
|
||||||
|
local ops_before_trash=find_all(1,#ops,1)
|
||||||
|
local ops_to_do={}
|
||||||
|
local corners={}
|
||||||
|
if #ops_before_trash>0 then
|
||||||
|
ops_to_do=ops_before_trash
|
||||||
|
corners[i-1]=true
|
||||||
|
else
|
||||||
|
ops_to_do=find_all(#ops,1,-1)
|
||||||
|
corners[i]=true
|
||||||
|
end
|
||||||
|
|
||||||
local do_all=#ops==#ops_to_do
|
local do_all=#ops==#ops_to_do
|
||||||
ops=ops_to_do
|
ops=ops_to_do
|
||||||
|
|
||||||
|
if (do_all) corners[i-1]=true corners[i]=true
|
||||||
|
|
||||||
if #ops>0 then
|
if #ops>0 then
|
||||||
if (hypothetically) return ancs,i-1
|
if (hypothetically) return ancs,i-1
|
||||||
|
|
||||||
@ -1391,8 +1411,6 @@ function rope:_tug(hypothetically)
|
|||||||
o.mx,o.my,dmx,dmy
|
o.mx,o.my,dmx,dmy
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
local move_up_to=i
|
|
||||||
if (do_all) move_up_to=i-1
|
|
||||||
for node=ancs[i-1].ix,ancs[i].ix do
|
for node=ancs[i-1].ix,ancs[i].ix do
|
||||||
local anc=self:_anc(node)
|
local anc=self:_anc(node)
|
||||||
local x0,y0=anc.x,anc.y
|
local x0,y0=anc.x,anc.y
|
||||||
@ -1409,7 +1427,7 @@ function rope:_tug(hypothetically)
|
|||||||
end}
|
end}
|
||||||
end
|
end
|
||||||
local dmxh,dmyh=dmx,dmy
|
local dmxh,dmyh=dmx,dmy
|
||||||
if (node<ancs[move_up_to].ix) dmxh,dmyh=0,0
|
if (not corners[node]) dmxh,dmyh=0,0
|
||||||
anc.todo={
|
anc.todo={
|
||||||
{},
|
{},
|
||||||
upd(x0+dmxh*2,y0+dmyh*2),
|
upd(x0+dmxh*2,y0+dmyh*2),
|
||||||
@ -1431,16 +1449,22 @@ function rope:_tug(hypothetically)
|
|||||||
local dmx,dmy=
|
local dmx,dmy=
|
||||||
sgn0(latch.dx),
|
sgn0(latch.dx),
|
||||||
sgn0(latch.dy)
|
sgn0(latch.dy)
|
||||||
local lanc=ancs[2]
|
local obj_anc=ancs[1]
|
||||||
|
local pull_anc=ancs[2]
|
||||||
|
local pull_dx=pull_anc.x-obj_anc.x
|
||||||
|
local pull_dy=pull_anc.y-obj_anc.y
|
||||||
|
|
||||||
local mx0=latch.rec.mx
|
local mx0=latch.rec.mx
|
||||||
local my0=latch.rec.my
|
local my0=latch.rec.my
|
||||||
|
|
||||||
local mxa=(lanc.x+dmx)\8
|
local mxa=(pull_anc.x+dmx)\8
|
||||||
local mya=(lanc.y+dmy)\8
|
local mya=(pull_anc.y+dmy)\8
|
||||||
|
|
||||||
local too_far=false
|
local too_far=false
|
||||||
if
|
if
|
||||||
|
(dmx!=0 and sgn0(pull_dx)!=dmx) or
|
||||||
|
(dmy!=0 and sgn0(pull_dy)!=dmy) or
|
||||||
|
|
||||||
sgn0(mx0-mxa)!=
|
sgn0(mx0-mxa)!=
|
||||||
sgn0(mx0+dmx-mxa) or
|
sgn0(mx0+dmx-mxa) or
|
||||||
|
|
||||||
@ -1461,7 +1485,7 @@ function rope:_tug(hypothetically)
|
|||||||
dmx,dmy
|
dmx,dmy
|
||||||
)
|
)
|
||||||
-- be busy for 4 ticks while the crate moves
|
-- be busy for 4 ticks while the crate moves
|
||||||
self:_anc(0).todo={{},{},{},{}}
|
self:_anc(0).todo={{},{},{},{},{}}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1513,7 +1537,7 @@ function rope:_calc_push(
|
|||||||
my=(a0.y-1)\8
|
my=(a0.y-1)\8
|
||||||
dmy=-1
|
dmy=-1
|
||||||
|
|
||||||
elseif a0.y%8==7 and a0.y<an.y-3 then
|
elseif a0.y%8==7 and a0.y<an.y-6 then
|
||||||
-- push down
|
-- push down
|
||||||
my=(a0.y+1)\8
|
my=(a0.y+1)\8
|
||||||
dmy=1
|
dmy=1
|
||||||
@ -1733,9 +1757,9 @@ __map__
|
|||||||
0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
0c000000000044000c0c0c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
0c000000000044000c0c0c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
0c000000000000000c0c0c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
0c0000000000000000000000000000000c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
0c00000000001c000c0c0c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
0c00000000001c0000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
0c000000000000000c0c0c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
0c0000000000000000000000000000410000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
0c000000000000000c0c0c0c0c0c0c0c0c00000000000020210000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
0c000000000000000c0c0c0c0c0c0c0c0c00000000000020210000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
0c000000000000000000000c0c0c0c0c0c00000000000030310000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
0c000000000000000000000c0c0c0c0c0c00000000000030310000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
0c0c0c0c0c0c0c0c0000000c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
0c0c0c0c0c0c0c0c0000000c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
@ -1743,8 +1767,8 @@ __map__
|
|||||||
3d00000c4f00003f0c000c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
3d00000c4f00003f0c000c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
0c0000000000000000000c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
0c0000000000000000000c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
010000000000000c0c0c0c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
010000000000000c0c0c0c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
0c0c0c0c00000c0c0c0c0c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
0c0c0c0c00410c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
||||||
__sfx__
|
__sfx__
|
||||||
01280000050550c05511055180551d05500000000000000000055070550c0550f055130550f0550c0550705501055080550d055140551905500000000000000000055070550f0551305518055130550f0550c055
|
01280000050550c05511055180551d05500000000000000000055070550c0550f055130550f0550c0550705501055080550d055140551905500000000000000000055070550f0551305518055130550f0550c055
|
||||||
0128000000000000001f0001f055200551f0551d055180551b055000000000000000000000000000000000000000000000000001b0551d0551b05519055140551805500000000000000000000000000000000000
|
0128000000000000001f0001f055200551f0551d055180551b055000000000000000000000000000000000000000000000000001b0551d0551b05519055140551805500000000000000000000000000000000000
|
||||||
|
Loading…
Reference in New Issue
Block a user