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

@ -106,14 +106,8 @@ function sgn0(x)
end
function _mnmx(x,y)
return min(x,y),max(x,y)
end
-->8
bg={}
add(modules,bg)
function bg:draw0()
cls(0)
if (x>y)return y,x
return x,y
end
-->8
level={}
@ -135,10 +129,15 @@ function level:reinit(n)
self:spawn_exit()
end
function level:restart()
self:reinit(self.ix)
end
function level:advance()
self:reinit(self.ix+1)
end
pitpal = {[0]=1, [7]=0}
function level:draw()
cls(1)
pal(1,0)
@ -150,11 +149,11 @@ function level:draw()
for _,pit in pairs(self._pits) do
spr(pit.s,pit.px,pit.py)
if pit.contents then
pal(7,0)
pal(0,1)
pal(pitpal)
palt(0,false)
spr(pit.contents,pit.px,pit.py)
pal()
pal(1,0)
end
for _,crate in pairs(self._crates) do
spr(crate.s,crate.px,crate.py)
@ -179,7 +178,7 @@ function level:update()
if #crate.todo==0 then
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)
crate.dead=true
pit.contents=crate.s
@ -205,7 +204,7 @@ function level:load_dynobjs()
local px,py=mx*8,my*8
local s=self:_mget(mx,my)
local def=self:_get_cratedef(s)
if def!=nil then
if def then
self._crates[mxy]={
s=s,def=def,
mx=mx,my=my,
@ -228,8 +227,8 @@ end
function level:recollide()
self._coll={}
for mx=0,15,1 do
for my=0,15,1 do
for mx=0,15 do
for my=0,15 do
local mxy=_mix(mx,my)
self._coll[mxy]=
fget(self:_mget(mx,my),7) or
@ -239,16 +238,16 @@ function level:recollide()
end
function level:reanchor(remove)
if remove or self._anch==nil then
if remove or not self._anch then
self._anch={}
end
for ax0=0,31,1 do
for ay0=0,31,1 do
local ax1,ay1=ax0-1+2*(ax0%2),ay0-1+2*(ay0%2)
local mx0,my0=ax0\2,ay0\2
local mx1,my1=ax1\2,ay1\2
for ax0=0,31 do
local ax1 = ax0-1+2*(ax0%2)
local mx0,mx1 = ax0\2,ax1\2
for ay0=0,31 do
local ay1=ay0-1+2*(ay0%2)
local my0,my1=ay0\2,ay1\2
if (
not self:mcoll(mx0,my0) and
@ -421,6 +420,10 @@ function level:can_move(
return false
end
if player.x==mx0+dmx and player.y==my0+dmy then
return false
end
-- todo: check tongue collision
if player.rope then
local px,py=mx0*8,my0*8
@ -471,6 +474,10 @@ add(modules,player)
function player:init()
--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
function player:reinit(x,y)
@ -481,6 +488,7 @@ function player:reinit(x,y)
self.todo={}
self.fall_frame=0
self.reset_frame=0
self.orientx=-1
self.orienty=0
@ -509,6 +517,10 @@ function player:update()
return xs
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 level:win_at(self.x,self.y) then
level:advance()
@ -575,6 +587,10 @@ function player:update()
local rx,ry=self:_rope_pos()
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
self.rope=nil
add(self.todo,{})
@ -584,10 +600,32 @@ function player:update()
end
end
function player:_fall()
if self.fall_frame<10 then
self.fall_frame+=1
function player:_vanish_if_requested()
local bvan=btn(❎)
if self.bvan and not bvan then
self.vanishing=false
elseif not self.bvan and bvan then
self.vanishing=true
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
function player:_rope_pos()
@ -609,21 +647,52 @@ function player:draw()
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 (invis_level>=1.0) return
if (self.fall_frame>0) then
--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
if self.orientx==-1 then
setpal()
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)
if (self.rope and invis_level<=0.25) pal() self.rope:draw() setpal()
spr(head,px-3,py-3,1,1)
else
setpal()
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)
if (self.rope and invis_level<=0.25) pal() self.rope:draw() setpal()
spr(head,px+3,py-3,1,1,true)
end
pal()
@ -1148,6 +1217,23 @@ end
-->8
-- 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()
self:_make_consistent()
if (self.under_destruction) return
@ -1338,22 +1424,22 @@ end
__gfx__
000000000003000000000033000300000000000000000000000000000000000000000000000000000000000000000000dddddddd000000000000000000000000
000000000333330000003333033333000aa00aa000000000000000000000000000000000000000000000000000000000dddddddd000000000000000000000000
000000009933399000399330933333900aaaaaa000000000000000000000000000000000000000000000000000000000dddddddd000000000000000000000000
000000009a333a90033a9330933333900aaaaaa000000000000000000000000000000000000000000000000000000000dddddddd000000000000000000000000
000000003333333033333300033333000099990000000000000000000000000000000000000000000000000000000000dddddddd000000000000000000000000
0000000003333300000033000333330000aaaa0000000000000000000000000000000000000000000000000000000000dddddddd000000000000000000000000
0000000000333c0003333c0000333000000aa00000000000000000000000000000000000000000000000000000000000dddddddd000000000000000000000000
000000000000cc000000cc000000cc000044440000000000000000000000000000000000000000000000000000000000dddddddd000000000000000000000000
0000ee00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011111111000000000000000000000000
000e00e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011111111000000000000000000000000
00e0000e000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011111111000000000000000000000000
00e0e00e00c0c0c00000000000000000000000000000000000000000000000000000000000000000000000000000000011111111000000000000000000000000
00ee00ee00ccccc00000000000000000000000000000000000000000000000000000000000000000000000000000000011111111000000000000000000000000
00000ee00ccccccc0000000000000000000000000000000000000000000000000000000000000000000000000000000011111111000000000000000000000000
00eeee000c00c00c0000000000000000000000000000000000000000000000000000000000000000000000000000000011111111000000000000000000000000
eeee0000cc0cc0cc0000000000000000000000000000000000000000000000000000000000000000000000000000000011111111000000000000000000000000
000000000000300000000022000030000000000000000000000000000000000000000000000000000000000000000000dddddddd000000000000000000000000
000000000033333000003322003333300aa00aa000000000000000000000000000000000000000000000000000000000dddddddd000000000000000000000000
000000000993339900399320093333390aaaaaa000000000000000000000000000000000000000000000000000000000dddddddd000000000000000000000000
0000000009a333a9033a9320093333390aaaaaa000000000000000000000000000000000000000000000000000000000dddddddd000000000000000000000000
000000000233333233333200002222200099990000000000000000000000000000000000000000000000000000000000dddddddd000000000000000000000000
0000000000222220000022000022222000aaaa0000000000000000000000000000000000000000000000000000000000dddddddd000000000000000000000000
00000000000222c002222c0000022200000aa00000000000000000000000000000000000000000000000000000000000dddddddd000000000000000000000000
0000000000000cc00000cc0000000cc00044440000000000000000000000000000000000000000000000000000000000dddddddd000000000000000000000000
0000ff00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011111111000000000000000000000000
000f00f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011111111000000000000000000000000
00d0000f000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011111111000000000000000000000000
00d0d00f00c040500000000000000000000000000000000000000000000000000000000000000000000000000000000011111111000000000000000000000000
00dd00ee00c445500000000000000000000000000000000000000000000000000000000000000000000000000000000011111111000000000000000000000000
00000ee00c4445550000000000000000000000000000000000000000000000000000000000000000000000000000000011111111000000000000000000000000
00eeee000c0040050000000000000000000000000000000000000000000000000000000000000000000000000000000011111111000000000000000000000000
eeee0000cc0440550000000000000000000000000000000000000000000000000000000000000000000000000000000011111111000000000000000000000000
00000000000a90000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
00000aaaaaaa91000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0000aaaaaa1a91100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000