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