Multi-layer interpretation solution
NES games have only one background layer. Therefore in games with multiple graphical layers object in the front layer will completly hide the one in the back layer or both objects apperance will be mixed in the same tiles. However we can interpolate the missing graphic of the back layer based on surround shapes to create the correct multi-layer representation. To do it we use a pair of script tagged "bg" and "bg1". The surround shapes will be tagged "bg" and the target 3dShape will be tagged "bg1" and play the role of a "place holder".
- "bg" script: pattern parameters used in the script:
- CData[1]: if the value is different than 0 then the shape texture will not be used as background texture in case there is different shapws in the bg region/slot
- CData[2] : the tolerance delta deternimes if a background shape belongs to a backgroun region/slot. If this value is -1 then the shape will be treated like the sole bg region in the current frame
function Start()
bgSlot = {}
MaxSlot = 10
for i = 1, MaxSlot do
bgSlot[i] = {}
end
end
function End()
bgSlot = nil
end
function Update()
bgCount = 0
bgOne = 0
end
function Connect(s, slot, delta)
local r = s.Palette == slot.shape.Palette and s.tStart.x <= slot.ex + delta and slot.sx <= s.tEnd.x + delta and s.tStart.y <= slot.ey + delta and slot.sx <= s.tEnd.x + delta;
return r;
end
function UpdateS()
if bgOne == 1 then
return
end
if shape.Bg then
if shape.CData[2] == -1 then
bgOne = 1
bgCount = 1
local slot = bgSlot[1]
slot.sx = -1
slot.sy = -1
slot.ex = 33
slot.ey = 31
slot.delta = 0
slot.shape = shape
return
end
for i = 1, bgCount do
local slot = bgSlot[i]
local delta = max(slot.delta, shape.CData[2])
if Connect(shape2D, slot, delta) then
slot.sx = min(slot.sx, shape2D.tStart.x)
slot.sy = min(slot.sy, shape2D.tStart.y)
slot.ex = max(slot.ex, shape2D.tEnd.x)
slot.ey = max(slot.ey, shape2D.tEnd.y)
slot.delta = delta
if slot.shape.CData[1] ~= 0 then
slot.shape = shape
slot.delta = delta
end
return;
end
end
if bgCount < MaxSlot then
bgCount = bgCount + 1;
local slot = bgSlot[bgCount]
slot.shape = shape
slot.sx = shape2D.tStart.x
slot.sy = shape2D.tStart.y
slot.ex = shape2D.tEnd.x
slot.ey = shape2D.tEnd.y
slot.delta = shape.CData[2]
end
end
end
function min(a,b)
if a < b then
return a
end
return b
end
function max(a,b)
if a > b then
return a
end
return b
end
- "bg1" script: pattern parameters used in the script:
- CDatap[0] : bg texture will have this offset while applying to this place holder
function In(shape2D, bgSlot)
return shape2D.tStart.x + 1 >= bgSlot.sx and shape2D.tStart.y + 1 >= bgSlot.sy and shape2D.tEnd.x <= bgSlot.ex + 1 and shape2D.tEnd.y <= bgSlot.ey + 1
end
function Start()
bg1List = {}
bg1Count = 0
end
function Update()
for i = 1,bg1Count do
bg1List[i] = nil
end
bg1Count = 0
end
function UpdateS()
if shape.Bg then
bg1Count = bg1Count + 1
bg1List[bg1Count] = shape
end
end
function LateUpdate()
for j = 1,bg1Count do
local select = nil
local shape = bg1List[j]
for i = 1, bgCount do
local _bgSlot = bgSlot[i]
if shape.Shape2D ~= _bgSlot.shape.Shape2D and In(shape.Shape2D, _bgSlot) and (not select or (select.ey - select.sy > _bgSlot.ey - _bgSlot.sy)) then
select = _bgSlot
end
end
if select then
shape.Enable = true
local bgShape = select.shape
shape.customPalette = bgShape.Palette
shape.Layer = bgShape.Layer
shape.Offset.z = bgShape.Offset.z
shape.CastShadow = bgShape.CastShadow
shape.RecvShadow = bgShape.RecvShadow
shape.slot = bgShape.slot
shape.texOffset.x = shape.CData[0]
shape.Scale.z = bgShape.Scale.z * bgShape.sizeZ / shape.sizeZ
shape.Alpha = bgShape.Alpha
shape.Pivot.z = 0
else
shape.Enable = false
end
end
end