Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- These tile IDs encode open/cleared tiles where motion is possible
- local clear = {}
- for i,v in pairs({0x00, 0x02, 0x04, 0x22, 0x2c, 0x3a}) do clear[v]=true end
- -- These tile IDs encode blocked tiles that cannot be entered
- local blocked = {}
- for i,v in pairs({0x18, 0x1a, 0x1c, 0x1e, 0x20, 0x28, 0x2a, 0x32}) do blocked[v]=true end
- local tiles = {}
- local camx = memory.readword(0x7e080e)
- local camy = memory.readword(0x7e0812)
- local playerx = memory.readword(0x7e1000)
- local playery = memory.readword(0x7e1002)
- local function getCollisionData()
- camx = memory.readword(0x7e080e)
- camy = memory.readword(0x7e0812)
- playerx = memory.readword(0x7e1000)
- playery = memory.readword(0x7e1002)
- local width = memory.readbyte(0x7e0827)*16
- tiles = {}
- for y=math.floor(camy/16),math.floor(camy/16)+14 do
- tiles[y] = {}
- for x=math.floor(camx/16),math.floor(camx/16)+16 do
- tiles[y][x] = AND(memory.readbyte(0x7ea001+2*(y*width+x)),0xfe)
- end
- end
- end
- local function tileExists(x,y) return tiles[y] and tiles[y][x] end
- local function tileCleared(x,y) return tileExists(x,y) and clear[tiles[y][x]] end
- local function tileBlocked(x,y) return tileExists(x,y) and blocked[tiles[y][x]] end
- local function renderArrowBody(scrx,scry)
- gui.box(scrx+7,scry+3,scrx+9,scry+12,0xFFFFFFFF,0x000000FF)
- end
- local function renderArrowHeadUp(scrx,scry)
- gui.line(scrx+5,scry+5,scrx+8,scry+2,0x000000FF)
- gui.line(scrx+11,scry+5,scrx+8,scry+2,0x000000FF)
- gui.line(scrx+7,scry+6,scrx+5,scry+6,0x000000FF)
- gui.line(scrx+9,scry+6,scrx+11,scry+6,0x000000FF)
- gui.pixel(scrx+8,scry+3,0xFFFFFFFF)
- gui.line(scrx+7,scry+4,scrx+9,scry+4,0xFFFFFFFF)
- gui.line(scrx+6,scry+5,scrx+10,scry+5,0xFFFFFFFF)
- end
- local function renderArrowHeadDown(scrx,scry)
- gui.line(scrx+5,scry+10,scrx+8,scry+13,0x000000FF)
- gui.line(scrx+11,scry+10,scrx+8,scry+13,0x000000FF)
- gui.line(scrx+7,scry+9,scrx+5,scry+9,0x000000FF)
- gui.line(scrx+9,scry+9,scrx+11,scry+9,0x000000FF)
- gui.pixel(scrx+8,scry+12,0xFFFFFFFF)
- gui.line(scrx+7,scry+11,scrx+9,scry+11,0xFFFFFFFF)
- gui.line(scrx+6,scry+10,scrx+10,scry+10,0xFFFFFFFF)
- end
- local function renderTile(x,y)
- if not tileExists(x,y) or tileCleared(x,y) then return end
- local tile = tiles[y][x]
- local scrx = 16*x-camx
- local scry = 16*y-camy-1
- if tileBlocked(x,y) then
- gui.box(scrx-1,scry-1,scrx+16,scry+16,0xFF000080,0)
- if not tileBlocked(x,y-1) then gui.line(scrx,scry,scrx+15,scry,0xFF0000FF) end
- if not tileBlocked(x,y+1) then gui.line(scrx,scry+15,scrx+15,scry+15,0xFF0000FF) end
- if not tileBlocked(x-1,y) then gui.line(scrx,scry,scrx,scry+15,0xFF0000FF) end
- if not tileBlocked(x+1,y) then gui.line(scrx+15,scry,scrx+15,scry+15,0xFF0000FF) end
- if not tileBlocked(x-1,y-1) then gui.pixel(scrx,scry,0xFF0000FF) end
- if not tileBlocked(x+1,y+1) then gui.pixel(scrx+15,scry+15,0xFF0000FF) end
- if not tileBlocked(x-1,y+1) then gui.pixel(scrx,scry+15,0xFF0000FF) end
- if not tileBlocked(x+1,y-1) then gui.pixel(scrx+15,scry,0xFF0000FF) end
- elseif tile==0x0c then -- leftdown/rightup
- gui.line(scrx+15,scry,scrx,scry+15,0xFF0000FF)
- if tileCleared(x,y-1) and tileCleared(x-1,y) then
- gui.line(scrx+15,scry,scrx,scry,0xFF000080)
- gui.line(scrx,scry+1,scrx,scry+15,0xFF000080)
- else
- for i=14,0,-1 do gui.line(scrx,scry+i,scrx+i,scry,0xFF000080) end
- end
- if tileCleared(x,y+1) and tileCleared(x+1,y) then
- gui.line(scrx+15,scry,scrx+15,scry+15,0xFF000080)
- gui.line(scrx+14,scry+15,scrx,scry+15,0xFF000080)
- else
- for i=1,15 do gui.line(scrx+i,scry+15,scrx+15,scry+i,0xFF000080) end
- end
- elseif tile==0x0e then -- leftup/rightdown
- gui.line(scrx,scry,scrx+15,scry+15,0xFF0000FF)
- if tileCleared(x,y-1) and tileCleared(x+1,y) then
- gui.line(scrx,scry,scrx+15,scry,0xFF000080)
- gui.line(scrx+15,scry+1,scrx+15,scry+15,0xFF000080)
- else
- for i=0,14 do gui.line(scrx+i,scry+i,scrx+15,scry+i,0xFF000080) end
- end
- if tileCleared(x,y+1) and tileCleared(x-1,y) then
- gui.line(scrx,scry,scrx,scry+15,0xFF000080)
- gui.line(scrx+1,scry+15,scrx+15,scry+15,0xFF000080)
- else
- for i=1,15 do gui.line(scrx+0,scry+i,scrx+i,scry+i,0xFF000080) end
- end
- elseif tile==0x10 or tile==0x34 or tile==0x36 or tile==0x3e then -- Fall/Vine/Crawl/Claw climb
- gui.box(scrx-1,scry-1,scrx+16,scry+16,0x00000080,0)
- if tileExists(x,y-1) and tiles[y-1][x]~=tile then gui.line(scrx,scry,scrx+15,scry,0x000000FF) end
- if tileExists(x,y+1) and tiles[y+1][x]~=tile then gui.line(scrx,scry+15,scrx+15,scry+15,0x000000FF) end
- if tileExists(x-1,y) and tiles[y][x-1]~=tile then gui.line(scrx,scry,scrx,scry+15,0x000000FF) end
- if tileExists(x+1,y) and tiles[y][x+1]~=tile then gui.line(scrx+15,scry,scrx+15,scry+15,0x000000FF) end
- renderArrowBody(scrx,scry)
- if tile~=0x10 then renderArrowHeadUp(scrx,scry) end
- renderArrowHeadDown(scrx,scry)
- elseif AND(tiles[y][x],0x80)~=0 then
- gui.box(scrx,scry,scrx+15,scry+15,0xFF800080)
- gui.text(scrx+2,scry+4,"NPC")
- else
- gui.box(scrx,scry,scrx+15,scry+15,0xFF000080)
- local tile = "??"
- if tiles[y] and tiles[y][x] then tile = tiles[y][x] end
- gui.text(scrx+4,scry+4,string.format("%02x",tile))
- end
- end
- local function renderField()
- for y=math.floor(camy/16),math.floor(camy/16)+14 do
- for x=math.floor(camx/16),math.floor(camx/16)+16 do
- renderTile(x,y)
- end
- end
- local relx = playerx -camx
- local rely = playery -camy
- -- Draw player collision
- gui.box(relx-8, rely-17,relx+7, rely-2,0x00FF0080)
- gui.line(relx-8, rely-9,relx+7, rely-9,0x0000FFFF)
- gui.line(relx, rely-2,relx, rely-17,0x000000FFFF)
- end
- local prevX = 0
- local prevY = 0
- local function getPositionData()
- prevX = memory.readword(0x7e1000)
- prevY = memory.readword(0x7e1002)
- end
- local dX = 0
- local dY = 0
- local function getDisplacementData()
- dX = prevX - memory.readword(0x7e1000)
- dY = prevY - memory.readword(0x7e1002)
- end
- local function showDisplacement()
- if dX<0 then
- gui.text(playerx-camx+11,playery-camy-12,-dX,0x00FF00FF)
- elseif dX>0 then
- gui.text(playerx-camx-14,playery-camy-12,dX,0x00FF00FF)
- end
- if dY<0 then
- gui.text(playerx-camx-1,playery-camy+1,-dY,0x00FF00FF)
- elseif dY>0 then
- gui.text(playerx-camx-1,playery-camy-26,dY,0x00FF00FF)
- end
- end
- -- Local display function
- local function my_display()
- getDisplacementData()
- getCollisionData()
- if not hidden then
- renderField()
- showDisplacement()
- end
- getPositionData()
- end
- -- Hook the display function to the GUI update
- local on_gui_update_old = gui.register()
- local function on_gui_update_new()
- if on_gui_update_old then
- on_gui_update_old()
- end
- my_display()
- end
- gui.register(on_gui_update_new)
- -- Public functions
- collision_map = {}
- function collision_map.show()
- hidden = false
- end
- function collision_map.hide()
- hidden = true
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement