Compare commits

..

No commits in common. "d0eba82c7b5131b3e44af4a8bef53ded513ef10a" and "11e33d010911cf1392006c50ffe7fa525ac612a7" have entirely different histories.

View File

@ -22,6 +22,7 @@ function names(root)
end end
function _doall(x) function _doall(x)
for n in names(x) do for n in names(x) do
for mod in all(modules) do for mod in all(modules) do
local f=mod[n] local f=mod[n]
@ -31,12 +32,13 @@ function _doall(x)
end end
-- source: https://www.lexaloffle.com/bbs/?pid=78990 -- source: https://www.lexaloffle.com/bbs/?pid=78990
gaps=split"57,23,10,4,1" gaps={57,23,10,4,1}
--{701,301,132,57,23,10,4,1} --{701,301,132,57,23,10,4,1}
function shellsort(a) function shellsort(a)
for gap in all(gaps) do for gap in all(gaps) do
for i=gap+1,#a do for i=gap+1,#a do
local x,j=a[i],i-gap local x=a[i]
local j=i-gap
while j>=1 and a[j].key>x.key do while j>=1 and a[j].key>x.key do
a[j+gap]=a[j] a[j+gap]=a[j]
j-=gap j-=gap
@ -55,36 +57,36 @@ function linefill(ax,ay,bx,by,r,c)
local n=min(abs(dx),abs(dy))/d local n=min(abs(dx),abs(dy))/d
d*=sqrt(n*n+1) d*=sqrt(n*n+1)
if(d<0.001) return if(d<0.001) return
local ca,sa=dx/d,-dy/d local ca,sa=dx/d,-dy/d
-- polygon points -- polygon points
local s={ local s={
{0,-r},{d,-r},{d,r},{0,r} {0,-r},{d,-r},{d,r},{0,r}
} }
local u,v,spans=s[4][1],s[4][2],{} local u,v,spans=s[4][1],s[4][2],{}
local x0,y0=ax+u*ca+v*sa,ay-u*sa+v*ca local x0,y0=ax+u*ca+v*sa,ay-u*sa+v*ca
for i=1,4 do for i=1,4 do
local u,v=s[i][1],s[i][2] local u,v=s[i][1],s[i][2]
local x1,y1=ax+u*ca+v*sa,ay-u*sa+v*ca local x1,y1=ax+u*ca+v*sa,ay-u*sa+v*ca
local _x1,_y1=x1,y1 local _x1,_y1=x1,y1
if(y0>y1) x0,y0,x1,y1=x1,y1,x0,y0 if(y0>y1) x0,y0,x1,y1=x1,y1,x0,y0
local dx=(x1-x0)/(y1-y0) local dx=(x1-x0)/(y1-y0)
if(y0<0) x0-=y0*dx y0=-1 if(y0<0) x0-=y0*dx y0=-1
local cy0=y0\1+1 local cy0=y0\1+1
-- sub-pix shift -- sub-pix shift
x0+=(cy0-y0)*dx x0+=(cy0-y0)*dx
for y=y0\1+1,min(y1\1,127) do for y=y0\1+1,min(y1\1,127) do
-- open span? -- open span?
local span=spans[y] local span=spans[y]
if span then if span then
rectfill(x0,y,span,y) rectfill(x0,y,span,y)
else else
spans[y]=x0 spans[y]=x0
end
x0+=dx
end end
x0+=dx x0,y0=_x1,_y1
end end
x0,y0=_x1,_y1
end
end end
function _apply(x,ts,a) function _apply(x,ts,a)
@ -140,27 +142,14 @@ function level:advance()
end end
function level:draw() function level:draw()
cls(1)
pal(1,0)
map( map(
self.bigx*16,self.bigy*16, self.bigx*16,self.bigy*16,
0,0,16,16, 0,0,16,16,
64 -- flag 6: visible 64 -- flag 6: visible
) )
for _,pit in pairs(self._pits) do
spr(pit.s,pit.px,pit.py)
if pit.contents then
pal(7,0)
pal(0,1)
palt(0,false)
spr(pit.contents,pit.px,pit.py)
pal()
end
for _,crate in pairs(self._crates) do for _,crate in pairs(self._crates) do
spr(crate.s,crate.px,crate.py) spr(crate.s,crate.px,crate.py)
end
end end
pal()
end end
function level:busy() function level:busy()
@ -173,55 +162,26 @@ end
function level:update() function level:update()
_apply(self, self.todo) _apply(self, self.todo)
local remove={} for _,crate in pairs(self._crates) do
for cix,crate in pairs(self._crates) do
_apply(crate, crate.todo) _apply(crate, crate.todo)
if #crate.todo==0 then
local pit=self._pits[_mix(crate.mx,crate.my)]
if pit!=nil and pit.contents==nil then
add(remove,cix)
crate.dead=true
pit.contents=crate.s
end
end
end
for cix in all(remove) do
self._crates[cix]=nil
end
if #remove>0 then
self:recollide()
self:reanchor(true)
end end
end end
function level:load_dynobjs() function level:load_dynobjs()
self._crates={} self._crates={}
self._pits={}
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 s=self:_mget(mx,my) local s=self:_mget(mx,my)
local def=self:_get_cratedef(s) local def=self:_get_cratedef(s)
if def!=nil then if def!=nil then
self._crates[mxy]={ self._crates[mxy]={
s=s,def=def, s=s,def=def,
mx=mx,my=my, mx=mx,my=my,
px=px,py=py, px=mx*8,py=my*8,
todo={} todo={}
} }
end end
if s==28 then -- pit
self._pits[mxy]={
s=s,
mx=mx,my=my,
px=px,py=py,
contents=nil
}
end
end end
end end
end end
@ -281,11 +241,6 @@ function level:anchors_in(px0,py0,px1,py1)
return ancs return ancs
end end
function level:get_open_pit(mx,my)
local pit=self._pits[_mix(mx,my)]
if (pit and pit.contents==nil) return pit
end
function level:point_anchor(px,py) function level:point_anchor(px,py)
local ax,ay=self:p2a(px,py) local ax,ay=self:p2a(px,py)
local anc=self._anch[_amix(ax,ay)] local anc=self._anch[_amix(ax,ay)]
@ -479,8 +434,6 @@ function player:reinit(x,y)
self.px=0 self.px=0
self.py=0 self.py=0
self.todo={} self.todo={}
self.fall_frame=0
self.orientx=-1 self.orientx=-1
self.orienty=0 self.orienty=0
@ -514,11 +467,6 @@ function player:update()
level:advance() level:advance()
return return
end end
if level:get_open_pit(self.x,self.y) then
self.todo={{update=self._fall}}
return
end
if btn(⬅️) then if btn(⬅️) then
if level:can_move(true,self.x,self.y,-1,0,0,2) then if level:can_move(true,self.x,self.y,-1,0,0,2) then
self.todo=f4({{orientx=-1,orienty=0,px=-2},{px=-7},{x=self.x-1}}) self.todo=f4({{orientx=-1,orienty=0,px=-2},{px=-7},{x=self.x-1}})
@ -584,12 +532,6 @@ function player:update()
end end
end end
function player:_fall()
if self.fall_frame<10 then
self.fall_frame+=1
end
end
function player:_rope_pos() function player:_rope_pos()
local px=self.x*8+self.px local px=self.x*8+self.px
local px2=px+4 local px2=px+4
@ -608,26 +550,21 @@ function player:draw()
local py=self.y*8+self.py local py=self.y*8+self.py
local head=2-self.orienty local head=2-self.orienty
if (self.fall_frame>5) return
if (self.fall_frame>0) then
for i=0,15 do pal(i,1) end
end
if self.orientx==-1 then if self.orientx==-1 then
spr(16,px+6,py-2,1,1) spr(16,px+6,py-2,1,1)
if (self.rope and self.fall_frame==0) self.rope:draw() if (self.rope) self.rope:draw()
spr(17,px+1,py,1,1) spr(17,px+1,py,1,1)
spr(head,px-3,py-3,1,1) spr(head,px-3,py-3,1,1)
else else
spr(16,px-6,py-2,1,1,true) spr(16,px-6,py-2,1,1,true)
if (self.rope and self.fall_frame==0) self.rope:draw() if (self.rope) self.rope:draw()
spr(17,px-1,py,1,1,true) spr(17,px-1,py,1,1,true)
spr(head,px+3,py-3,1,1,true) spr(head,px+3,py-3,1,1,true)
end end
pal() --spr(17,px+3,py)
--spr(17,px+6,py)
-- if spr(2,self.x*8+self.px)
end end
-->8 -->8
@ -700,16 +637,12 @@ function rope:_make_consistent()
) )
if #self.latch.rec.todo==0 then if #self.latch.rec.todo==0 then
if self.latch.rec.dead==true then
self.under_destruction=true
return
end
for i=0,#self.ancs do for i=0,#self.ancs do
local a0=self:_anc(i) local a0=self:_anc(i)
local a1=self:_anc(i+1) local a1=self:_anc(i+1)
if not self:_can_stretch(a0, a1) then if not self:_can_stretch(a0, a1) then
self.under_destruction=true self.under_destruction=true
return break
end end
end end
end end
@ -1338,22 +1271,22 @@ end
__gfx__ __gfx__
000000000003000000000033000300000000000000000000000000000000000000000000000000000000000000000000dddddddd000000000000000000000000 00000000000300000000003300030000000000000000000000000000000000000000000000000000000000000000000077777777000000000000000000000000
000000000333330000003333033333000aa00aa000000000000000000000000000000000000000000000000000000000dddddddd000000000000000000000000 000000000333330000003333033333000aa00aa00000000000000000000000000000000000000000000000000000000077777777000000000000000000000000
000000009933399000399330933333900aaaaaa000000000000000000000000000000000000000000000000000000000dddddddd000000000000000000000000 000000009933399000399330933333900aaaaaa00000000000000000000000000000000000000000000000000000000077777777000000000000000000000000
000000009a333a90033a9330933333900aaaaaa000000000000000000000000000000000000000000000000000000000dddddddd000000000000000000000000 000000009a333a90033a9330933333900aaaaaa00000000000000000000000000000000000000000000000000000000077777777000000000000000000000000
000000003333333033333300033333000099990000000000000000000000000000000000000000000000000000000000dddddddd000000000000000000000000 00000000333333303333330003333300009999000000000000000000000000000000000000000000000000000000000077777777000000000000000000000000
0000000003333300000033000333330000aaaa0000000000000000000000000000000000000000000000000000000000dddddddd000000000000000000000000 0000000003333300000033000333330000aaaa000000000000000000000000000000000000000000000000000000000077777777000000000000000000000000
0000000000333c0003333c0000333000000aa00000000000000000000000000000000000000000000000000000000000dddddddd000000000000000000000000 0000000000333c0003333c0000333000000aa0000000000000000000000000000000000000000000000000000000000077777777000000000000000000000000
000000000000cc000000cc000000cc000044440000000000000000000000000000000000000000000000000000000000dddddddd000000000000000000000000 000000000000cc000000cc000000cc00004444000000000000000000000000000000000000000000000000000000000077777777000000000000000000000000
0000ee00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011111111000000000000000000000000 0000ee00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000e00e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011111111000000000000000000000000 000e00e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00e0000e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011111111000000000000000000000000 00e0000e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00e0e00e00c0c0c00000000000000000000000000000000000000000000000000000000000000000000000000000000011111111000000000000000000000000 00e0e00e00c0c0c00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00ee00ee00ccccc00000000000000000000000000000000000000000000000000000000000000000000000000000000011111111000000000000000000000000 00ee00ee00ccccc00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000ee00ccccccc0000000000000000000000000000000000000000000000000000000000000000000000000000000011111111000000000000000000000000 00000ee00ccccccc0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00eeee000c00c00c0000000000000000000000000000000000000000000000000000000000000000000000000000000011111111000000000000000000000000 00eeee000c00c00c0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
eeee0000cc0cc0cc0000000000000000000000000000000000000000000000000000000000000000000000000000000011111111000000000000000000000000 eeee0000cc0cc0cc0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000a90000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000a90000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000aaaaaaa91000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000aaaaaaa91000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000aaaaaa1a91100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000aaaaaa1a91100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
@ -1370,14 +1303,14 @@ eeee0000cc0cc0cc0000000000000000000000000000000000000000000000000000000000000000
0000000077a000000000000000000000000000000000000000000000000000000000000000000000000000000000000077777777777777777777777777777777 0000000077a000000000000000000000000000000000000000000000000000000000000000000000000000000000000077777777777777777777777777777777
00000007777a00000000000000000000000000000000000000000000000000000000000000000000000000000000000077777777777777777770077777777777 00000007777a00000000000000000000000000000000000000000000000000000000000000000000000000000000000077777777777777777770077777777777
00044444444444000000000000000000000000000000000000000000000000000000000000000000000000000000000077777777777777777770077777777777 00044444444444000000000000000000000000000000000000000000000000000000000000000000000000000000000077777777777777777770077777777777
77077077777007777707707777700777770770777770077777077077777007777707707777700777770770777770077777077077777007777707707777700777 dd0dd0ddddd00ddddd0dd0ddddd00ddddd0dd0ddddd00ddddd0dd0ddddd00ddddd0dd0ddddd00ddddd0dd0ddddd00ddddd0dd0ddddd00ddddd0dd0ddddd00ddd
77777777777007777777777777700777777777777770077777777777777007777777777777700777777777777770077777777777777007777777777777700777 ddddddddddd00dddddddddddddd00dddddddddddddd00dddddddddddddd00dddddddddddddd00dddddddddddddd00dddddddddddddd00dddddddddddddd00ddd
07777770077777700777777707777777077777700777777007777777077777777777777077777770777777777777777777777770777777707777777777777777 0dddddd00dddddd00ddddddd0ddddddd0dddddd00dddddd00ddddddd0dddddddddddddd0ddddddd0ddddddddddddddddddddddd0ddddddd0dddddddddddddddd
77700777777007777770070077700700777007777770077777700700777007000070077700700777007007000070070000700777007007770070070000700700 ddd00dddddd00dddddd00d00ddd00d00ddd00dddddd00dddddd00d00ddd00d0000d00ddd00d00ddd00d00d0000d00d0000d00ddd00d00ddd00d00d0000d00d00
77700777777007777770070077700700777007777770077777700700777007000070077700700777007007000070070000700777007007770070070000700700 ddd00dddddd00dddddd00d00ddd00d00ddd00dddddd00dddddd00d00ddd00d0000d00ddd00d00ddd00d00d0000d00d0000d00ddd00d00ddd00d00d0000d00d00
07777770077777700777777707777777077777700777777007777777077777777777777077777770777777777777777777777770777777707777777777777777 0dddddd00dddddd00ddddddd0ddddddd0dddddd00dddddd00ddddddd0dddddddddddddd0ddddddd0ddddddddddddddddddddddd0ddddddd0dddddddddddddddd
77777777777777777777777777777777777007777770077777700777777007777777777777777777777777777777777777700777777007777770077777700777 ddddddddddddddddddddddddddddddddddd00dddddd00dddddd00dddddd00dddddddddddddddddddddddddddddddddddddd00dddddd00dddddd00dddddd00ddd
77077077770770777707707777077077777007777770077777700777777007777707707777077077770770777707707777700777777007777770077777700777 dd0dd0dddd0dd0dddd0dd0dddd0dd0ddddd00dddddd00dddddd00dddddd00ddddd0dd0dddd0dd0dddd0dd0dddd0dd0ddddd00dddddd00dddddd00dddddd00ddd
__label__ __label__
77777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777 77777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777
77777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777 77777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777
@ -1515,9 +1448,9 @@ __map__
0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0c000000000044000c0c0c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0c000000000000000c0c0c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0c000000000000000c0c0c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0100000000001c000c0c0c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0c000000000000000c0c0c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
01000000000000000c0c0c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0c000000000000000c0c0c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0c000000000000000c0c0c0c0c0c0c0c0c00000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0c000000000000000c0c0c0c0c0c0c0c0c00000000000020210000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0c000000000000000c0c0c0c0c0c0c0c0c00000000000020210000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0c000000000000000000000c0c0c0c0c0c00000000000030310000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0c000000000000000000000c0c0c0c0c0c00000000000030310000000000000c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000