From 70ffbd246546a6ac6d0f31d4f19ed97427c5c64c Mon Sep 17 00:00:00 2001 From: Nyeogmi Date: Mon, 2 Jan 2023 18:27:36 -0800 Subject: [PATCH] Save a few more tokens here and there --- chameleonic.p8 | 66 +++++++++++++++++++------------------------------- 1 file changed, 25 insertions(+), 41 deletions(-) diff --git a/chameleonic.p8 b/chameleonic.p8 index ed54ac8..2aed388 100644 --- a/chameleonic.p8 +++ b/chameleonic.p8 @@ -944,13 +944,7 @@ function rope:update() elseif self.state.name=="latched" then if (not self.latch) wrongbleep:bleep(5) self:destroy() return - - if self.latch.rec then - if self.latch.rec.dead==true then - self:destroy() - end - end - + if (self.latch.rec and self.latch.rec.dead) self:destroy() if (not self:_check_pinch()) self: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 len+=distance(points[i],points[i+1]) 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 - local src=points[i] - local dst=points[i+1] - + local src,dst=points[i],points[i+1] local x,y=dst.x,dst.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) len_to_show-=dist_base @@ -1015,6 +1003,10 @@ function rope:affected_src_xy(artificial_pxy) ) end +TONGUE_SEGS=gsv[[0`0.25`1 +0.25`0.9`0.5 +0.9`1`1]] + function rope:draw(artificial_pxy) local points,highlight,hypo_ops,hypo_blocks=self:_tug(true) @@ -1026,14 +1018,11 @@ function rope:draw(artificial_pxy) self:_resegment(points,artificial_pxy, function(x,y,dx,dy,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) - end - - 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) + circfill(x+dx,y+dy,1) end ) @@ -1041,31 +1030,30 @@ function rope:draw(artificial_pxy) local l=self.latch if l and l.rec and (self.state.reelin or self:latched()) then local function rfsplit(x) rectfill(unpack(split(x))) end - local ldx,ldy=l.dx,l.dy colorh(0) camera(-l.rec.px,-l.rec.py) - if (ldx==-1) rfsplit"0,3,2,4" - if (ldx==1) rfsplit"5,3,7,4" - if (ldy==-1) rfsplit"3,0,4,2" - if (ldy==1) rfsplit"3,5,4,7" + if (l.dx==-1) rfsplit"0,3,2,4" + if (l.dx==1) rfsplit"5,3,7,4" + if (l.dy==-1) rfsplit"3,0,4,2" + if (l.dy==1) rfsplit"3,5,4,7" camera() color() end -- hypothetical 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 time%0.5>0.25 then - for o in all(hypo_ops) do + if flicker_on then + foreach(hypo_ops, function(o) local mx0,my0,dmx,dmy=unpack(o) - local px1,py1=(mx0+dmx)*8,(my0+dmy)*8 - spr(14,px1,py1) - end + spr(14,(mx0+dmx)*8,(my0+dmy)*8) + end) end - for o in all(hypo_blocks) do + foreach(hypo_blocks, function(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) - end + spr(53,8*x+4*dx,8*y+4*dy,1,1,flicker_on) + end) end -- debug @@ -1442,10 +1430,6 @@ function _which_side(xy,x0y0,x1y1) return sgn0((x1-x0)*(y-y0) - (y1-y0)*(x-x0)) end -function distance_dxy(dx,dy) - return sqrt(dx*dx+dy*dy) -end - function distance(p1,p2) local dx=p2.x-p1.x local dy=p2.y-p1.y