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
normpal = {[1]=0,[8]=0,[14]=0}
pitpal = {[8]=0,[13]=3,[4]=3,[7]=3}
function level:draw()
cls(5)
fillp()
@ -349,11 +350,15 @@ 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
spr(15,pit.px,pit.py)
pal(pitpal)
palt(0,false)
spr(79,pit.px,pit.py)
pal()
pal(normpal)
end
palt(8,true)
spr(pit.s,px,py)
@ -380,7 +385,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
@ -406,7 +411,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)
@ -431,7 +436,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]
@ -452,7 +457,7 @@ function level:recollide_reanchor()
not self:mcoll(mx1,my0) and
not self:mcoll(mx1,my1)
) then
local key=_mix{"GEOM",mx0,my0,dx,dy}
local key="GEOM"..mx0..","..my0..","..dx..","..dy
anch_new[key]= {
max(mx0,mx1),max(my0,my1),adx=-dx,ady=-dy
}
@ -461,7 +466,7 @@ function level:recollide_reanchor()
end
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 mx1,my1=mx0+dx,my0+dy
anch_new[key]={
@ -480,13 +485,11 @@ function level:recollide_reanchor()
end
self._anch=anch_new
self._anch_keys={}
self._anch_by={}
self._anch_by_position={}
for k,v in pairs(self._anch) do
local ax,ay=_anch_unpack(v)
add(self._anch_keys,{key=k})
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
local pkey=_mix(_anch_unpack(v))
self._anch_by_position[pkey]=self._anch_by_position[pkey] or v
end
shellsort(self._anch_keys)
shellsort(moves)
@ -501,7 +504,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()
@ -514,17 +517,11 @@ function level:anchor_points()
end
function level:anchor_at(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}]
return self._anch_by_position[_mix(_anch_unpack(point))]
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
@ -546,7 +543,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
@ -560,11 +557,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)
@ -574,10 +571,8 @@ function level:_mget(mx,my)
)
end
function _mix(arg)
local out=arg[1]
for i=2,#arg do out..=","..arg[i] end
return out
function _mix(mx,my)
return mx..","..my
end
-- crate spec:
@ -596,7 +591,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)
@ -633,12 +628,10 @@ end
ropecheck=split"-0.6,0.4,0.4"
-- argument "o" is a rope operation:
-- array of [mx0,my0,dmx,dmy]
function level:can_move(
is_player,o,exclude_src,exclude_dst
is_player,
mx0,my0,dmx,dmy,exclude_src,exclude_dst
)
local mx0,my0,dmx,dmy=unpack(o)
local mx1,my1=mx0+dmx,my0+dmy
if (is_player and self:win_at(mx1,my1)) return true
if (is_player and self:get_open_pit(mx1,my1)) return wrongbleep:adequately_warned()
@ -654,13 +647,8 @@ function level:can_move(
return true
end
-- argument is a rope operation:
-- array of [mx0,my0,dmx,dmy]
-- must be a free function
-- to use as a foreach target
function level_tug_crate(t)
local self,mx0,my0,dmx,dmy=level,unpack(t)
local mxy0=_mix{mx0,my0}
function level:tug_crate(mx0,my0,dmx,dmy)
local mxy0=_mix(mx0,my0)
local existing=self._crates[mxy0]
if (not existing) return
@ -675,7 +663,7 @@ function level_tug_crate(t)
{px=px1,py=py1}
}
self._crates[_mix{mx1,my1}]=existing
self._crates[_mix(mx1,my1)]=existing
end
-->8
@ -741,7 +729,7 @@ function player:update()
else
local x,y=self.x,self.y
local function try_move(dx,dy,f)
if level:can_move(true,{x,y,dx,dy},0,2) then
if level:can_move(true,x,y,dx,dy,0,2) then
self.todo=f
self.cooldown=3
local t=f[#f]
@ -915,7 +903,6 @@ function rope:new(
id=0,
state={name="cast",frame=0},
latch=latch,
flicker_t=t(),
}
r.src=src
r.dst=dst
@ -1001,7 +988,7 @@ function rope:affected_src_xy(artificial_px,artificial_py)
end
function rope:draw(artificial_px,artificial_py)
local points,highlight,hypo_ops,hypo_blocks=self:_tug(true)
local points,highlight=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
@ -1071,22 +1058,6 @@ function rope:draw(artificial_px,artificial_py)
color()
end
-- hypothetical
local time=t()-self.flicker_t
if n=="latched" and time>0 and not level:busy() then
if time%0.5>0.25 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
for o in all(hypo_blocks) do
local x,y,dx,dy=unpack(o)
spr(53,8*x+4*dx,8*y+4*dy,1,1,time%0.5>0.25)
end
end
-- debug
--[[
local n1=self.src
@ -1129,7 +1100,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)
@ -1163,9 +1134,9 @@ function rope:relax()
local n2=n1.next
if (not n2) return
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
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
self:_drag(n1,position_new,{_anch_unpack(n1)})
_anch_del(n1)
else n0=n0.next end
@ -1241,9 +1212,9 @@ function rope:_check_pinch()
return true
end
function calc_tension(xy0,xy1,xy2)
function would_stick(anchor,xy0,xy1,xy2)
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 dx,dy=x2-x0,y2-y0
@ -1267,12 +1238,10 @@ function calc_tension(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
function would_stick(anch,tens)
adx,ady=unpack(tens)
return anch.adx==adx and anch.ady==ady
return
anchor and anchor.adx==adx and anchor.ady==ady,
{x1_new,y1_new}
end
function rope:experience_anchor_moves(moves)
@ -1336,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,calc_tension(n0,anch_new,n1))
) and would_stick(anch_new,n0,nil,n1)
then
local nx05,ny05
if ax_new==ax_old then
@ -1374,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,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
@ -1535,38 +1504,39 @@ end
function rope:tug()
if (not self:latched()) return
local success=self:_tug()
if (success) self.flicker_t=t()
return success
return self:_tug()
end
function rope:_tug(hypothetically)
local ancs=self:_anchors_simplified()
local touched={}
local blocks = {}
for i=#ancs-1,2,-1 do
local ops_before_trash,blocks_before_trash=self:_calc_push(ancs[i+1],ancs[i],ancs[i-1],ancs[i-2])
local ops = {}
for b in all(blocks_before_trash) do add(blocks, b) end
local ops_before_trash=self:_calc_push(ancs[i+1],ancs[i],ancs[i-1],ancs[i-2])
local ops_to_do,corners={}
if #ops_before_trash>0 then
ops=ops_before_trash
ops_to_do=ops_before_trash
else
local ops_after_trash,blocks_after_trash=self:_calc_push(ancs[i-2],ancs[i-1],ancs[i],ancs[i+1])
ops=ops_after_trash
for b in all(blocks_after_trash) do add(blocks,b) end
local ops_after_trash=self:_calc_push(ancs[i-2],ancs[i-1],ancs[i],ancs[i+1])
ops_to_do=ops_after_trash
end
local ops=ops_to_do
if #ops>0 then
if (hypothetically) return ancs,i-1,ops,blocks
foreach(ops, level_tug_crate)
if (hypothetically) return ancs,i-1
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
end
end
local latch=self.latch
if latch and latch.el=="eyehook" then
if (hypothetically) return ancs,0,{},blocks
if (hypothetically) return ancs,0
player.todo={{
update=function(s)
if not s.rope or s.rope:done() then
@ -1607,20 +1577,17 @@ function rope:_tug(hypothetically)
invalid_move=true
end
if not invalid_move then
local mv = {mx0,my0,dmx,dmy}
if level:can_move(false,mv,1,0) then
if (hypothetically) return ancs,0,{mv},blocks
if not invalid_move and
level:can_move(false,mx0,my0,dmx,dmy,1,0)
then
if (hypothetically) return ancs,0
level_tug_crate(mv)
return true
else
add(blocks, mv)
end
level:tug_crate(mx0,my0,dmx,dmy)
return true
end
end
if (hypothetically) return ancs,0,{},blocks
if (hypothetically) return ancs
return
end
@ -1645,16 +1612,21 @@ function rope:_calc_push(
smy=-smy
end
local dmx=1 -- maybe push right?
local mx,dmx
if anch.adx==-1 and a0.x>an.x+7 then
-- push left
ax0, dmx=ax0-1,-1
elseif anch.adx!=1 or a0.x>=an.x-7 then
mx=ax0-1
dmx=-1
elseif anch.adx==1 and a0.x<an.x-7 then
-- push right
mx=ax0
dmx=1
else
return {}
end
for my=my0,my1,smy do
add(ops,{ax0,my,dmx,0})
add(ops,{mx=mx,my=my,dmx=dmx,dmy=0})
end
end
@ -1666,32 +1638,42 @@ function rope:_calc_push(
smx=-smx
end
local dmy=1 -- maybe push down?
local my,dmy
if anch.ady==-1 and a0.y>an.y+6 then
-- push up
ay0,dmy=ay0-1,-1
elseif anch.ady!=1 or a0.y>=an.y-6 then
my=ay0-1
dmy=-1
elseif anch.ady==1 and a0.y<an.y-6 then
-- push down
my=ay0
dmy=1
else
return {}
end
for mx=mx0,mx1,smx do
add(ops,{mx,ay0,0,dmy})
add(ops,{mx=mx,my=my,dmx=0,dmy=dmy})
end
end
local ops2,blocked={},{}
local ops2={}
for o in all(ops) do
local mx,my=unpack(o)
if level:mcoll(mx,my) then
if (not level:get_crate(mx, my)) break
if not level:can_move(false,o,0,0) then
add(blocked,o)
if not level:mcoll(o.mx,o.my) then
-- great!
else
local crate=level:get_crate(o.mx,o.my)
if crate then
if not level:can_move(false,o.mx,o.my,o.dmx,o.dmy,0,0) then
break
end
else
break
end
add(ops2,o)
end
end
return ops2,blocked
return ops2
end
function rope:_anchors_simplified()
@ -1915,23 +1897,24 @@ function persist:init0()
cartdata("ulimate_lizard_total_destruction_0_1")
self.init0 = self.read
self:read()
self.ready=true
end
function persist:read()
self.ready=false
local m = dget(0) == 0
self.music = m
if m then music_on() else music_off() end
self.max_level = dget(1)
self.recent_level = dget(2)
self.ready=true
end
function persist:wipe()
self.ready=false
for i=0,64 do
dset(i,0)
end
self:read()
self.ready=true
end
function persist:lvlstart()
@ -1947,14 +1930,14 @@ function persist:write()
dset(2, self.recent_level)
end
__gfx__
000030000000002200003000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeff1ff1ff1fffffff1ffffff1fffffff1dddddddd111111110000000033300333
003333300000332200333330eeffffffffffffffffffffeee5e555e55e555e5eff1ff1ffffffffffffffffffffffffffdddddddd111111110cc00cc033300333
099333990039932009333339effeeeeeeeeeeeeeeeeeeffee5eeeeeeeeeeee5eff1ff1ffff111111ff1111ff111111ffdddddddd111111110cccccc033333333
09a333a9033a932009333339efee33e3333e333e3333eefee5e333e333333e5eff1ff1ffff1fffffff1ff1fffffff1ffdddddddd1111111100c00c0000300300
023333323333320000222220efe333e3333e333e33333efee5e333e333333e5eff1ff1ffff1fffffff1ff1fffffff1ffdddddddd1111111100c00c0000300300
002222200000220000222220efe33eeeeeeeeeeeeee33efeeee33eeeeee33eeeff1111ffff111111ff1ff1ff111111ffdddddddd111111110cccccc033333333
000222c002222c0000022200efeeee555e555e55e5eeeefee5eeeeffffeeee5effffffffffffffffff1ff1ffffffffffdddddddd111111110cc00cc033300333
00000cc00000cc0000000cc0efe33e5eeeeeeeeee5e33efee5e33efeefe33e5e1ffffff11fffffffff1ff1fffffffff1dddddddd111111110000000033300333
000030000000002200003000eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeff1ff1ff1fffffff1ffffff1fffffff1dddddddd111111110005000000000000
003333300000332200333330eeffffffffffffffffffffeee5e555e55e555e5eff1ff1ffffffffffffffffffffffffffdddddddd111111110000500000000000
099333990039932009333339effeeeeeeeeeeeeeeeeeeffee5eeeeeeeeeeee5eff1ff1ffff111111ff1111ff111111ffdddddddd111111110000000000000000
09a333a9033a932009333339efee33e3333e333e3333eefee5e333e333333e5eff1ff1ffff1fffffff1ff1fffffff1ffdddddddd111111115005005000000000
023333323333320000222220efe333e3333e333e33333efee5e333e333333e5eff1ff1ffff1fffffff1ff1fffffff1ffdddddddd111111110500500500000000
002222200000220000222220efe33eeeeeeeeeeeeee33efeeee33eeeeee33eeeff1111ffff111111ff1ff1ff111111ffdddddddd111111110000000000000000
000222c002222c0000022200efeeee555e555e55e5eeeefee5eeeeffffeeee5effffffffffffffffff1ff1ffffffffffdddddddd111111110005000000000000
00000cc00000cc0000000cc0efe33e5eeeeeeeeee5e33efee5e33efeefe33e5e1ffffff11fffffffff1ff1fffffffff1dddddddd111111110000500000000000
0000ff000000000000000000efe33e5e11111111e5e33efee5e33efeefe33e5eff1ff1ffffffffffffffffffffffffff88888888555555555555555588888888
000f00f0000000000aa00aa0efe33eee11ffff11eee33efeeee33effffe33e5eff1ff1ffffffffffffffffffffffffff88888888558855885588558888888888
00d0000f000000000aaaaaa0efe33e5e1ff11ff1e5e33efee5e33eeeeee33eeeff1ff1fffff11111ffffffff11111fff88888888888888888888888888888888
@ -1973,10 +1956,10 @@ eeee0000cc04405500444400efeeee5e11111111e5eeeefeeeeeeeeeeeeeeeeeffffffffffffffff
000aa111991111103bbbbbb3eeeeeeeeeeeeeeeeeeeeeeeeff1ff1ffffffffffffffffff00000000000000000000000000000000000000000000000000000000
0000000099100000f765000000000000000000000000000000000000000000000000000000000000000000000000000011111111111111111999999111111111
00000000990000007700000000000000000000000000000000000000000000000000000000000000000000000000000019911991999999911999999119999999
00000000990000006060000000000000000bc0000090020000000000000000000000000000000000000000000000000019977991999999911999999119999999
00000000090000005005000000bbcc00000bc0000009200000000000000000000000000000000000000000000000000019911991999117111991199111711999
00000000aa0000000000000000ccbb00000cb0000002900000000000000000000000000000000000000000000000000019911991999117111991199111711999
0000000077a000000000000000000000000cb0000020090000000000000000000000000000000000000000000000000019999991999999911997799119999999
00000000990000006060000000000000000000000000000000000000000000000000000000000000000000000000000019977991999999911999999119999999
00000000090000005005000000000000000000000000000000000000000000000000000000000000000000000000000019911991999117111991199111711999
00000000aa0000000000000000000000000000000000000000000000000000000000000000000000000000000000000019911991999117111991199111711999
0000000077a000000000000000000000000000000000000000000000000000000000000000000000000000000000000019999991999999911997799119999999
00000007777a00000000000000000000000000000000000000000000000000000000000000000000000000000000000019999991999999911991199119999999
00044444444444000000000000000000000000000000000000000000000000000000000000000000000000000000000019999991111111111111111111111111
44444444444004444444444444400444444444444440044444444444444004444444444444400444444444444440044444444444444004444444444444400444
@ -2034,7 +2017,7 @@ eeee0000cc04405500444400efeeee5e11111111e5eeeefeeeeeeeeeeeeeeeeeffffffffffffffff
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000031c0c000040000000000c0c0c0c0c051
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000031c0c0000000c000c0c0c0c0c0c0c051
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000031c0c0000000c0d0c0c0c0c0c0c0c051
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000031c0c0c0c0c0c000c0c0c0c0c0c0c051
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
@ -2206,7 +2189,7 @@ __label__
77777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777
__gff__
000000c0c0c0c0c0c0c0c0c0c0c00000000000c0c0c0c0c0c0c0c0c0202020200040c0c0c0c0c0c0c008080800000000404000000000080808080808c0c0c0c000000000080808080808080800000008000000000808080808080808000000000008080808080808080808080000000000080808080808080808080800000000
000000c0c0c0c0c0c0c0c0c0c0c00000000000c0c0c0c0c0c0c0c0c0202020200040c0c0c0c0c0c0c008080800000000404000000808080808080808c0c0c0c000000000080808080808080800000008000000000808080808080808000000000008080808080808080808080000000000080808080808080808080800000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
__map__
0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d1203040404050d0d0d0d010d0d0d0d0d0d0d0d0d0d0d0d0d0d120d0d0d0d0d0d0d0d0d0d0d0d0d03043e0a040404050d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d