Compare commits

..

2 Commits

Author SHA1 Message Date
e3dfd9e2b0
Save/load system. Not golfed.
Saves the music flag, the last level the player played, and the furthest level reached. Loads music flag on launch. Title screen starts on most recent level played; when in "release configuration" the title screen will only let the player pick levels up to the maximum reached through gameplay, but right now this is replaced with the 31.

Save file can be wiped by holding the down arrow at the title screen.
2023-01-02 12:55:45 -08:00
38b180ba7e
Level 23. Minimal "requires pivot to avoid occlusion". 2023-01-02 01:42:02 -08:00

View File

@ -337,6 +337,7 @@ function level:advance()
end end
normpal = {[1]=0,[8]=0,[14]=0} normpal = {[1]=0,[8]=0,[14]=0}
pitpal = {[8]=0,[13]=3,[4]=3,[7]=3}
function level:draw() function level:draw()
cls(5) cls(5)
fillp() fillp()
@ -349,11 +350,15 @@ function level:draw()
for _,pit in pairs(self._pits) do for _,pit in pairs(self._pits) do
local px,py=pit.px,pit.py 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) spr(pit.s,px,py)
if pit.full then if pit.full then
spr(15,pit.px,pit.py) pal(pitpal)
palt(0,false)
spr(79,pit.px,pit.py)
pal()
pal(normpal)
end end
palt(8,true) palt(8,true)
spr(pit.s,px,py) spr(pit.s,px,py)
@ -380,7 +385,7 @@ function level:update()
_apply(crate, crate.todo) _apply(crate, crate.todo)
if #crate.todo==0 then 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 if pit and not pit.full then
add(remove,cix) add(remove,cix)
crate.dead=true crate.dead=true
@ -406,7 +411,7 @@ function level:load_dynobjs()
local crate_id=1 local crate_id=1
for mx=0,15,1 do for mx=0,15,1 do
for my=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 px,py=mx*8,my*8
local s=self:_mget(mx,my) local s=self:_mget(mx,my)
local def=self:_get_cratedef(s) local def=self:_get_cratedef(s)
@ -431,7 +436,7 @@ function level:recollide_reanchor()
self._coll={} self._coll={}
for mx=0,15 do for mx=0,15 do
for my=0,15 do for my=0,15 do
local mxy=_mix{mx,my} local mxy=_mix(mx,my)
self._coll[mxy]= self._coll[mxy]=
fget(self:_mget(mx,my),7) or fget(self:_mget(mx,my),7) or
self._crates[mxy] self._crates[mxy]
@ -452,7 +457,7 @@ function level:recollide_reanchor()
not self:mcoll(mx1,my0) and not self:mcoll(mx1,my0) and
not self:mcoll(mx1,my1) not self:mcoll(mx1,my1)
) then ) then
local key=_mix{"GEOM",mx0,my0,dx,dy} local key="GEOM"..mx0..","..my0..","..dx..","..dy
anch_new[key]= { anch_new[key]= {
max(mx0,mx1),max(my0,my1),adx=-dx,ady=-dy max(mx0,mx1),max(my0,my1),adx=-dx,ady=-dy
} }
@ -461,7 +466,7 @@ function level:recollide_reanchor()
end end
for _,cr in pairs(self._crates) do for _,cr in pairs(self._crates) do
local key=_mix{"CRATE",cr.id,dx,dy} local key="CRATE"..cr.id..","..dx..","..dy
local mx0,my0=cr.mx,cr.my local mx0,my0=cr.mx,cr.my
local mx1,my1=mx0+dx,my0+dy local mx1,my1=mx0+dx,my0+dy
anch_new[key]={ anch_new[key]={
@ -480,13 +485,11 @@ function level:recollide_reanchor()
end end
self._anch=anch_new self._anch=anch_new
self._anch_keys={} self._anch_keys={}
self._anch_by={} self._anch_by_position={}
for k,v in pairs(self._anch) do for k,v in pairs(self._anch) do
local ax,ay=_anch_unpack(v)
add(self._anch_keys,{key=k}) add(self._anch_keys,{key=k})
local pkey=_mix{ax,ay} local pkey=_mix(_anch_unpack(v))
self._anch_by[pkey]=self._anch_by[pkey] or v self._anch_by_position[pkey]=self._anch_by_position[pkey] or v
self._anch_by[_mix{ax,ay,v.adx,v.ady}]=v
end end
shellsort(self._anch_keys) shellsort(self._anch_keys)
shellsort(moves) shellsort(moves)
@ -501,7 +504,7 @@ function level:recollide_reanchor()
end end
function level:win_at(mx,my) function level:win_at(mx,my)
return self._wins[_mix{mx,my}] return self._wins[_mix(mx,my)]
end end
function level:anchor_points() function level:anchor_points()
@ -514,17 +517,11 @@ function level:anchor_points()
end end
function level:anchor_at(point) function level:anchor_at(point)
return self._anch_by[_mix{_anch_unpack(point)}] return self._anch_by_position[_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 end
function level:get_open_pit(mx,my) 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 if (pit and not pit.full) return pit
end end
@ -546,7 +543,7 @@ function level:spawn_exit()
-- next check: is at least one of -- next check: is at least one of
-- nx or ny out of range [0, 15]? -- nx or ny out of range [0, 15]?
if (nx | ny) & 0xFFF0 ~= 0 then if (nx | ny) & 0xFFF0 ~= 0 then
self._wins[_mix{nx,ny}]=true self._wins[_mix(nx,ny)]=true
end end
end end
end end
@ -560,11 +557,11 @@ end
function level:mcoll(mx,my) function level:mcoll(mx,my)
if ((mx | my) & 0xFFF0!=0) return true if ((mx | my) & 0xFFF0!=0) return true
return self._coll[_mix{mx,my}] return self._coll[_mix(mx,my)]
end end
function level:get_crate(mx,my) function level:get_crate(mx,my)
return self._crates[_mix{mx,my}] return self._crates[_mix(mx,my)]
end end
function level:_mget(mx,my) function level:_mget(mx,my)
@ -574,10 +571,8 @@ function level:_mget(mx,my)
) )
end end
function _mix(arg) function _mix(mx,my)
local out=arg[1] return mx..","..my
for i=2,#arg do out..=","..arg[i] end
return out
end end
-- crate spec: -- crate spec:
@ -596,7 +591,7 @@ end
function level:get_latch(dx,dy,px,py) function level:get_latch(dx,dy,px,py)
local mx,my=px\8,py\8 local mx,my=px\8,py\8
local mxy=_mix{mx,my} local mxy=_mix(mx,my)
local crate=self._crates[mxy] local crate=self._crates[mxy]
local dx1,dy1=-sgn0(dx),-sgn0(dy) local dx1,dy1=-sgn0(dx),-sgn0(dy)
@ -653,7 +648,7 @@ function level:can_move(
end end
function level:tug_crate(mx0,my0,dmx,dmy) function level:tug_crate(mx0,my0,dmx,dmy)
local mxy0=_mix{mx0,my0} local mxy0=_mix(mx0,my0)
local existing=self._crates[mxy0] local existing=self._crates[mxy0]
if (not existing) return if (not existing) return
@ -668,7 +663,7 @@ function level:tug_crate(mx0,my0,dmx,dmy)
{px=px1,py=py1} {px=px1,py=py1}
} }
self._crates[_mix{mx1,my1}]=existing self._crates[_mix(mx1,my1)]=existing
end end
-->8 -->8
@ -908,7 +903,6 @@ function rope:new(
id=0, id=0,
state={name="cast",frame=0}, state={name="cast",frame=0},
latch=latch, latch=latch,
flicker_t=t(),
} }
r.src=src r.src=src
r.dst=dst r.dst=dst
@ -994,7 +988,7 @@ function rope:affected_src_xy(artificial_px,artificial_py)
end end
function rope:draw(artificial_px,artificial_py) function rope:draw(artificial_px,artificial_py)
local points,highlight,hypo_ops=self:_tug(true) local points,highlight=self:_tug(true)
local n,perc_to_show,from_end = self.state.name,1.0 local n,perc_to_show,from_end = self.state.name,1.0
if (n=="done") return if (n=="done") return
if (n=="cast") perc_to_show=self.state.frame/2 if (n=="cast") perc_to_show=self.state.frame/2
@ -1064,16 +1058,6 @@ function rope:draw(artificial_px,artificial_py)
color() color()
end 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 -- debug
--[[ --[[
local n1=self.src local n1=self.src
@ -1116,7 +1100,7 @@ function rope:draw(artificial_px,artificial_py)
pset(x+p.adx,y,11) pset(x+p.adx,y,11)
pset(x,y+p.ady,11) pset(x,y+p.ady,11)
end end
]]-- ]]
end end
function rope:drag_dst(xy) function rope:drag_dst(xy)
@ -1150,9 +1134,9 @@ function rope:relax()
local n2=n1.next local n2=n1.next
if (not n2) return if (not n2) return
local adxy,position_new=calc_tension(n0,n1,n2) local anch=level:anchor_at(n1)
local anch=level:anchor_at_tension(n1,adxy) local wouldstick,position_new=would_stick(anch,n0,n1,n2)
if not anch or _anch_eq(n1,position_new) then if not (wouldstick or _anch_eq(n1,position_new)) then
self:_drag(n1,position_new,{_anch_unpack(n1)}) self:_drag(n1,position_new,{_anch_unpack(n1)})
_anch_del(n1) _anch_del(n1)
else n0=n0.next end else n0=n0.next end
@ -1228,9 +1212,9 @@ function rope:_check_pinch()
return true return true
end end
function calc_tension(xy0,xy1,xy2) function would_stick(anchor,xy0,xy1,xy2)
local x0,y0=_anch_unpack(xy0) local x0,y0=_anch_unpack(xy0)
local x1,y1=_anch_unpack(xy1) local x1,y1=_anch_unpack(xy1 or anchor)
local x2,y2=_anch_unpack(xy2) local x2,y2=_anch_unpack(xy2)
local dx,dy=x2-x0,y2-y0 local dx,dy=x2-x0,y2-y0
@ -1254,12 +1238,10 @@ function calc_tension(xy0,xy1,xy2)
x1_new,y1_new=x0+(y1-y0)/dy*dx,y1 x1_new,y1_new=x0+(y1-y0)/dy*dx,y1
ady,adx=signs(dx,x1_new-x1) ady,adx=signs(dx,x1_new-x1)
end end
return {adx,ady},{x1_new,y1_new}
end
function would_stick(anch,tens) return
adx,ady=unpack(tens) anchor and anchor.adx==adx and anchor.ady==ady,
return anch.adx==adx and anch.ady==ady {x1_new,y1_new}
end end
function rope:experience_anchor_moves(moves) function rope:experience_anchor_moves(moves)
@ -1323,7 +1305,7 @@ function rope:_be_pushed_by1(anch_old,anch_new)
(_which_side(anch_old,n0,n1)!= (_which_side(anch_old,n0,n1)!=
_which_side(anch_new,n0,n1) _which_side(anch_new,n0,n1)
) and would_stick(anch_new,calc_tension(n0,anch_new,n1)) ) and would_stick(anch_new,n0,nil,n1)
then then
local nx05,ny05 local nx05,ny05
if ax_new==ax_old then if ax_new==ax_old then
@ -1361,7 +1343,7 @@ function rope:_drag(n1,new,removing)
local side_orig=_which_side(anchor,pivot,point_orig) local side_orig=_which_side(anchor,pivot,point_orig)
local side_final=_which_side(anchor,pivot,point_final) local side_final=_which_side(anchor,pivot,point_final)
if (side_orig!=side_final and would_stick(anchor,calc_tension(pivot,anchor,point_final))) add(eligible,{anchor,side_final}) if (side_orig!=side_final and would_stick(anchor,pivot,nil,point_final)) add(eligible,{anchor,side_final})
end end
end end
@ -1522,9 +1504,7 @@ end
function rope:tug() function rope:tug()
if (not self:latched()) return if (not self:latched()) return
local success=self:_tug() return self:_tug()
if (success) self.flicker_t=t()
return success
end end
function rope:_tug(hypothetically) function rope:_tug(hypothetically)
@ -1544,16 +1524,19 @@ function rope:_tug(hypothetically)
local ops=ops_to_do local ops=ops_to_do
if #ops>0 then if #ops>0 then
if (hypothetically) return ancs,i-1,ops if (hypothetically) return ancs,i-1
for o in all(ops) do level:tug_crate(unpack(o)) end 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
return true return true
end end
end end
local latch=self.latch local latch=self.latch
if latch and latch.el=="eyehook" then if latch and latch.el=="eyehook" then
if (hypothetically) return ancs,0,{} if (hypothetically) return ancs,0
player.todo={{ player.todo={{
update=function(s) update=function(s)
if not s.rope or s.rope:done() then if not s.rope or s.rope:done() then
@ -1597,7 +1580,7 @@ function rope:_tug(hypothetically)
if not invalid_move and if not invalid_move and
level:can_move(false,mx0,my0,dmx,dmy,1,0) level:can_move(false,mx0,my0,dmx,dmy,1,0)
then then
if (hypothetically) return ancs,0,{{mx0,my0,dmx,dmy}} if (hypothetically) return ancs,0
level:tug_crate(mx0,my0,dmx,dmy) level:tug_crate(mx0,my0,dmx,dmy)
return true return true
@ -1643,7 +1626,7 @@ function rope:_calc_push(
end end
for my=my0,my1,smy do for my=my0,my1,smy do
add(ops,{mx,my,dmx,0}) add(ops,{mx=mx,my=my,dmx=dmx,dmy=0})
end end
end end
@ -1670,19 +1653,18 @@ function rope:_calc_push(
end end
for mx=mx0,mx1,smx do for mx=mx0,mx1,smx do
add(ops,{mx,my,0,dmy}) add(ops,{mx=mx,my=my,dmx=0,dmy=dmy})
end end
end end
local ops2={} local ops2={}
for o in all(ops) do for o in all(ops) do
local mx,my,dmx,dmy=unpack(o) if not level:mcoll(o.mx,o.my) then
if not level:mcoll(mx,my) then
-- great! -- great!
else else
local crate=level:get_crate(mx,my) local crate=level:get_crate(o.mx,o.my)
if crate then if crate then
if not level:can_move(false,mx,my,dmx,dmy,0,0) then if not level:can_move(false,o.mx,o.my,o.dmx,o.dmy,0,0) then
break break
end end
else else
@ -1948,14 +1930,14 @@ function persist:write()
dset(2, self.recent_level) dset(2, self.recent_level)
end end
__gfx__ __gfx__
000030000000002200003000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeff1ff1ff1fffffff1ffffff1fffffff1dddddddd111111110000000033300333 000030000000002200003000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeff1ff1ff1fffffff1ffffff1fffffff1dddddddd111111110005000000000000
003333300000332200333330eeffffffffffffffffffffeee5e555e55e555e5eff1ff1ffffffffffffffffffffffffffdddddddd111111110cc00cc033300333 003333300000332200333330eeffffffffffffffffffffeee5e555e55e555e5eff1ff1ffffffffffffffffffffffffffdddddddd111111110000500000000000
099333990039932009333339effeeeeeeeeeeeeeeeeeeffee5eeeeeeeeeeee5eff1ff1ffff111111ff1111ff111111ffdddddddd111111110cccccc033333333 099333990039932009333339effeeeeeeeeeeeeeeeeeeffee5eeeeeeeeeeee5eff1ff1ffff111111ff1111ff111111ffdddddddd111111110000000000000000
09a333a9033a932009333339efee33e3333e333e3333eefee5e333e333333e5eff1ff1ffff1fffffff1ff1fffffff1ffdddddddd1111111100c00c0000300300 09a333a9033a932009333339efee33e3333e333e3333eefee5e333e333333e5eff1ff1ffff1fffffff1ff1fffffff1ffdddddddd111111115005005000000000
023333323333320000222220efe333e3333e333e33333efee5e333e333333e5eff1ff1ffff1fffffff1ff1fffffff1ffdddddddd1111111100c00c0000300300 023333323333320000222220efe333e3333e333e33333efee5e333e333333e5eff1ff1ffff1fffffff1ff1fffffff1ffdddddddd111111110500500500000000
002222200000220000222220efe33eeeeeeeeeeeeee33efeeee33eeeeee33eeeff1111ffff111111ff1ff1ff111111ffdddddddd111111110cccccc033333333 002222200000220000222220efe33eeeeeeeeeeeeee33efeeee33eeeeee33eeeff1111ffff111111ff1ff1ff111111ffdddddddd111111110000000000000000
000222c002222c0000022200efeeee555e555e55e5eeeefee5eeeeffffeeee5effffffffffffffffff1ff1ffffffffffdddddddd111111110cc00cc033300333 000222c002222c0000022200efeeee555e555e55e5eeeefee5eeeeffffeeee5effffffffffffffffff1ff1ffffffffffdddddddd111111110005000000000000
00000cc00000cc0000000cc0efe33e5eeeeeeeeee5e33efee5e33efeefe33e5e1ffffff11fffffffff1ff1fffffffff1dddddddd111111110000000033300333 00000cc00000cc0000000cc0efe33e5eeeeeeeeee5e33efee5e33efeefe33e5e1ffffff11fffffffff1ff1fffffffff1dddddddd111111110000500000000000
0000ff000000000000000000efe33e5e11111111e5e33efee5e33efeefe33e5eff1ff1ffffffffffffffffffffffffff88888888555555555555555588888888 0000ff000000000000000000efe33e5e11111111e5e33efee5e33efeefe33e5eff1ff1ffffffffffffffffffffffffff88888888555555555555555588888888
000f00f0000000000aa00aa0efe33eee11ffff11eee33efeeee33effffe33e5eff1ff1ffffffffffffffffffffffffff88888888558855885588558888888888 000f00f0000000000aa00aa0efe33eee11ffff11eee33efeeee33effffe33e5eff1ff1ffffffffffffffffffffffffff88888888558855885588558888888888
00d0000f000000000aaaaaa0efe33e5e1ff11ff1e5e33efee5e33eeeeee33eeeff1ff1fffff11111ffffffff11111fff88888888888888888888888888888888 00d0000f000000000aaaaaa0efe33e5e1ff11ff1e5e33efee5e33eeeeee33eeeff1ff1fffff11111ffffffff11111fff88888888888888888888888888888888
@ -2035,7 +2017,7 @@ eeee0000cc04405500444400efeeee5e11111111e5eeeefeeeeeeeeeeeeeeeeeffffffffffffffff
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000031c0c000040000000000c0c0c0c0c051 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000031c0c000040000000000c0c0c0c0c051
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000031c0c0000000c000c0c0c0c0c0c0c051 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000031c0c0000000c0d0c0c0c0c0c0c0c051
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000031c0c0c0c0c0c000c0c0c0c0c0c0c051 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000031c0c0c0c0c0c000c0c0c0c0c0c0c051
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000