catch up to latest developments #10

Merged
kistaro merged 12 commits from pyrex/chameleonic:main into main 2022-12-21 06:50:14 +00:00
Showing only changes of commit b897f748be - Show all commits

View File

@ -117,22 +117,46 @@ end
kbd={} kbd={}
add(real_modules,kbd) add(real_modules,kbd)
function kbd:init() function kbd:init()
self.prev_real=btn() self.real=btn()
self.down=0 self.down=0
end end
function kbd:update() function kbd:update()
local now=btn() -- figure out what keys are _really_ pressed
local pressed=now&~self.prev_real local now_real=btn()
self.down&=now local was_real=self.real
self.down|=pressed self.real=now_real
self.prev_real=now
-- add keys that are really pressed
-- if they weren't really pressed before
-- (they may have been force-
-- released by :release())
local real_pressed=(~was_real)&now_real
local now_down=(self.down&now_real)|real_pressed
local was_down=self.down
self.down=now_down
-- deduce pressed/released by changes in down
local pressed=(~was_down)&now_down
local released=(~now_down)&was_down
self.pressed=pressed
self.released=released
end end
function kbd:btn(i) function kbd:btn(i)
return self.down&(1<<i)!=0 return self.down&(1<<i)!=0
end end
function kbd:btnp(i)
return self.pressed&(1<<i)!=0
end
function kbd:btnr(i)
return self.released&(1<<i)!=0
end
function kbd:release(i) function kbd:release(i)
self.down&=~(1<<i) self.down&=~(1<<i)
end end
@ -624,33 +648,41 @@ function player:update()
end end
if kbd:btn(0) then if kbd:btn(0) then
if level:can_move(true,self.x,self.y,-1,0,0,2) then self.orientx=-1
self.todo=f4({{orientx=-1,orienty=0,px=-2},{px=-7},{x=self.x-1}}) self.orienty=0
else
self.orientx=-1
self.orienty=0
end
elseif kbd:btn(1) then elseif kbd:btn(1) then
if level:can_move(true,self.x,self.y,1,0,0,2) then self.orientx=1
self.todo=f4({{orientx=1,orienty=0,px=2},{px=7},{x=self.x+1}}) self.orienty=0
else
self.orientx=1
self.orienty=0
end
elseif kbd:btn(2) then elseif kbd:btn(2) then
if level:can_move(true,self.x,self.y,0,-1,0,2) then self.orienty=-1
self.todo=f4({{orienty=-1,py=-2},{py=-7},{y=self.y-1}})
else
self.orienty=-1
end
elseif kbd:btn(3) then elseif kbd:btn(3) then
if level:can_move(true,self.x,self.y,0,1,0,2) then self.orienty=1
self.todo=f4({{orienty=1,py=2},{py=7},{y=self.y+1}}) end
else
self.orienty=1 if kbd:btn(4) then
if kbd:btnp(4) and self.rope!=nil then
self.rope:destroy()
kbd:release(4)
end end
elseif kbd:btn(4) then -- wait for user to release it
if self.rope==nil then else
if kbd:btn(0) 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}})
end
elseif kbd:btn(1) 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}})
end
elseif kbd:btn(2) then
if level:can_move(true,self.x,self.y,0,-1,0,2) then
self.todo=f4({{orienty=-1,py=-2},{py=-7},{y=self.y-1}})
end
elseif kbd:btn(3) then
if level:can_move(true,self.x,self.y,0,1,0,2) then
self.todo=f4({{orienty=1,py=2},{py=7},{y=self.y+1}})
end
elseif self.rope==nil and kbd:btnr(4) then
local rx,ry,rx2,ry2=self:_rope_pos() local rx,ry,rx2,ry2=self:_rope_pos()
local dx,dy=12*self.orientx,12*self.orienty local dx,dy=12*self.orientx,12*self.orienty
if (dy!=0) dx=0 if (dy!=0) dx=0
@ -660,19 +692,16 @@ function player:update()
update=function() update=function()
return self.rope==nil or self.rope:latched() return self.rope==nil or self.rope:latched()
end end
},{},{}} }}
else elseif kbd:btnp(5) then
self.rope:tug() if self.rope!=nil then
self.todo={{},{},{}} self.rope:tug()
end end
elseif kbd:btn(5) then
if self.rope!=nil then
self.rope:destroy()
end end
end end
end end
if (self.rope) self.rope:prevent_highlight(#self.todo>0) if (self.rope) self.rope:prevent_highlight(#self.todo>0)
_apply(self,self.todo) _apply(self,self.todo)
if self.rope then if self.rope then
@ -686,9 +715,6 @@ function player:update()
if self.rope:done() then if self.rope:done() then
self.rope=nil self.rope=nil
add(self.todo,{})
add(self.todo,{})
add(self.todo,{})
end end
end end
end end