3 Commits

Author SHA1 Message Date
528e67045d Trimming
Trim up redundant nil checks, sequential assignments that could be on a shared line, and repeated references to a deeply nested variable.
2022-12-23 00:34:00 -08:00
1995501583 Save tokens on movemebnt checks
I promise this is mathematically equivalent-ish to the original. (0.2 and its multiples are nonterminating decimals in base 2, so there's a little jank when the negative shift right is a shift left.)
2022-12-23 00:18:50 -08:00
9d93f30426 Fix crate math.
I forgot that -1 & 1 = 1 rather than 0 so all the bit math didn't work. But I can fix it with polynomial algebra! this is much better.
2022-12-23 00:02:02 -08:00

View File

@ -502,11 +502,7 @@ function level:get_latch(dx,dy,px,py)
local dx1,dy1=-sgn0(dx),-sgn0(dy)
if crate then
if crate.def & (
dy1 >>> 15 |
(dy1 & 0x1) << 2 |
(dx1 & 0x8000) >>> 12 |
(dx1 & 0x1) << 1) ~= 0 then
if crate.def & dy1*dy1*(2.5+1.5*dy1)+dx1*dx1*(5-3*dx1) ~= 0 then
return {
el="crate",
dx=dx1,dy=dy1,
@ -548,12 +544,12 @@ function level:can_move(
if player.rope then
local chk=false
local w,h=1.6,0.2
if (dmx==0) w,h=0.2,1.6
if (dmy==-1) rectx,recty=0.4,-0.8
if (dmy==1) rectx,recty=0.4,0.2
if (dmx==-1) rectx,recty=-0.8,0.4
if (dmx==1) rectx,recty=0.2,0.4
if dmx==0 then
w,h=0.2,1.6
else
dmy = 0
end
rectx,recty=dmx*(0.4>>>dmx),dmy*(0.4>>>dmy)
if (player.rope:collide_mrect(mx0+rectx,my0+recty,w,h,exclude_src,exclude_dst)) return false
end
@ -630,7 +626,7 @@ function player:update()
end
if kbd:btn(4) then
if kbd:btnp(4) and self.rope!=nil then
if kbd:btnp(4) and self.rope then
self.rope:destroy()
kbd:release(4)
end
@ -663,7 +659,7 @@ function player:update()
self.todo={{
update=function()
return self.rope==nil or self.rope:latched()
return not self.rope or self.rope:latched()
end
}}
elseif kbd:btnp(5) then
@ -768,7 +764,7 @@ function player:draw()
if self.rope then
local rx_adj,ry_adj=self.rope:affected_src_xy(rx,ry)
if rx_adj!=nil then
if rx_adj then
local drx,dry=rx_adj-rx,ry_adj-ry
rx,ry=rx+drx,ry+dry
px,py=px+drx,py+dry
@ -836,10 +832,7 @@ function rope:update()
elseif self.state.name=="latched" then
if (self.latch==nil) wrongbleep:bleep(5) self:destroy() return
if
self.latch!=nil and
self.latch.rec!=nil
then
if self.latch and self.latch.rec then
self:drag_src(
self.latch.rec.mx+0.5+self.latch.ax_offset,
self.latch.rec.my+0.5+self.latch.ay_offset
@ -901,11 +894,10 @@ end
function rope:draw(artificial_px,artificial_py)
local points,highlight=self:_tug(true)
if (self.state.name=="done") return
local perc_to_show=1.0
local from_end=false
if (self.state.name=="cast") perc_to_show=self.state.frame/2
if (self.state.name=="destroy") perc_to_show=(1.0-self.state.frame/8)^2
local n,perc_to_show,from_end = self.state.name,1.0,false
if (n=="done") return
if (n=="cast") perc_to_show=self.state.frame/2
if (n=="destroy") perc_to_show=(1.0-self.state.frame/8)^2
if (self.state.reelin) from_end=true
points[#points]={x=artificial_px,y=artificial_py}
@ -1194,7 +1186,7 @@ function rope:be_pushed_by(anchor,ax_old,ay_old)
local ax_new,ay_new=anchor.ax,anchor.ay
while true do
n1=n0.next
if (n1==nil) return
if (not n1) return
local nx0,ny0=n0.ax,n0.ay
local nx1,ny1=n1.ax,n1.ay
@ -1321,7 +1313,7 @@ function _stepfrom(x0,x1)
local done=false
if x0==x1 then
return function()
if (done) return nil
if (done) return
done=true return x0
end
end