Compare commits

...

2 Commits

Author SHA1 Message Date
5df3f00809 Fix another rope bug 2023-01-02 13:05:58 -08:00
c81b3a03d3 Crate push previews 2023-01-02 12:18:30 -08:00

View File

@ -319,7 +319,6 @@ function level:advance()
end
normpal = {[1]=0,[8]=0,[14]=0}
pitpal = {[8]=0,[13]=3,[4]=3,[7]=3}
function level:draw()
cls(5)
fillp()
@ -332,15 +331,11 @@ function level:draw()
for _,pit in pairs(self._pits) do
local px,py=pit.px,pit.py
local pr=self._pits[_mix(px+1,py)]
local pr=self._pits[_mix{px+1,py}]
spr(pit.s,px,py)
if pit.full then
pal(pitpal)
palt(0,false)
spr(79,pit.px,pit.py)
pal()
pal(normpal)
spr(15,pit.px,pit.py)
end
palt(8,true)
spr(pit.s,px,py)
@ -367,7 +362,7 @@ function level:update()
_apply(crate, crate.todo)
if #crate.todo==0 then
local pit=self._pits[_mix(crate.mx,crate.my)]
local pit=self._pits[_mix{crate.mx,crate.my}]
if pit and not pit.full then
add(remove,cix)
crate.dead=true
@ -393,7 +388,7 @@ function level:load_dynobjs()
local crate_id=1
for mx=0,15,1 do
for my=0,15,1 do
local mxy=_mix(mx,my)
local mxy=_mix{mx,my}
local px,py=mx*8,my*8
local s=self:_mget(mx,my)
local def=self:_get_cratedef(s)
@ -418,7 +413,7 @@ function level:recollide_reanchor()
self._coll={}
for mx=0,15 do
for my=0,15 do
local mxy=_mix(mx,my)
local mxy=_mix{mx,my}
self._coll[mxy]=
fget(self:_mget(mx,my),7) or
self._crates[mxy]
@ -439,7 +434,7 @@ function level:recollide_reanchor()
not self:mcoll(mx1,my0) and
not self:mcoll(mx1,my1)
) then
local key="GEOM"..mx0..","..my0..","..dx..","..dy
local key=_mix{"GEOM",mx0,my0,dx,dy}
anch_new[key]= {
max(mx0,mx1),max(my0,my1),adx=-dx,ady=-dy
}
@ -448,7 +443,7 @@ function level:recollide_reanchor()
end
for _,cr in pairs(self._crates) do
local key="CRATE"..cr.id..","..dx..","..dy
local key=_mix{"CRATE",cr.id,dx,dy}
local mx0,my0=cr.mx,cr.my
local mx1,my1=mx0+dx,my0+dy
anch_new[key]={
@ -467,11 +462,13 @@ function level:recollide_reanchor()
end
self._anch=anch_new
self._anch_keys={}
self._anch_by_position={}
self._anch_by={}
for k,v in pairs(self._anch) do
local ax,ay=_anch_unpack(v)
add(self._anch_keys,{key=k})
local pkey=_mix(_anch_unpack(v))
self._anch_by_position[pkey]=self._anch_by_position[pkey] or v
local pkey=_mix{ax,ay}
self._anch_by[pkey]=self._anch_by[pkey] or v
self._anch_by[_mix{ax,ay,v.adx,v.ady}]=v
end
shellsort(self._anch_keys)
shellsort(moves)
@ -486,7 +483,7 @@ function level:recollide_reanchor()
end
function level:win_at(mx,my)
return self._wins[_mix(mx,my)]
return self._wins[_mix{mx,my}]
end
function level:anchor_points()
@ -499,11 +496,17 @@ function level:anchor_points()
end
function level:anchor_at(point)
return self._anch_by_position[_mix(_anch_unpack(point))]
return self._anch_by[_mix{_anch_unpack(point)}]
end
function level:anchor_at_tension(point,tension)
local ax,ay=_anch_unpack(point)
local adx,ady=_anch_unpack(tension)
return self._anch_by[_mix{ax,ay,adx,ady}]
end
function level:get_open_pit(mx,my)
local pit=self._pits[_mix(mx,my)]
local pit=self._pits[_mix{mx,my}]
if (pit and not pit.full) return pit
end
@ -525,7 +528,7 @@ function level:spawn_exit()
-- next check: is at least one of
-- nx or ny out of range [0, 15]?
if (nx | ny) & 0xFFF0 ~= 0 then
self._wins[_mix(nx,ny)]=true
self._wins[_mix{nx,ny}]=true
end
end
end
@ -539,11 +542,11 @@ end
function level:mcoll(mx,my)
if ((mx | my) & 0xFFF0!=0) return true
return self._coll[_mix(mx,my)]
return self._coll[_mix{mx,my}]
end
function level:get_crate(mx,my)
return self._crates[_mix(mx,my)]
return self._crates[_mix{mx,my}]
end
function level:_mget(mx,my)
@ -553,8 +556,10 @@ function level:_mget(mx,my)
)
end
function _mix(mx,my)
return mx..","..my
function _mix(arg)
local out=arg[1]
for i=2,#arg do out..=","..arg[i] end
return out
end
-- crate spec:
@ -573,7 +578,7 @@ end
function level:get_latch(dx,dy,px,py)
local mx,my=px\8,py\8
local mxy=_mix(mx,my)
local mxy=_mix{mx,my}
local crate=self._crates[mxy]
local dx1,dy1=-sgn0(dx),-sgn0(dy)
@ -630,7 +635,7 @@ function level:can_move(
end
function level:tug_crate(mx0,my0,dmx,dmy)
local mxy0=_mix(mx0,my0)
local mxy0=_mix{mx0,my0}
local existing=self._crates[mxy0]
if (not existing) return
@ -645,7 +650,7 @@ function level:tug_crate(mx0,my0,dmx,dmy)
{px=px1,py=py1}
}
self._crates[_mix(mx1,my1)]=existing
self._crates[_mix{mx1,my1}]=existing
end
-->8
@ -885,6 +890,7 @@ function rope:new(
id=0,
state={name="cast",frame=0},
latch=latch,
flicker_t=t(),
}
r.src=src
r.dst=dst
@ -970,7 +976,7 @@ function rope:affected_src_xy(artificial_px,artificial_py)
end
function rope:draw(artificial_px,artificial_py)
local points,highlight=self:_tug(true)
local points,highlight,hypo_ops=self:_tug(true)
local n,perc_to_show,from_end = self.state.name,1.0
if (n=="done") return
if (n=="cast") perc_to_show=self.state.frame/2
@ -1040,6 +1046,16 @@ function rope:draw(artificial_px,artificial_py)
color()
end
-- hypothetical
local time=t()-self.flicker_t
if n=="latched" and time>0 and time%0.5>0.25 and not level:busy() then
for o in all(hypo_ops) do
local mx0,my0,dmx,dmy=unpack(o)
local px1,py1=(mx0+dmx)*8,(my0+dmy)*8
spr(14,px1,py1)
end
end
-- debug
--[[
local n1=self.src
@ -1082,7 +1098,7 @@ 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(xy)
@ -1116,9 +1132,9 @@ function rope:relax()
local n2=n1.next
if (not n2) return
local anch=level:anchor_at(n1)
local wouldstick,position_new=would_stick(anch,n0,n1,n2)
if not (wouldstick or _anch_eq(n1,position_new)) then
local adxy,position_new=calc_tension(n0,n1,n2)
local anch=level:anchor_at_tension(n1,adxy)
if not anch or _anch_eq(n1,position_new) then
self:_drag(n1,position_new,{_anch_unpack(n1)})
_anch_del(n1)
else n0=n0.next end
@ -1194,9 +1210,9 @@ function rope:_check_pinch()
return true
end
function would_stick(anchor,xy0,xy1,xy2)
function calc_tension(xy0,xy1,xy2)
local x0,y0=_anch_unpack(xy0)
local x1,y1=_anch_unpack(xy1 or anchor)
local x1,y1=_anch_unpack(xy1)
local x2,y2=_anch_unpack(xy2)
local dx,dy=x2-x0,y2-y0
@ -1220,10 +1236,12 @@ function would_stick(anchor,xy0,xy1,xy2)
x1_new,y1_new=x0+(y1-y0)/dy*dx,y1
ady,adx=signs(dx,x1_new-x1)
end
return {adx,ady},{x1_new,y1_new}
end
return
anchor and anchor.adx==adx and anchor.ady==ady,
{x1_new,y1_new}
function would_stick(anch,tens)
adx,ady=unpack(tens)
return anch.adx==adx and anch.ady==ady
end
function rope:experience_anchor_moves(moves)
@ -1287,7 +1305,7 @@ function rope:_be_pushed_by1(anch_old,anch_new)
(_which_side(anch_old,n0,n1)!=
_which_side(anch_new,n0,n1)
) and would_stick(anch_new,n0,nil,n1)
) and would_stick(anch_new,calc_tension(n0,anch_new,n1))
then
local nx05,ny05
if ax_new==ax_old then
@ -1325,7 +1343,7 @@ function rope:_drag(n1,new,removing)
local side_orig=_which_side(anchor,pivot,point_orig)
local side_final=_which_side(anchor,pivot,point_final)
if (side_orig!=side_final and would_stick(anchor,pivot,nil,point_final)) add(eligible,{anchor,side_final})
if (side_orig!=side_final and would_stick(anchor,calc_tension(pivot,anchor,point_final))) add(eligible,{anchor,side_final})
end
end
@ -1486,7 +1504,9 @@ end
function rope:tug()
if (not self:latched()) return
return self:_tug()
local success=self:_tug()
if (success) self.flicker_t=t()
return success
end
function rope:_tug(hypothetically)
@ -1506,19 +1526,16 @@ function rope:_tug(hypothetically)
local ops=ops_to_do
if #ops>0 then
if (hypothetically) return ancs,i-1
if (hypothetically) return ancs,i-1,ops
local dmx,dmy=ops[1].dmx,ops[1].dmy
for o in all(ops) do
level:tug_crate(o.mx,o.my,o.dmx,o.dmy)
end
for o in all(ops) do level:tug_crate(unpack(o)) end
return true
end
end
local latch=self.latch
if latch and latch.el=="eyehook" then
if (hypothetically) return ancs,0
if (hypothetically) return ancs,0,{}
player.todo={{
update=function(s)
if not s.rope or s.rope:done() then
@ -1562,7 +1579,7 @@ function rope:_tug(hypothetically)
if not invalid_move and
level:can_move(false,mx0,my0,dmx,dmy,1,0)
then
if (hypothetically) return ancs,0
if (hypothetically) return ancs,0,{{mx0,my0,dmx,dmy}}
level:tug_crate(mx0,my0,dmx,dmy)
return true
@ -1608,7 +1625,7 @@ function rope:_calc_push(
end
for my=my0,my1,smy do
add(ops,{mx=mx,my=my,dmx=dmx,dmy=0})
add(ops,{mx,my,dmx,0})
end
end
@ -1635,18 +1652,19 @@ function rope:_calc_push(
end
for mx=mx0,mx1,smx do
add(ops,{mx=mx,my=my,dmx=0,dmy=dmy})
add(ops,{mx,my,0,dmy})
end
end
local ops2={}
for o in all(ops) do
if not level:mcoll(o.mx,o.my) then
local mx,my,dmx,dmy=unpack(o)
if not level:mcoll(mx,my) then
-- great!
else
local crate=level:get_crate(o.mx,o.my)
local crate=level:get_crate(mx,my)
if crate then
if not level:can_move(false,o.mx,o.my,o.dmx,o.dmy,0,0) then
if not level:can_move(false,mx,my,dmx,dmy,0,0) then
break
end
else
@ -1864,14 +1882,14 @@ function debugmouse:draw3()
end
__gfx__
000030000000002200003000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeff1ff1ff1fffffff1ffffff1fffffff1dddddddd111111110005000000000000
003333300000332200333330eeffffffffffffffffffffeee5e555e55e555e5eff1ff1ffffffffffffffffffffffffffdddddddd111111110000500000000000
099333990039932009333339effeeeeeeeeeeeeeeeeeeffee5eeeeeeeeeeee5eff1ff1ffff111111ff1111ff111111ffdddddddd111111110000000000000000
09a333a9033a932009333339efee33e3333e333e3333eefee5e333e333333e5eff1ff1ffff1fffffff1ff1fffffff1ffdddddddd111111115005005000000000
023333323333320000222220efe333e3333e333e33333efee5e333e333333e5eff1ff1ffff1fffffff1ff1fffffff1ffdddddddd111111110500500500000000
002222200000220000222220efe33eeeeeeeeeeeeee33efeeee33eeeeee33eeeff1111ffff111111ff1ff1ff111111ffdddddddd111111110000000000000000
000222c002222c0000022200efeeee555e555e55e5eeeefee5eeeeffffeeee5effffffffffffffffff1ff1ffffffffffdddddddd111111110005000000000000
00000cc00000cc0000000cc0efe33e5eeeeeeeeee5e33efee5e33efeefe33e5e1ffffff11fffffffff1ff1fffffffff1dddddddd111111110000500000000000
000030000000002200003000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeff1ff1ff1fffffff1ffffff1fffffff1dddddddd111111110000000033300333
003333300000332200333330eeffffffffffffffffffffeee5e555e55e555e5eff1ff1ffffffffffffffffffffffffffdddddddd111111110cc00cc033300333
099333990039932009333339effeeeeeeeeeeeeeeeeeeffee5eeeeeeeeeeee5eff1ff1ffff111111ff1111ff111111ffdddddddd111111110cccccc033333333
09a333a9033a932009333339efee33e3333e333e3333eefee5e333e333333e5eff1ff1ffff1fffffff1ff1fffffff1ffdddddddd1111111100c00c0000300300
023333323333320000222220efe333e3333e333e33333efee5e333e333333e5eff1ff1ffff1fffffff1ff1fffffff1ffdddddddd1111111100c00c0000300300
002222200000220000222220efe33eeeeeeeeeeeeee33efeeee33eeeeee33eeeff1111ffff111111ff1ff1ff111111ffdddddddd111111110cccccc033333333
000222c002222c0000022200efeeee555e555e55e5eeeefee5eeeeffffeeee5effffffffffffffffff1ff1ffffffffffdddddddd111111110cc00cc033300333
00000cc00000cc0000000cc0efe33e5eeeeeeeeee5e33efee5e33efeefe33e5e1ffffff11fffffffff1ff1fffffffff1dddddddd111111110000000033300333
0000ff000000000000000000efe33e5e11111111e5e33efee5e33efeefe33e5eff1ff1ffffffffffffffffffffffffff88888888555555555555555588888888
000f00f0000000000aa00aa0efe33eee11ffff11eee33efeeee33effffe33e5eff1ff1ffffffffffffffffffffffffff88888888558855885588558888888888
00d0000f000000000aaaaaa0efe33e5e1ff11ff1e5e33efee5e33eeeeee33eeeff1ff1fffff11111ffffffff11111fff88888888888888888888888888888888