I think I just added some convenience for when I try to continue.
First, I cleaned up my getwall a little...
function getwall(tx, ty) -- Expects input by tile
-- Returns a number from 0 to 3, identifying collision data for given tile
-- 0 is open space, 1 is solid wall, 2 and 3 are types of destructible
-- Has knowledge of location and range of wall array.
addr = 0x6000
tx = tx%64
ty = ty%30
if tx > 31 then -- horizontal scroll uses two different arrays
tx = tx - 32
addr = addr + 0x100
end
addr = addr + math.floor( tx/4 ) + ty*8
return AND( 3 * 4^(tx%4) , memory.readbyte(addr) ) /4^( tx%4 )
end -- Bitmask Target Byte RightShift
Next, I created another function...
function PosTile(px, py) -- Expects input by pixel
-- Returns the tile position for given screen coordinates.
-- Keep in mind in vertical scrollers, ty is often negative.
-- Has knowledge of scrolling type and stage position
sp = memory.readbyte(0x0044)
if memory.readbyte(0x0041) == 0 then -- horizontal scrolling
sp = sp + memory.readbyte(0x0045)*256
tx = math.floor( (px+sp)/8 )
ty = math.floor( py /8 )+4
return tx, ty
elseif memory.readbyte(0x0041) == 1 then -- vertical scrolling
sp = sp + memory.readbyte(0x0045)*240
tx = math.floor( px /8 )
ty = math.floor( (py-sp)/8 )
return tx, ty
end
return "nil" -- It shouldn't fall out to here.
end
Then I did stuff with them:
while true do
for pl=0, 1 do
plX = memory.readbyte(0x035C+pl) + memory.readbyte(0x0064+pl)/256
plY = memory.readbyte(0x0337+pl) + memory.readbyte(0x0062+pl)/256
plS = memory.readbyte(0x0070+pl)/4 + 1.25
for x=-2, 2 do
for y=-2, 2 do
if getwall(PosTile(plX+x*plS , plY+y*plS)) == 0 then
color="green"
else
color="red"
end
gui.drawbox(187+x*4+pl*28, 215+y*4, 189+x*4+pl*28, 217+y*4, color)
end
end
end
FCEU.frameadvance()
end
I have my own personal terrain radar. It tells me if I were to move 1 or 2 frames in some direction, whether my position will intersect with a wall. We can adjust a few values to change scanning radius or where the boxes are located.
I see something about that gui.register() function. I'm wondering how it is to be used... Having the small green/red boxes show up when it's important and not a frame after it's importance should help things a bit.