Sorta working

This commit is contained in:
Pyrex 2022-12-18 15:18:07 -08:00
parent 581e345e31
commit 97e580e7db

View File

@ -760,6 +760,7 @@ function rope:new(
ancs={},
dst={x=x,y=y,todo={}},
state={name="cast",dx=dx,dy=dy},
dirty=true,
latch=nil,
latch_frame=0,
}
@ -783,6 +784,14 @@ function rope:busy()
end
function rope:update()
local was_busy=self:busy()
for i=0,#self.ancs+1 do
local anc=self:_anc(i)
_apply(anc,anc.todo,i)
end
local is_busy=self:busy()
if (was_busy and not is_busy) self.dirty=true
if self.state.name=="cast" then
self:continue_cast()
elseif self.state.name=="latched" then
@ -791,7 +800,7 @@ function rope:update()
self.latch_frame=10
end
self:_make_consistent()
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"}
@ -806,15 +815,8 @@ function rope:destroy()
end
function rope:_make_consistent()
for i=0,#self.ancs+1 do
local anc=self:_anc(i)
_apply(anc,anc.todo,i)
end
if (self.latch==nil) self:destroy() return
self:_tidy_up_gen()
if
self.latch!=nil and
self.latch.rec!=nil
@ -830,24 +832,14 @@ function rope:_make_consistent()
end
end
end
local invalid=false
self:_tidy_up_gen()
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
invalid=true
break
self:destroy()
end
end
if (invalid) self:make_dirty() self:_tidy_up_gen()
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
end
function rope:continue_cast()
@ -926,6 +918,9 @@ function rope:draw()
for _,p in pairs(level._anch) do
pset(p.x,p.y,11)
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)
if self.all_ops!=nil then
for i,o in ipairs(self.all_ops) do
rect(o.mx*8,o.my*8,o.mx*8+7,o.my*8+7,4)
@ -976,6 +971,17 @@ function rope:make_dirty()
end
function rope:_tidy_up_gen()
local invalid=false
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
invalid=true
break
end
end
if (invalid) self:make_dirty()
if (not self:latched()) return
if (not self.dirty) return