Save a few more tokens here and there
This commit is contained in:
parent
be864f06bb
commit
70ffbd2465
@ -944,13 +944,7 @@ function rope:update()
|
|||||||
|
|
||||||
elseif self.state.name=="latched" then
|
elseif self.state.name=="latched" then
|
||||||
if (not self.latch) wrongbleep:bleep(5) self:destroy() return
|
if (not self.latch) wrongbleep:bleep(5) self:destroy() return
|
||||||
|
if (self.latch.rec and self.latch.rec.dead) self:destroy()
|
||||||
if self.latch.rec then
|
|
||||||
if self.latch.rec.dead==true then
|
|
||||||
self:destroy()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if (not self:_check_pinch()) self:destroy()
|
if (not self:_check_pinch()) self:destroy()
|
||||||
|
|
||||||
elseif self.state.name=="destroy" then -- destroy
|
elseif self.state.name=="destroy" then -- destroy
|
||||||
@ -979,21 +973,15 @@ function rope:_resegment(points,artificial_pxy,cb)
|
|||||||
for i=1,#points-1 do
|
for i=1,#points-1 do
|
||||||
len+=distance(points[i],points[i+1])
|
len+=distance(points[i],points[i+1])
|
||||||
end
|
end
|
||||||
local len_to_show=perc_to_show*len
|
local len_to_show,ia,iz,istep=perc_to_show*len,#points-1,1,-1
|
||||||
|
if (from_end) ia,iz,istep=iz,ia,1
|
||||||
|
|
||||||
local len_cumulative=0
|
|
||||||
local ia,iz,istep=#points-1,1,-1
|
|
||||||
if (from_end) ia,iz,istep=1,#points-1,1
|
|
||||||
|
|
||||||
local val
|
|
||||||
for i=ia,iz,istep do
|
for i=ia,iz,istep do
|
||||||
local src=points[i]
|
local src,dst=points[i],points[i+1]
|
||||||
local dst=points[i+1]
|
|
||||||
|
|
||||||
local x,y=dst.x,dst.y
|
local x,y=dst.x,dst.y
|
||||||
local dx,dy=src.x-x,src.y-y
|
local dx,dy=src.x-x,src.y-y
|
||||||
|
|
||||||
local dist_base=distance_dxy(dx,dy)
|
local dist_base=sqrt(dx*dx+dy*dy)
|
||||||
|
|
||||||
local coef=min(len_to_show/dist_base,1.0)
|
local coef=min(len_to_show/dist_base,1.0)
|
||||||
len_to_show-=dist_base
|
len_to_show-=dist_base
|
||||||
@ -1015,6 +1003,10 @@ function rope:affected_src_xy(artificial_pxy)
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
TONGUE_SEGS=gsv[[0`0.25`1
|
||||||
|
0.25`0.9`0.5
|
||||||
|
0.9`1`1]]
|
||||||
|
|
||||||
function rope:draw(artificial_pxy)
|
function rope:draw(artificial_pxy)
|
||||||
local points,highlight,hypo_ops,hypo_blocks=self:_tug(true)
|
local points,highlight,hypo_ops,hypo_blocks=self:_tug(true)
|
||||||
|
|
||||||
@ -1026,14 +1018,11 @@ function rope:draw(artificial_pxy)
|
|||||||
self:_resegment(points,artificial_pxy,
|
self:_resegment(points,artificial_pxy,
|
||||||
function(x,y,dx,dy,i)
|
function(x,y,dx,dy,i)
|
||||||
colorh(i)
|
colorh(i)
|
||||||
local function lf(d0,d1,w)
|
foreach(TONGUE_SEGS,function(row)
|
||||||
|
local d0,d1,w=unpack(row)
|
||||||
linefill(x+d0*dx,y+d0*dy,x+d1*dx,y+d1*dy,w)
|
linefill(x+d0*dx,y+d0*dy,x+d1*dx,y+d1*dy,w)
|
||||||
end
|
end)
|
||||||
|
circfill(x+dx,y+dy,1)
|
||||||
lf(0,0.25,1.0)
|
|
||||||
lf(0.25,1,0.5)
|
|
||||||
lf(0.9,1,1.0)
|
|
||||||
circfill(x+dx+0.5,y+dy+0.5,1.0)
|
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -1041,31 +1030,30 @@ function rope:draw(artificial_pxy)
|
|||||||
local l=self.latch
|
local l=self.latch
|
||||||
if l and l.rec and (self.state.reelin or self:latched()) then
|
if l and l.rec and (self.state.reelin or self:latched()) then
|
||||||
local function rfsplit(x) rectfill(unpack(split(x))) end
|
local function rfsplit(x) rectfill(unpack(split(x))) end
|
||||||
local ldx,ldy=l.dx,l.dy
|
|
||||||
colorh(0)
|
colorh(0)
|
||||||
camera(-l.rec.px,-l.rec.py)
|
camera(-l.rec.px,-l.rec.py)
|
||||||
if (ldx==-1) rfsplit"0,3,2,4"
|
if (l.dx==-1) rfsplit"0,3,2,4"
|
||||||
if (ldx==1) rfsplit"5,3,7,4"
|
if (l.dx==1) rfsplit"5,3,7,4"
|
||||||
if (ldy==-1) rfsplit"3,0,4,2"
|
if (l.dy==-1) rfsplit"3,0,4,2"
|
||||||
if (ldy==1) rfsplit"3,5,4,7"
|
if (l.dy==1) rfsplit"3,5,4,7"
|
||||||
camera()
|
camera()
|
||||||
color()
|
color()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- hypothetical
|
-- hypothetical
|
||||||
local time=t()-self.flicker_t
|
local time=t()-self.flicker_t
|
||||||
|
local flicker_on=time%0.5>0.25
|
||||||
if self:latched() and time>0 and not level:busy() then
|
if self:latched() and time>0 and not level:busy() then
|
||||||
if time%0.5>0.25 then
|
if flicker_on then
|
||||||
for o in all(hypo_ops) do
|
foreach(hypo_ops, function(o)
|
||||||
local mx0,my0,dmx,dmy=unpack(o)
|
local mx0,my0,dmx,dmy=unpack(o)
|
||||||
local px1,py1=(mx0+dmx)*8,(my0+dmy)*8
|
spr(14,(mx0+dmx)*8,(my0+dmy)*8)
|
||||||
spr(14,px1,py1)
|
end)
|
||||||
end
|
|
||||||
end
|
end
|
||||||
for o in all(hypo_blocks) do
|
foreach(hypo_blocks, function(o)
|
||||||
local x,y,dx,dy=unpack(o)
|
local x,y,dx,dy=unpack(o)
|
||||||
spr(53,8*x+4*dx,8*y+4*dy,1,1,time%0.5>0.25)
|
spr(53,8*x+4*dx,8*y+4*dy,1,1,flicker_on)
|
||||||
end
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- debug
|
-- debug
|
||||||
@ -1442,10 +1430,6 @@ function _which_side(xy,x0y0,x1y1)
|
|||||||
return sgn0((x1-x0)*(y-y0) - (y1-y0)*(x-x0))
|
return sgn0((x1-x0)*(y-y0) - (y1-y0)*(x-x0))
|
||||||
end
|
end
|
||||||
|
|
||||||
function distance_dxy(dx,dy)
|
|
||||||
return sqrt(dx*dx+dy*dy)
|
|
||||||
end
|
|
||||||
|
|
||||||
function distance(p1,p2)
|
function distance(p1,p2)
|
||||||
local dx=p2.x-p1.x
|
local dx=p2.x-p1.x
|
||||||
local dy=p2.y-p1.y
|
local dy=p2.y-p1.y
|
||||||
|
Loading…
Reference in New Issue
Block a user