Compare commits

..

16 Commits

Author SHA1 Message Date
dc33b46260 Misc golf and perf improvements 2022-12-31 15:07:23 -08:00
fa5c13eb0d Golf would_stick a bit 2022-12-31 14:48:24 -08:00
bef28a8d87 Fix misc rope bugs 2022-12-31 14:44:24 -08:00
cc6efb5e61 Re-refactor 1 2022-12-31 14:05:22 -08:00
08fa3cd46e Use bit math to keep player from leaving the map 2022-12-30 23:38:08 -08:00
ba14cc18f2 Remove unnecessary nils and falses 2022-12-30 23:30:05 -08:00
4987e71deb Shorten rope drawing code 2022-12-30 23:09:38 -08:00
95e5b3d0bf Shorten latch code 2022-12-30 23:04:27 -08:00
3f7f96a520 On reinit, take away the player's rope 2022-12-30 22:47:36 -08:00
59774303e4 Fix restart anim 2022-12-30 22:45:34 -08:00
003c6b5dc3 Rope timing fixes 2022-12-30 22:45:12 -08:00
37283c146d Fix an edge case in snappy controls 2022-12-30 22:41:08 -08:00
87219678ef Snappier controls 2022-12-30 22:39:15 -08:00
7c3cd44b9a Default level 0 2022-12-30 22:28:42 -08:00
0534e8df79 Crate-pushing puzzle before The Pivot 2022-12-30 21:09:01 -08:00
5955cf1695 Mirror two stages 2022-12-30 20:01:03 -08:00

View File

