forked from pyrex/chameleonic
Golf level slightly
This commit is contained in:
parent
9fbccee378
commit
ae7dc8374e
@ -231,9 +231,7 @@ end
|
|||||||
function level:reinit(n)
|
function level:reinit(n)
|
||||||
self.ix=n
|
self.ix=n
|
||||||
self.todo={}
|
self.todo={}
|
||||||
self.bigx=(n%8)
|
self.bigx,self.bigy=n%8,n\8
|
||||||
self.bigy=(n\8)
|
|
||||||
self.next_crate_id=1
|
|
||||||
|
|
||||||
self:load_dynobjs()
|
self:load_dynobjs()
|
||||||
self:recollide()
|
self:recollide()
|
||||||
@ -302,7 +300,7 @@ function level:update()
|
|||||||
end
|
end
|
||||||
if #remove>0 then
|
if #remove>0 then
|
||||||
self:recollide()
|
self:recollide()
|
||||||
self:reanchor(true)
|
self:reanchor()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -310,6 +308,7 @@ function level:load_dynobjs()
|
|||||||
self._crates={}
|
self._crates={}
|
||||||
self._pits={}
|
self._pits={}
|
||||||
|
|
||||||
|
local crate_id=1
|
||||||
for mx=0,15,1 do
|
for mx=0,15,1 do
|
||||||
for my=0,15,1 do
|
for my=0,15,1 do
|
||||||
local mxy=_mix(mx,my)
|
local mxy=_mix(mx,my)
|
||||||
@ -319,22 +318,16 @@ function level:load_dynobjs()
|
|||||||
if def then
|
if def then
|
||||||
self._crates[mxy]={
|
self._crates[mxy]={
|
||||||
s=s,def=def,
|
s=s,def=def,
|
||||||
id=self.next_crate_id,
|
id=crate_id,
|
||||||
mx=mx,my=my,
|
mx=mx,my=my,
|
||||||
px=px,py=py,
|
px=px,py=py,
|
||||||
todo={}
|
todo={}
|
||||||
}
|
}
|
||||||
self.next_crate_id+=1
|
crate_id+=1
|
||||||
end
|
end
|
||||||
|
|
||||||
if s==28 then -- pit
|
-- pit
|
||||||
self._pits[mxy]={
|
if (s==28) self._pits[mxy]={s=s,mx=mx,my=my,px=px,py=py}
|
||||||
s=s,
|
|
||||||
mx=mx,my=my,
|
|
||||||
px=px,py=py,
|
|
||||||
contents=nil
|
|
||||||
}
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -405,17 +398,11 @@ function level:reanchor()
|
|||||||
end
|
end
|
||||||
shellsort(self._anch_keys)
|
shellsort(self._anch_keys)
|
||||||
for point in self:anchor_points() do
|
for point in self:anchor_points() do
|
||||||
if point.ax_old!=nil then
|
if (point.ax_old and player.rope) player.rope:be_pushed_by(point,point.ax_old,point.ay_old)
|
||||||
if (player.rope!=nil) player.rope:be_pushed_by(point,point.ax_old,point.ay_old)
|
point.ax_old,point.ay_old=nil,nil
|
||||||
point.ax_old=nil
|
|
||||||
point.ay_old=nil
|
|
||||||
end
|
|
||||||
end
|
|
||||||
for point in self:anchor_points() do
|
|
||||||
assert(not point.dropped)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if (player.rope!=nil) player.rope:relax()
|
if (player.rope) player.rope:relax()
|
||||||
end
|
end
|
||||||
|
|
||||||
function level:win_at(mx,my)
|
function level:win_at(mx,my)
|
||||||
@ -485,14 +472,10 @@ end
|
|||||||
|
|
||||||
function _amix(ax,ay)
|
function _amix(ax,ay)
|
||||||
return ax..","..ay
|
return ax..","..ay
|
||||||
--if (ax<0 or ay<0 or ax>31 or ay>31) return nil
|
|
||||||
--return ay*32+ax
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function _mix(mx,my)
|
function _mix(mx,my)
|
||||||
return mx..","..my
|
return mx..","..my
|
||||||
--if (mx<0 or my<0 or mx>15 or my>15) return nil
|
|
||||||
--return my*16+mx
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function level:_get_cratedef(s)
|
function level:_get_cratedef(s)
|
||||||
@ -553,35 +536,23 @@ function level:can_move(
|
|||||||
is_player,
|
is_player,
|
||||||
mx0,my0,dmx,dmy,exclude_src,exclude_dst
|
mx0,my0,dmx,dmy,exclude_src,exclude_dst
|
||||||
)
|
)
|
||||||
if is_player and self:win_at(mx0+dmx,my0+dmy) then
|
local mx1,my1=mx0+dmx,my0+dmy
|
||||||
return true
|
if (is_player and self:win_at(mx1,my1)) return true
|
||||||
end
|
if (is_player and self:get_open_pit(mx1,my1)) return wrongbleep:adequately_warned()
|
||||||
if is_player and self:get_open_pit(mx0+dmx,my0+dmy) then
|
|
||||||
return wrongbleep:adequately_warned()
|
|
||||||
end
|
|
||||||
|
|
||||||
if self:mcoll(mx0+dmx,my0+dmy) then
|
if (self:mcoll(mx1,my1) or player.x==mx1 and player.y==my1) return false
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
if player.x==mx0+dmx and player.y==my0+dmy then
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
-- todo: check tongue collision
|
|
||||||
if player.rope then
|
if player.rope then
|
||||||
local chk=false
|
local chk=false
|
||||||
if dmx==0 and dmy==-1 then
|
local w,h=1.6,0.2
|
||||||
chk=player.rope:collide_mrect(mx0+0.4,my0-0.8,0.2,1.6,exclude_src,exclude_dst)
|
if (dmx==0) w,h=0.2,1.6
|
||||||
elseif dmx==0 and dmy==1 then
|
|
||||||
chk=player.rope:collide_mrect(mx0+0.4,my0+0.2,0.2,1.6,exclude_src,exclude_dst)
|
|
||||||
elseif dmx==-1 and dmy==0 then
|
|
||||||
chk=player.rope:collide_mrect(mx0-0.8,my0+0.4,1.6,0.2,exclude_src,exclude_dst)
|
|
||||||
elseif dmx==1 and dmy==0 then
|
|
||||||
chk=player.rope:collide_mrect(mx0+0.2,my0+0.4,1.6,0.2,exclude_src,exclude_dst)
|
|
||||||
end
|
|
||||||
|
|
||||||
if (chk) return false
|
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 (player.rope:collide_mrect(mx0+rectx,my0+recty,w,h,exclude_src,exclude_dst)) return false
|
||||||
end
|
end
|
||||||
|
|
||||||
return true
|
return true
|
||||||
@ -590,22 +561,21 @@ end
|
|||||||
function level:tug_crate(mx0,my0,dmx,dmy)
|
function level:tug_crate(mx0,my0,dmx,dmy)
|
||||||
local mxy0=_mix(mx0,my0)
|
local mxy0=_mix(mx0,my0)
|
||||||
local existing=self._crates[mxy0]
|
local existing=self._crates[mxy0]
|
||||||
if (existing==nil) return
|
if (not existing) return
|
||||||
|
|
||||||
self._crates[mxy0]=nil
|
self._crates[mxy0]=nil
|
||||||
|
|
||||||
local mx1,my1=mx0+dmx,my0+dmy
|
local mx1,my1=mx0+dmx,my0+dmy
|
||||||
local mxy1=_mix(mx1,my1)
|
local px1,py1=mx1*8,my1*8
|
||||||
existing.todo={
|
existing.todo={
|
||||||
{px=mx1*8+dmx,py=my1*8+dmy,mx=mx1,my=my1,update=function()
|
{px=px1+dmx,py=py1+dmy,mx=mx1,my=my1,update=function()
|
||||||
self:recollide()
|
self:recollide()
|
||||||
self:reanchor()
|
self:reanchor()
|
||||||
return true
|
return true
|
||||||
end},
|
end},
|
||||||
{px=mx1*8,py=my1*8}
|
{px=px1,py=py1}
|
||||||
}
|
}
|
||||||
|
|
||||||
self._crates[mxy1]=existing
|
self._crates[_mix(mx1,my1)]=existing
|
||||||
end
|
end
|
||||||
|
|
||||||
-->8
|
-->8
|
||||||
|
Loading…
Reference in New Issue
Block a user