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