@ -117,7 +117,7 @@ function _rast(
if (x0<x1) sx=1
if (y0<y1) sy=1
local done=false,err
local done,err
if dx>dy then
err=dx/2.0
while x0!=x1 do
@ -207,7 +207,7 @@ function title:draw()
print(lvlstr,51,90,blinkcol)
end
start_level=11
start_level=0
max_level=31
function title:update()
@ -234,10 +234,10 @@ function level:reinit(n)
self.ix=n
self.todo={}
self.bigx,self.bigy=n%8,n\8
self.dirty=false
self:load_dynobjs()
self:recollide()
self:reanchor(true)
self:recollide_reanchor()
self:spawn_exit()
end
@ -252,8 +252,7 @@ end
normpal = {[1]=0,[8]=0,[14]=0}
pitpal = {[8]=0,[13]=3,[4]=3,[7]=3}
function level:draw()
fillp(0b1111111110111111)
rectfill(0,0,127,127,0x55)
cls(5)
fillp()
pal(normpal)
map(
@ -289,7 +288,7 @@ function level:busy()
for _,crate in pairs(self._crates) do
if (#crate.todo>0) return true
end
return false
return
end
function level:update()
@ -310,10 +309,12 @@ function level:update()
end
for cix in all(remove) do
self._crates[cix]=nil
self.dirty=true
end
if #remove>0 then
self:recollide()
self:reanchor()
if self.dirty then
self:recollide_reanchor()
self.dirty=false
end
end
@ -345,19 +346,17 @@ function level:load_dynobjs()
end
end
function level:recollide()
function level:recollide_reanchor()
self._coll={}
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
self._crates[mxy]!=nil
self._crates[mxy]
end
end
end
function level:reanchor()
local anch_new={}
for dxy in all{{-1,-1},{1,-1},{-1,1},{1,1}} do
local dx,dy=unpack(dxy)
@ -390,18 +389,12 @@ function level:reanchor()
end
end
local anch_old=self._anch
if (anch_old==nil) anch_old={}
for _,old in pairs(anch_old) do
old.dropped=true
end
local moves={}
for k,new in pairs(anch_new) do
local old=anch_old[k]
local old=(self._anch or {})[k]
if old then
anch_new[k]=old
old.ax_old,old.ay_old,old.ax,old.ay,old.adx,old.ady=old.ax,old.ay,new.ax,new.ay,new.adx,new.ady
old.dropped=nil
anch_new[k]=new
if (old.ax!=new.ax or old.ay!=new.ay) add(moves,{old.ax,old.ay,new.ax,new.ay,old,key=k})
end
end
self._anch=anch_new
@ -410,15 +403,16 @@ function level:reanchor()
add(self._anch_keys,{key=k})
end
shellsort(self._anch_keys)
for point in self:anchor_points() do
if point.ax_old and player.rope and (point.ax_old != point.ax or point.ay_old != point.ay) then
-- printh("moving: "..tostring({point.ax_old,point.ay_old}).."=>"..tostring({point.ax,point.ay}))
player.rope:be_pushed_by(point,point.ax_old,point.ay_old)
end
point.ax_old,point.ay_old=nil,nil
shellsort(moves)
--printh("!!STARTING!!")
if player.rope then
player.rope:experience_anchor_moves(moves)
end
if (player.rope) player.rope:relax()
for point in self:anchor_points() do
point.moved=nil
end
end
function level:win_at(mx,my)
@ -426,22 +420,28 @@ function level:win_at(mx,my)
end
function level:anchor_points()
keys=all(self._anch_keys)
-- TODO: Return this to using all()
local keys=all(self._anch_keys)
return function()
local k=keys()
if (k==nil) return nil
return self._anch[k.key]
if (k) return self._anch[k.key]
end
end
function level:anchor_at(ax,ay)
for i in self:anchor_points() do
if (i.ax==ax and i.ay==ay) return i
end
end
function level:get_open_pit(mx,my)
local pit=self._pits[_mix(mx,my)]
if (pit and pit.contents==nil) return pit
if (pit and not pit.contents) return pit
end
function level:spawn_exit()
self._wins={}
local spawned=false
local spawned
local spawn_at=function(x,y)
if (self:_mget(x,y)!=1) return
assert(not spawned,x..","..y)
@ -470,11 +470,8 @@ function level:spawn_exit()
end
function level:mcoll(mx,my)
return self._coll[_mix(mx,my)]!=false
end
function level:pcoll(px,py)
return self:mcoll(px\8,py\8)
if ((mx | my) & 0xFFF0!=0) return true
return self._coll[_mix(mx,my)]
end
function level:get_crate(mx,my)
@ -557,12 +554,12 @@ function level:can_move(
if (is_player and self:win_at(mx1,my1)) return true
if (is_player and self:get_open_pit(mx1,my1)) return wrongbleep:adequately_warned()
if (self:mcoll(mx1,my1) or player.x==mx1 and player.y==my1) return false
if (self:mcoll(mx1,my1) or player.x==mx1 and player.y==my1) return
if player.rope then
local w,h=1.2,0.2
if (dmx==0) w,h=0.2,1.2
if (player.rope:collide_mrect(mx0+ropecheck[dmx+2],my0+ropecheck[dmy+2],w,h,exclude_src,exclude_dst)) return false
if (player.rope:collide_mrect(mx0+ropecheck[dmx+2],my0+ropecheck[dmy+2],w,h,exclude_src,exclude_dst)) return
end
return true
@ -578,8 +575,7 @@ function level:tug_crate(mx0,my0,dmx,dmy)
local px1,py1=mx1*8,my1*8
existing.todo={
{px=px1+dmx,py=py1+dmy,mx=mx1,my=my1,update=function()
self:recollide()
self:reanchor()
self.dirty=true
return true
end},
{px=px1,py=py1}
@ -603,6 +599,8 @@ function player:reinit(x,y)
self.x,self.y=x,y
self.px,self.py=0,0
self.todo={}
self.cooldown=4
self.rope=nil -- don't elide, needs to be cleared if present
self.fall_frame=0
@ -636,6 +634,10 @@ function player:update()
self.orienty=1
end
function btncd(x)
return (kbd:btn(x) and self.cooldown==0) or kbd:btnp(x)
end
if kbd:btn(4) then
if kbd:btnp(4) and self.rope then
self.rope:destroy()
@ -643,23 +645,30 @@ function player:update()
end
-- wait for user to release it
else
local x,y=self.x,self.y
local function try_move(dx,dy,f)
if (level:can_move(true,self.x,self.y,dx,dy,0,2)) self.todo=f return
if level:can_move(true,x,y,dx,dy,0,2) then
self.todo=f
self.cooldown=3
local t=f[#f]
t.x=x+dx
t.y=y+dy
return
end
wrongbleep:bleep()
end
if kbd:btn(0) then
try_move(-1,0,{{orientx=-1,orienty=0,px=-2},{px=-7},{x=self.x-1,px=0}})
elseif kbd:btn(1) then
try_move(1,0,{{orientx=1,orienty=0,px=2},{px=7},{x=self.x+1,px=0}})
elseif kbd:btn(2) then
try_move(0,-1,{{orienty=-1,py=-2},{py=-7},{y=self.y-1,py=0}})
elseif kbd:btn(3) then
try_move(0,1,{{orienty=1,py=2},{py=7},{y=self.y+1,py=0}})
if btncd(0) then
try_move(-1,0,{{orientx=-1,orienty=0,px=-2,py=0},{px=1}})
elseif btncd(1) then
try_move(1,0,{{orientx=1,orienty=0,px=2,py=0},{px=-1}})
elseif btncd(2) then
try_move(0,-1,{{orienty=-1,px=0,py=-2},{py=1}})
elseif btncd(3) then
try_move(0,1,{{orienty=1,px=0,py=2},{py=-1}})
elseif not self.rope and kbd:btnr(4) then
local dx,dy=self.orientx,self.orienty
if (dy!=0) dx=0
local x,y=self.x,self.y
while not level:mcoll(x,y) do x+=dx y+=dy end
self.rope=rope:new(
@ -679,7 +688,9 @@ function player:update()
end
end
if (#self.todo==0) self.px=0 self.py=0
_apply(self,self.todo)
if (self.cooldown>0) self.cooldown-=1
if self.rope then
self.rope:update()
@ -764,7 +775,7 @@ function player:draw()
-- 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)
if (vanish_level>i/#vanish) pal(ilc,5)
end
if (self.fall_frame>3) local zc=@0x5f00&0xf0 for i=0x5f00,0x5f0c,4 do poke4(i,0x0101.0101) end poke(0x5f00,zc|0x01)
@ -841,9 +852,9 @@ function rope:update()
if (self.state.frame>=3) self.state={name="latched"}
elseif self.state.name=="latched" then
if (self.latch==nil) wrongbleep:bleep(5) self:destroy() return
if (not self.latch) wrongbleep:bleep(5) self:destroy() return
if self.latch and self.latch.rec then
if 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
@ -858,7 +869,7 @@ function rope:update()
elseif self.state.name=="destroy" then -- destroy
self.state.frame+=1
if (self.state.frame>=5) self.state={name="done",reelin=self.state.reelin}
if (self.state.frame>=4) self.state={name="done",reelin=self.state.reelin}
else
-- done state
end
@ -905,10 +916,10 @@ end
function rope:draw(artificial_px,artificial_py)
local points,highlight=self:_tug(true)
local n,perc_to_show,from_end = self.state.name,1.0,false
local n,perc_to_show,from_end = self.state.name,1.0
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 (n=="destroy") perc_to_show=(1.0-self.state.frame/4)^2
if (self.state.reelin) from_end=true
points[#points]={x=artificial_px,y=artificial_py}
@ -922,6 +933,11 @@ function rope:draw(artificial_px,artificial_py)
local len_cumulative=0
local ia,iz,istep=#points-1,1,-1
if (from_end) ia,iz,istep=1,#points-1,1
local function colorh(ix)
color(8)
if (highlight==ix) color(12)
end
for i=ia,iz,istep do
local src=points[i]
local dst=points[i+1]
@ -938,36 +954,35 @@ function rope:draw(artificial_px,artificial_py)
if from_end then
x,y=x+dx-dx*coef,y+dy-dy*coef
dx,dy=dx*coef,dy*coef
else
dx,dy=dx*coef,dy*coef
end
dx,dy=dx*coef,dy*coef
colorh(i)
local function lf(d0,d1,w)
linefill(x+d0*dx,y+d0*dy,x+d1*dx,y+d1*dy,w)
end
local color=8
if (highlight==i) color=12
linefill(x,y,x+0.25*dx,y+0.25*dy,1.0,color)
linefill(x+0.25*dx,y+0.25*dy,x+1*dx,y+1*dy,0.5,color)
linefill(x+0.9*dx,y+0.9*dy,x+dx,y+dy,1.0,color)
circfill(x+dx+0.5,y+dy+0.5,1.0,color)
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
-- draw latch
if self.latch!=nil and self.latch.rec and (perc_to_show>=1.0 or from_end) then
local x,y=self.latch.rec.px,self.latch.rec.py
local ldx,ldy=self.latch.dx,self.latch.dy
local color=8
if (highlight==0) color=12
if self.latch.dx==-1 and self.latch.dy==0 then
rectfill(x,y+3,x+2,y+4,color)
elseif self.latch.dx==1 and self.latch.dy==0 then
rectfill(x+5,y+3,x+7,y+4,color)
elseif self.latch.dx==0 and self.latch.dy==-1 then
rectfill(x+3,y,x+4,y+2,color)
elseif self.latch.dx==0 and self.latch.dy==1 then
rectfill(x+3,y+5,x+4,y+7,color)
end
local l=self.latch
if l and l.rec and (perc_to_show>=1.0 or from_end) 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"
camera()
color()
end
-- debug
@ -976,31 +991,26 @@ function rope:draw(artificial_px,artificial_py)
local sy=0
while true do
if (n1==nil) break
local anch=level:anchor_at(n1.ax,n1.ay)
local x=n1.ax*8
local y=n1.ay*8
if n1.associated_with then
if (n1.associated_with.adx>0) x-=1
if (n1.associated_with.ady>0) y-=1
if anch then
if (anch.adx>0) x-=1
if (anch.ady>0) y-=1
end
rectfill(x-1,y-1,x+1,y+1,12)
print("ax="..n1.ax..",ay="..n1.ay,72,sy)
print(tostring(n1.associated_with and (not n1.associated_with.dropped and n1.associated_with.ax==n1.ax and n1.associated_with.ay==n1.ay)),76,sy+7)
sy+=14
sy+=7
local n0=n1.prev
local n2=n1.next
if n0!=nil and n2!=nil then
if n1.associated_with then
local _,_,_,adx,ady=would_stick(n0.ax,n0.ay,n1.associated_with,n2.ax,n2.ay)
assert(adx==-1 or adx==0 or adx==1)
assert(ady==-1 or ady==0 or ady==1)
--assert(not (adx==0 and ady==0))
if anch then
local _,_,_=would_stick(anch,n0.ax,n0.ay,n1.ax,n1.ay,n2.ax,n2.ay)
local c=3
if (n1.associated_with.dropped) c=4
if (anch.dropped) c=4
rectfill(x+2,y+2,x+4,y+4,c)
pset(x+adx*2,y,9)
pset(x,y+ady*2,9)
else
rectfill(x+2,y+2,x+4,y+4,2)
end
@ -1019,7 +1029,7 @@ function rope:draw(artificial_px,artificial_py)
pset(x+p.adx,y,11)
pset(x,y+p.ady,11)
end
]]
]]
end
function rope:drag_dst(x,y)
@ -1038,66 +1048,42 @@ function rope:drag(n1,ax_new,ay_new)
end
function rope:relax()
local n0=self.src
while true do
if (n0==nil) break
if n0.associated_with and n0.associated_with.dropped then
for i in level:anchor_points() do
if i.ax==n0.ax and i.ay==n0.ay then
n0.associated_with=i
break
end
end
end
n0=n0.next
end
local n0=self.src
while true do
local n1=n0.next
if (n1==nil) break
if (not n1) break
local n2=n1.next
if n0.ax==n1.ax and n0.ay==n1.ay then
n0.next=n2
if (n2!=nil) n2.prev=n0
if (n2) n2.prev=n0
else
n0=n0.next
end
end
local n0=self.src
while true do
if (n0==nil) return
while n0 do
local n1=n0.next
if (n1==nil) return
if (not n1) return
local n2=n1.next
if (n2==nil) return
if (not n2) return
if n1.associated_with!=nil then
local x0,y0=n0.ax,n0.ay
local x1,y1=n1.ax,n1.ay
local x2,y2=n2.ax,n2.ay
local x0,y0=n0.ax,n0.ay
local x1,y1=n1.ax,n1.ay
local x2,y2=n2.ax,n2.ay
if x1!=n1.associated_with.ax or y1!=n1.associated_with.ay then
-- printh("dragging home: "..tostring{n1.ax,n1.ay}.."->"..tostring(n1.associated_with))
self:_drag(n1,n1.associated_with.ax,n1.associated_with.ay)
end
local would,x1_new,y1_new=would_stick(x0,y0,n1.associated_with,x2,y2)
if not would and not (n1.ax==x1_new and n1.ay==y1_new) then
-- printh("dragging: "..tostring{n1.associated_with, {x1_new, y1_new}})
-- printh("relaxing: "..tostring(n0.associated_with).."->"..tostring(n1.associated_with).."->"..tostring(n2.associated_with))
self:_drag(n1,x1_new,y1_new,n1.ax,n1.ay)
n0=n1.prev
n2=n1.next
n0.next=n2
n2.prev=n0
n1.next=nil
n1.prev=nil
else n0=n0.next end
local anch=level:anchor_at(n1.ax,n1.ay)
local would,x1_new,y1_new=would_stick(anch,x0,y0,x1,y1,x2,y2)
if not would and not (n1.ax==x1_new and n1.ay==y1_new) then
self:_drag(n1,x1_new,y1_new,n1.ax,n1.ay)
n0=n1.prev
n2=n1.next
n0.next=n2
n2.prev=n0
n1.next=nil
n1.prev=nil
else n0=n0.next end
end
end
@ -1111,7 +1097,7 @@ function rope:_check_sane()
local qxs,qys={},{}
while true do
local n1=n0.next
if (n1==nil) break
if (not n1) break
_rast(qxs,qys,flr(n0.ax*2),flr(n0.ay*2),flr(n1.ax*2),flr(n1.ay*2))
n0=n1
@ -1133,21 +1119,21 @@ function rope:_check_sane()
end
local function _blocked(qx,qy)
for i in all(_possible_tiles(qx,qy)) do
if (not level:mcoll(i.mx,i.my)) return false
if (not level:mcoll(i.mx,i.my)) return
end
return true
end
-- find cases where i move through an impassable zone
for i=1,#qxs do
if (_blocked(qxs[i],qys[i])) return false
if (_blocked(qxs[i],qys[i])) return
end
-- find cases where i am cut off diagonally
for i=3,#qxs do
local qx1,qy1=qxs[i-1],qys[i-1]
if qx1%2==0 and qy1%2==0 then
local ok=false
local ok
for m0 in all(_possible_tiles(qxs[i-2],qys[i-2])) do
for m2 in all(_possible_tiles(qxs[i],qys[i])) do
local mx0,my0=m0.mx,m0.my
@ -1164,49 +1150,75 @@ function rope:_check_sane()
end
end
if (not ok) return false
if (not ok) return
end
end
return true
end
function would_stick(x0,y0,anchor,x2,y2)
local x1,y1=anchor.ax,anchor.ay
function would_stick(anchor,x0,y0,x1,y1,x2,y2)
x1,y1=x1 or anchor.ax,y1 or anchor.ay
local dx=x2-x0
local dy=y2-y0
local dx,dy=x2-x0,y2-y0
if (x1==x0 and y1==y0) return
if (x1==x2 and y1==y2) return
if (x1==x0 and y1==y0) return false
if (x1==x2 and y1==y2) return false
local adx,ady
local x1_new,y1_new
if abs(dx)>abs(dy) then
if (x0>x2) dx,x0,y0,x2,y2=-dx,x2,y2,x0,y0
local dprop=(x1-x0)/dx
x1_new,y1_new=x1,y0+dprop*(y2-y0)
ady=sgn0(y1_new-y1)
adx=0
if (y0>y2) adx=ady
if (y0<y2) adx=-ady
else
if (y0>y2) dy,x0,y0,x2,y2=-dy,x2,y2,x0,y0
local dprop=(y1-y0)/dy
x1_new,y1_new=x0+dprop*(x2-x0),y1
adx=sgn0(x1_new-x1)
ady=0
if (x0>x2) ady=adx
if (x0<x2) ady=-adx
local function switch_ends()
dx,dy,x0,y0,x2,y2=-dx,-dy,x2,y2,x0,y0
end
local wouldnt=anchor.dropped or (anchor.adx!=adx or anchor.ady!=ady)
local function signs(douter,dinner)
local adb=sgn0(dinner)
return -sgn0(douter)*adb,adb
end
return not wouldnt,x1_new,y1_new,adx,ady
local adx,ady,x1_new,y1_new
if abs(dx)>abs(dy) then
if (x0>x2) switch_ends()
x1_new,y1_new=x1,y0+(x1-x0)/dx*dy
adx,ady=signs(dy,y1_new-y1)
else
if (y0>y2) switch_ends()
x1_new,y1_new=x0+(y1-y0)/dy*dx,y1
ady,adx=signs(dx,x1_new-x1)
end
return
anchor and anchor.adx==adx and anchor.ady==ady,
x1_new,y1_new
end
function rope:be_pushed_by(anchor,ax_old,ay_old)
function rope:experience_anchor_moves(moves)
self:_be_dragged_by(moves)
self:_be_pushed_by(moves)
self:relax()
end
function rope:_be_dragged_by(moves)
local n=self.src
while n do
for t in all(moves) do
local ax_old,ay_old,ax_new,ay_new=unpack(t)
if (ax_old==n.ax and ay_old==n.ay) n.dest={ax_new,ay_new} break
end
n=n.next
end
n=self.src
while n do
if (n.dest) self:_drag(n,unpack(n.dest)) n.dest=nil
n=n.next
end
end
function rope:_be_pushed_by(moves)
for i in all(moves) do
self:_be_pushed_by1(unpack(i))
end
end
function rope:_be_pushed_by1(ax_old,ay_old,ax_new,ay_new,anch)
local n0=self.src
local ax_new,ay_new=anchor.ax,anchor.ay
while true do
n1=n0.next
if (not n1) return
@ -1216,37 +1228,30 @@ function rope:be_pushed_by(anchor,ax_old,ay_old)
local nxmn,nxmx = _mnmx(nx0,nx1)
local nymn,nymx = _mnmx(ny0,ny1)
-- printh(tostring({anchor,nxmn,nxmx,nymn,nymx}))
if
(ax_new!=ax_old or (nxmn<=anchor.ax and anchor.ax<=nxmx)) and
(ay_new!=ay_old or (nymn<=anchor.ay and anchor.ay<=nymx)) and
(ax_new!=ax_old or (nxmn<ax_new and ax_new<nxmx)) and
(ay_new!=ay_old or (nymn<ay_new and ay_new<nymx)) and
(_which_side(ax_old,ay_old,nx0,ny0,nx1,ny1)!=
_which_side(ax_new,ay_new,nx0,ny0,nx1,ny1)
) and would_stick(nx0,ny0,anchor,nx1,ny1)
) and would_stick(anch,nx0,ny0,nil,nil,nx1,ny1)
then
-- printh("found (in): "..tostring({{nx0,ny0},{nx1,ny1}, anchor}))
local nx05,ny05
if ax_new==ax_old then
nx05=anchor.ax
nx05=ax_new
ny05=ny0+(nx05-nx0)/(nx1-nx0) * (ny1-ny0)
-- printh("found (x): "..tostring({nx05,ny05}))
elseif ay_new==ay_old then
ny05=anchor.ay
ny05=ay_new
nx05=nx0+(ny05-ny0)/(ny1-ny0) * (nx1-nx0)
-- printh("found (y): "..tostring({nx05,ny05}))
else
assert(false,"wtf?")
end
local n05={ax=nx05,ay=ny05,associated_with=anchor,prev=n0,next=n1}
--printh("adding: "..tostring({nx05,ny05,anchor}))
local n05={ax=nx05,ay=ny05,prev=n0,next=n1}
n0.next=n05
n1.prev=n05
self:_drag(n05,anchor.ax,anchor.ay)
-- printh("dragged: "..tostring({n05.ax,n05.ay,anchor}))
-- printh("local: "..tostring(n0.associated_with).."->"..tostring(n05.associated_with).."->"..tostring(n1.associated_with))
-- printh("creating: "..tostring{anch,{n0.ax,n0.ay},{n05.ax,n05.ay},{n1.ax,n1.ay}})
-- printh("dragging: "..tostring{anch,{n05.ax,n05.ay},{ax_new,ay_new}})
self:_drag(n05,ax_new,ay_new)
else
n0=n0.next
end
@ -1261,7 +1266,7 @@ function rope:_drag(n1,ax1_new,ay1_new,ax_removing,ay_removing)
(anchor.ax==ax_removing and anchor.ay==ay_removing)
end
if (ax_far0==ax_far1 and ay_far0==ay_far1) return nil
if (ax_far0==ax_far1 and ay_far0==ay_far1) return
if ax_far0==ax_far1 then
local ax_far=ax_far0
@ -1273,7 +1278,7 @@ function rope:_drag(n1,ax1_new,ay1_new,ax_removing,ay_removing)
if
not _uncreatable(anchor) and
(ax0<=anchor.ax and anchor.ax<=ax1) and
would_stick(ax_pivot,ay_pivot,anchor,ax_far,ay_far_new) and
would_stick(anchor,ax_pivot,ay_pivot,nil,nil,ax_far,ay_far_new) and
(
_which_side(anchor.ax,anchor.ay,ax_pivot,ay_pivot,ax_far,ay_far_old) !=
_which_side(anchor.ax,anchor.ay,ax_pivot,ay_pivot,ax_far,ay_far_new)
@ -1294,7 +1299,7 @@ function rope:_drag(n1,ax1_new,ay1_new,ax_removing,ay_removing)
if
not _uncreatable(anchor) and
(ay0<=anchor.ay and anchor.ay<=ay1) and
would_stick(ax_pivot,ay_pivot,anchor,ax_far_new,ay_far) and
would_stick(anchor,ax_pivot,ay_pivot,nil,nil,ax_far_new,ay_far) and
(
_which_side(anchor.ax,anchor.ay,ax_pivot,ay_pivot,ax_far_old,ay_far) !=
_which_side(anchor.ax,anchor.ay,ax_pivot,ay_pivot,ax_far_new,ay_far)
@ -1313,30 +1318,26 @@ function rope:_drag(n1,ax1_new,ay1_new,ax_removing,ay_removing)
n1.ay=ay1_new
local n0=n1.prev
while true do
if (n0==nil) break
while n0 do
local anch=_sweep_radar(
n0.ax,n0.ay,n1.ax,n1.ay,
n0.ax,n0.ay,ax1_old,ay1_old,ax1_new,ay1_new
)
if (anch==nil) break
local n05={ax=anch.ax,ay=anch.ay,associated_with=anch,prev=n0,next=n1}
-- printh("creating pre: "..tostring(n0.associated_with).."->"..tostring(n05.associated_with).."->"..tostring(n1.associated_with))
if (not anch) break
local n05={ax=anch.ax,ay=anch.ay,prev=n0,next=n1}
n0.next=n05
n1.prev=n05
n0=n05
end
local n2=n1.next
while true do
if (n2==nil) break
while n2 do
local anch=_sweep_radar(
n1.ax,n1.ay,n2.ax,n2.ay,
n2.ax,n2.ay,ax1_old,ay1_old,ax1_new,ay1_new
)
if (anch==nil) break
local n15={ax=anch.ax,ay=anch.ay,associated_with=anch,prev=n1,next=n2}
-- printh("creating post: "..tostring(n1.associated_with).."->"..tostring(n15.associated_with).."->"..tostring(n2.associated_with))
if (not anch) break
local n15={ax=anch.ax,ay=anch.ay,prev=n1,next=n2}
n1.next=n15
n2.prev=n15
n2=n15
@ -1344,7 +1345,7 @@ function rope:_drag(n1,ax1_new,ay1_new,ax_removing,ay_removing)
end
function _stepfrom(x0,x1)
local done=false
local done
if x0==x1 then
return function()
if (done) return
@ -1359,12 +1360,12 @@ function _stepfrom(x0,x1)
local i=flr(x0)
local top=flr(x1)
return function()
if (done) return nil
if (done) return
i+=1
if i>top then
done = true
if (x1!=flr(x1)) return mul*x1
return nil
return
end
return mul*i
end
@ -1390,25 +1391,25 @@ function rope:collide_mrect(mx0,my0,mw,mh,exclude_src,exclude_dst)
while true do
local n1=n0.next
if (n1==nil) return false
if (not n1) return
local nd=n0
for i=1,exclude_dst do
nd=nd.next
if (nd==nil) return false
if (not nd) return
end
local x1,y1,x2,y2=n0.ax,n0.ay,n1.ax,n1.ay
local function _line_line(x3,y3,x4,y4)
local denom=((y4-y3)*(x2-x1)-(x4-x3)*(y2-y1))
local denom=(y4-y3)*(x2-x1)-(x4-x3)*(y2-y1)
local ua=
((x4-x3)*(y1-y3)-(y4-y3)*(x1-x3))/denom
if (ua<0 or ua>1) return false
if (ua<0 or ua>1) return
local ub=
((x2-x1)*(y1-y3)-(y2-y1)*(x1-x3))/denom
if (ub<0 or ub>1) return false
if (ub<0 or ub>1) return
return true
end
@ -1429,12 +1430,12 @@ function rope:tug_orientxy()
local a1=self.dst
local a0=self.dst.prev
local dx=a0.ax-a1.ax
local tdx=nil
local tdx
if (dx>3/8) tdx=1
if (dx<-3/8) tdx=-1
local dy=a0.ay-a1.ay
local tdy=nil
local tdy
if abs(dy)>abs(dx)/2 then
if (dy>3/8) tdy=1
if (dy<-3/8) tdy=-1
@ -1475,11 +1476,11 @@ function rope:_tug(hypothetically)
end
local latch=self.latch
if latch!=nil and latch.el=="eyehook" then
if latch and latch.el=="eyehook" then
if (hypothetically) return ancs,0
player.todo={{
update=function(s)
if s.rope==nil or s.rope:done() then
if not s.rope or s.rope:done() then
return true
end
end
@ -1487,7 +1488,7 @@ function rope:_tug(hypothetically)
self:destroy(true)
return true
end
if latch!=nil and latch.el=="crate" then
if latch and latch.el=="crate" then
local dmx,dmy=
sgn0(latch.dx),
sgn0(latch.dy)
@ -1503,7 +1504,7 @@ function rope:_tug(hypothetically)
local mxa=(pull_anc.x+dmx)\8
local mya=(pull_anc.y+dmy)\8
local invalid_move=false
local invalid_move
if
(dmx!=0 and sgn0(pull_dx)!=dmx) or
(dmy!=0 and sgn0(pull_dy)!=dmy) or
@ -1527,15 +1528,15 @@ function rope:_tug(hypothetically)
end
end
if (hypothetically) return ancs,nil
return false
if (hypothetically) return ancs
return
end
function rope:_calc_push(
an,a0,a1,af
)
local ops={}
if (an==nil) return ops
if (not an) return ops
if a0.x==a1.x then
-- no far side applying pressure?
@ -1597,12 +1598,12 @@ function rope:_calc_push(
-- great!
else
local crate=level:get_crate(o.mx,o.my)
if crate==nil then
break
else
if crate then
if not level:can_move(false,o.mx,o.my,o.dmx,o.dmy,0,0) then
break
end
else
break
end
add(ops2,o)
end
@ -1617,23 +1618,23 @@ function rope:_anchors_simplified()
return atan2(p1.y-p0.y,p1.x-p0.x)
end
a=self.src
while a!=nil do
while a do
local point={
x=flr(a.ax*8+0.5),y=flr(a.ay*8+0.5),
ax=a.ax,ay=a.ay
}
local aw=a.associated_with
local aw=level:anchor_at(a.ax,a.ay)
local l=self.latch
if aw then
if (aw.adx==1) point.x-=1
if (aw.ady==1) point.y-=1
elseif a.prev==nil and l then
elseif not a.prev and l then
if (l.ax_offset<0) point.x-=1
if (l.ay_offset<0) point.y-=1
end
local p0,p1=points[#points-1],points[#points]
if p0==nil then
if not p0 then
add(points,point)
elseif _slope(p0,p1)==_slope(p1,point) then -- epsilon?
points[#points]=point
@ -1972,22 +1973,22 @@ __map__
0d0d0d0d0d0d0d0d0d080d0d0d0d0d0d0d0d230024242425141300000000150d0d0d134f1e00151414141400140d0d0d0d0d0d0d0d13000006240024070000150d2324240024242513000040441500140d0d0d0d0d0d0d0d0d080d0d0d0d0d0d0100000000000000062424242514140d0100001d1d483f230024242424242425
0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d1400140d0d0d0d2324242424250d0d0d13000000000000000000140d0d0d0d0d0d0d0d23242425140014232424250d0d0d1400140d0d13000000001500120d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d1423242424243c250d0d0d0d0d0d0d0d14131f1f00000000140d0d0d0d0d0d
0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d120d0d0d0d0d0d0d0d0d0d0d0d0d0d23242424251414141414140d0d0d0d0d0d0d0d0d0d0d0d0d010d0d0d0d0d0d0d0d0d010d0d0d232424242425140d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d23242424251414140d0d0d0d0d0d
0d030404040404050d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d000000000000000000000000000000000d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0d13001c00003f15030404040404050d0d0304043e0404050d0d0d0d0d0d0d0d000000000000000000000000000000000d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0d13001f1d000015130000000000150d0d130000000000150d0d0d0d0d0d0d0d000000000000000000000000000000000d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
010000001c000000004f1e1d1d00150d0d13000000000015030404040404050d000000000000000000000000000000000d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0d131d1d1f1e1e151300001f1f00150d0d1300000000001513460044004c150d000000000000000000000000000000000d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0d131c1c00000015130000000000150d0d2324241d242425131d1d1e1d1d150d000000000000000000000000000000000d0d0d0d030404040404050d0d0d0d0d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0d131c1c0014001513001e1e1927270b030404041f000000001c1c003f1c150d000000000000000000000000000000000d0d0d0d130000001c000000000d0d0d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0d131c1c00000000000000001c1c150d1300000000151414131f1f1e1f1f150d000000000000000000000000000000000d141414130028001c4516050014140d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0927271b1e1e0015130014001c1c150d0100000000151414130000410000150d0000000000000000000000000000000001000000000000001f0000150000001200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0d13000000000015130000001c1c150d130000284116050927271b001927270b000000000000000000000000000000000d14141413002800000000151414140d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0d13001d1d000015131e1e1d1f1f150d130043000000151f131c1c001c1f150d000000000000000000000000000000000d0d0d0d13000000000006250d0d0d0d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0d13001f1f1e4f000000001c00000012130000001d1d1500001f1f001f00150d000000000000000000000000000000000d0d0d0d232424242424250d0d0d0d0d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0d130000000000151300001f1d00150d2324242424242500130000000000150d000000000000000000000000000000000d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0d23242424242425133d00001c00150d0d0d0d0d0d0d1400130000000000150d000000000000000000000000000000000d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0d0d0d0d0d0d0d0d232424242424250d0d0d0d0d0d0d1400232424242424250d000000000000000000000000000000000d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d120d0d0d0d0d0d0d0d000000000000000000000000000000000d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0d0d0d0d0d0d0d0d030404040404050d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d010d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0d03040404040405133d00001c00150d0d0d0d0d0d0d0d0d0304043e0404050d0d0d0d0d030404000404050d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0d130000000000151300001d1f00150d0d0d0d0d0d0d0d0d150000000000150d0d0d0d0317420000004816050d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0d13001d1d1e4f000000001c000000010d03040404040405150000000000150d0d0d141300191b1d191b0015140d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0d13001f1f000015131e1e1f1d1d150d0d13460044004c15150000000000150d0d3d001e0042001f0048001e003f0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0d13000000000015130000001c1c150d0d131d1d1e1d1d152324241d2424250d0d140023240700410006242500140d0d0d0d0d0d030404040404050d0d0d0d0d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0927271b1e1e0015130014001c1c150d0d131c3d001c1c000000001f040404050d1400000023243c2425000000140d0d0d0d0d0d130000001c000000000d0d0d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0d131c1c00000000000000001c1c150d0d131f1f1e1f1f1514141300280000150d14000000001f1f1f00000000140d0d0d141414130028001c4516050014140d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0d131c1c0014001513001e1e1927270b0d1300004100001514141300000000010d144f47411400000014000000140d0d01000000000000001f0000150000001200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0d131c1c00000015130000000000150d0927271b001927270b031741280000150d14434b491400000014000000140d0d0d14141413002800000000151414140d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0d131f1f1d1e1e151300001d1d00150d0d131f1c001c1c151f130000004900150d03040404040000000304040405140d0d0d0d0d13000000000006250d0d0d0d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
120000001c000000004f1e1f1f00150d0d13001f001f1f0000131d1d000000150d1300000000000003170000000000120d0d0d0d232424242424250d0d0d0d0d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0d13001d1f000015130000000000150d0d1300000000001500232424242424250d13000000001d1d1d0000000015140d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0d13001c00003f15232424242424250d0d1300000000001500140d0d0d0d0d0d0d130000000625031700000000150d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0d232424242424250d0d0d0d0d0d0d0d0d2324242424242500140d0d0d0d0d0d0d130000062503170000000000150d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d120d0d0d0d0d0d0d0d232424250d23242424242424250d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d0d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
__sfx__
00110000250002500025030250302503000000230350000023030230302303023030230302303023030230302103021030210302103021030210300000000000177401774017740177311e7501e7501e7501e750
00110000290202a0212a0202a0202a0202a02025030250052503025030250302503025030250302503025030250302503025030250302503225030230322504526030260302a040000002d0402d0402d0402d040