pull changes from upstream #4

Merged
kistaro merged 5 commits from pyrex/chameleonic:main into main 2022-12-18 01:39:00 +00:00

View File

@ -101,19 +101,13 @@ function _apply(x,ts,a)
end end
function sgn0(x) function sgn0(x)
if (x==0) return x if (x==0) return x
return sgn(x) return sgn(x)
end end
function _mnmx(x,y) function _mnmx(x,y)
return min(x,y),max(x,y) if (x>y)return y,x
end return x,y
-->8
bg={}
add(modules,bg)
function bg:draw0()
cls(0)
end end
-->8 -->8
level={} level={}
@ -135,10 +129,15 @@ function level:reinit(n)
self:spawn_exit() self:spawn_exit()
end end
function level:restart()
self:reinit(self.ix)
end
function level:advance() function level:advance()
self:reinit(self.ix+1) self:reinit(self.ix+1)
end end
pitpal = {[0]=1, [7]=0}
function level:draw() function level:draw()
cls(1) cls(1)
pal(1,0) pal(1,0)
@ -150,11 +149,11 @@ function level:draw()
for _,pit in pairs(self._pits) do for _,pit in pairs(self._pits) do
spr(pit.s,pit.px,pit.py) spr(pit.s,pit.px,pit.py)
if pit.contents then if pit.contents then
pal(7,0) pal(pitpal)
pal(0,1)
palt(0,false) palt(0,false)
spr(pit.contents,pit.px,pit.py) spr(pit.contents,pit.px,pit.py)
pal() pal()
pal(1,0)
end 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)
@ -179,7 +178,7 @@ function level:update()
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!=nil and pit.contents==nil then if pit and not pit.contents then
add(remove,cix) add(remove,cix)
crate.dead=true crate.dead=true
pit.contents=crate.s pit.contents=crate.s
@ -205,7 +204,7 @@ function level:load_dynobjs()
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)
if def!=nil then if def then
self._crates[mxy]={ self._crates[mxy]={
s=s,def=def, s=s,def=def,
mx=mx,my=my, mx=mx,my=my,
@ -228,8 +227,8 @@ end
function level:recollide() function level:recollide()
self._coll={} self._coll={}
for mx=0,15,1 do for mx=0,15 do
for my=0,15,1 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
@ -239,16 +238,16 @@ function level:recollide()
end end
function level:reanchor(remove) function level:reanchor(remove)
if remove or self._anch==nil then if remove or not self._anch then
self._anch={} self._anch={}
end end
for ax0=0,31,1 do for ax0=0,31 do
for ay0=0,31,1 do local ax1 = ax0-1+2*(ax0%2)
local ax1,ay1=ax0-1+2*(ax0%2),ay0-1+2*(ay0%2) local mx0,mx1 = ax0\2,ax1\2
for ay0=0,31 do
local mx0,my0=ax0\2,ay0\2 local ay1=ay0-1+2*(ay0%2)
local mx1,my1=ax1\2,ay1\2 local my0,my1=ay0\2,ay1\2
if ( if (
not self:mcoll(mx0,my0) and not self:mcoll(mx0,my0) and
@ -420,6 +419,10 @@ function level:can_move(
if self:mcoll(mx0+dmx,my0+dmy) then if self:mcoll(mx0+dmx,my0+dmy) then
return false return false
end end
if player.x==mx0+dmx and player.y==my0+dmy then
return false
end
-- todo: check tongue collision -- todo: check tongue collision
if player.rope then if player.rope then
@ -471,6 +474,10 @@ add(modules,player)
function player:init() function player:init()
--self:reinit(8,14) --self:reinit(8,14)
-- don't change this on reinit:
-- it stays the same when the level is changed or reloaded
self.vanish_frame=0
end end
function player:reinit(x,y) function player:reinit(x,y)
@ -481,6 +488,7 @@ function player:reinit(x,y)
self.todo={} self.todo={}
self.fall_frame=0 self.fall_frame=0
self.reset_frame=0
self.orientx=-1 self.orientx=-1
self.orienty=0 self.orienty=0
@ -509,6 +517,10 @@ function player:update()
return xs return xs
end end
-- this is a non-gameplay action that takes precedence over
-- all gameplay actions
self:_vanish_if_requested()
if not self:any_busy() then if not self:any_busy() then
if level:win_at(self.x,self.y) then if level:win_at(self.x,self.y) then
level:advance() level:advance()
@ -575,6 +587,10 @@ function player:update()
local rx,ry=self:_rope_pos() local rx,ry=self:_rope_pos()
self.rope:drag_dst(rx,ry) self.rope:drag_dst(rx,ry)
local tdx,tdy=self.rope:tug_orientxy()
if (tdx!=0) self.orientx=tdx
if (tdy!=0) self.orienty=tdy
if self.rope:done() then if self.rope:done() then
self.rope=nil self.rope=nil
add(self.todo,{}) add(self.todo,{})
@ -584,10 +600,32 @@ function player:update()
end end
end end
function player:_fall() function player:_vanish_if_requested()
if self.fall_frame<10 then local bvan=btn(❎)
self.fall_frame+=1 if self.bvan and not bvan then
self.vanishing=false
elseif not self.bvan and bvan then
self.vanishing=true
end end
self.bvan=bvan
if self.vanishing then
self.vanish_frame+=1
if (self.fall_frame>0 or self.vanish_frame>20) then
level:restart()
self.vanish_frame=20
self.vanishing=false
end
else
self.vanish_frame-=1
end
self.vanish_frame=max(self.vanish_frame,0)
end
function player:_fall()
if (self.fall_frame<10) self.fall_frame+=1
end end
function player:_rope_pos() function player:_rope_pos()
@ -609,21 +647,52 @@ function player:draw()
local head=2-self.orienty local head=2-self.orienty
if (self.fall_frame>5) return local vanish_level=self.vanish_frame/20
local invis_level=max(self.fall_frame/10,4*(vanish_level-0.75))
if (self.fall_frame>0) then if (invis_level>=1.0) return
for i=0,15 do pal(i,1) end
--px+=sin(vanish_level*16)*max(vanish_level-0.1,0)*1
local HEAD=14--3
local BODY=12--12
local TAIL=14--14
local IRIS=7--9
local PUPIL=0--0
local setpal=function()
-- base colors
pal(13,TAIL)
pal(14,TAIL)
pal(15,TAIL)
pal(4,BODY)
pal(5,BODY)
pal(12,BODY)
pal(2,HEAD)
pal(3,HEAD)
pal(9,IRIS)
pal(10,PUPIL)
-- vanish colors
local vanish=split"13,15,14,5,4,12,2,3,9,10"
for i,ilc in ipairs(vanish) do
if (vanish_level>i/#vanish) pal(ilc,1)
end
if self.fall_frame>3 then
for i=0,15 do pal(i,1) end
end
end end
if self.orientx==-1 then if self.orientx==-1 then
setpal()
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()
spr(17,px+1,py,1,1) spr(17,px+1,py,1,1)
if (self.rope and invis_level<=0.25) pal() self.rope:draw() setpal()
spr(head,px-3,py-3,1,1) spr(head,px-3,py-3,1,1)
else else
setpal()
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()
spr(17,px-1,py,1,1,true) spr(17,px-1,py,1,1,true)
if (self.rope and invis_level<=0.25) pal() self.rope:draw() setpal()
spr(head,px+3,py-3,1,1,true) spr(head,px+3,py-3,1,1,true)
end end
pal() pal()
@ -1148,6 +1217,23 @@ end
-->8 -->8
-- moved here because it's complicated -- moved here because it's complicated
function rope:tug_orientxy()
local a1=self:_anc(#self.ancs+1)
local a0=self:_anc(#self.ancs)
local dx=a0.x-a1.x
local tdx=0
if (dx>3) tdx=1
if (dx<-3) tdx=-1
local dy=a0.y-a1.y
local tdy=0
if abs(dy)>abs(dx)/2 then
if (dy>3) tdy=1
if (dy<-3) tdy=-1
end
return tdx,tdy
end
function rope:tug() function rope:tug()
self:_make_consistent() self:_make_consistent()
if (self.under_destruction) return if (self.under_destruction) return
@ -1338,22 +1424,22 @@ end
__gfx__ __gfx__
000000000003000000000033000300000000000000000000000000000000000000000000000000000000000000000000dddddddd000000000000000000000000 000000000000300000000022000030000000000000000000000000000000000000000000000000000000000000000000dddddddd000000000000000000000000
000000000333330000003333033333000aa00aa000000000000000000000000000000000000000000000000000000000dddddddd000000000000000000000000 000000000033333000003322003333300aa00aa000000000000000000000000000000000000000000000000000000000dddddddd000000000000000000000000
000000009933399000399330933333900aaaaaa000000000000000000000000000000000000000000000000000000000dddddddd000000000000000000000000 000000000993339900399320093333390aaaaaa000000000000000000000000000000000000000000000000000000000dddddddd000000000000000000000000
000000009a333a90033a9330933333900aaaaaa000000000000000000000000000000000000000000000000000000000dddddddd000000000000000000000000 0000000009a333a9033a9320093333390aaaaaa000000000000000000000000000000000000000000000000000000000dddddddd000000000000000000000000
000000003333333033333300033333000099990000000000000000000000000000000000000000000000000000000000dddddddd000000000000000000000000 000000000233333233333200002222200099990000000000000000000000000000000000000000000000000000000000dddddddd000000000000000000000000
0000000003333300000033000333330000aaaa0000000000000000000000000000000000000000000000000000000000dddddddd000000000000000000000000 0000000000222220000022000022222000aaaa0000000000000000000000000000000000000000000000000000000000dddddddd000000000000000000000000
0000000000333c0003333c0000333000000aa00000000000000000000000000000000000000000000000000000000000dddddddd000000000000000000000000 00000000000222c002222c0000022200000aa00000000000000000000000000000000000000000000000000000000000dddddddd000000000000000000000000
000000000000cc000000cc000000cc000044440000000000000000000000000000000000000000000000000000000000dddddddd000000000000000000000000 0000000000000cc00000cc0000000cc00044440000000000000000000000000000000000000000000000000000000000dddddddd000000000000000000000000
0000ee00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011111111000000000000000000000000 0000ff00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011111111000000000000000000000000
000e00e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011111111000000000000000000000000 000f00f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011111111000000000000000000000000
00e0000e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011111111000000000000000000000000 00d0000f000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011111111000000000000000000000000
00e0e00e00c0c0c00000000000000000000000000000000000000000000000000000000000000000000000000000000011111111000000000000000000000000 00d0d00f00c040500000000000000000000000000000000000000000000000000000000000000000000000000000000011111111000000000000000000000000
00ee00ee00ccccc00000000000000000000000000000000000000000000000000000000000000000000000000000000011111111000000000000000000000000 00dd00ee00c445500000000000000000000000000000000000000000000000000000000000000000000000000000000011111111000000000000000000000000
00000ee00ccccccc0000000000000000000000000000000000000000000000000000000000000000000000000000000011111111000000000000000000000000 00000ee00c4445550000000000000000000000000000000000000000000000000000000000000000000000000000000011111111000000000000000000000000
00eeee000c00c00c0000000000000000000000000000000000000000000000000000000000000000000000000000000011111111000000000000000000000000 00eeee000c0040050000000000000000000000000000000000000000000000000000000000000000000000000000000011111111000000000000000000000000
eeee0000cc0cc0cc0000000000000000000000000000000000000000000000000000000000000000000000000000000011111111000000000000000000000000 eeee0000cc0440550000000000000000000000000000000000000000000000000000000000000000000000000000000011111111000000000000000000000000
00000000000a90000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000000000a90000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000aaaaaaa91000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 00000aaaaaaa91000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000aaaaaa1a91100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 0000aaaaaa1a91100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000