Created
August 20, 2016 01:13
-
-
Save Skarsnik/547e36239987adf65e888ca0de6d91b9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Original Script by Gunty found on http://tasvideos.org/forum/viewtopic.php?t=3686&postdays=0&postorder=asc&start=20 | |
-- Modifications by @wzl_ | |
console.writeline("Hello") | |
local hidden = false | |
-- 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 | |
for i,v in pairs({0x00}) 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 | |
for i,v in pairs({0x1c, 0x1e, 0x18, 0x32}) do blocked[v]=true end | |
-- 02, 04 Passable | |
-- 08 ratree plant chests - some pickups > meilin scarf, gumin logs | |
-- 0a pushable objects | |
-- 18 Blocked, can be pots and chests | |
-- 1a Sylvain portraits, tower 3/4? | |
-- 1c Blocked | |
-- 1e Blocked | |
-- 26 water | |
-- 28 pits | |
-- 24 rope | |
-- 32 blocked tiles, usually by pits or water | |
-- 3a staris no run? | |
-- 3c diagonal stairs ? | |
-- 80 npc, magirock? | |
-- a6 floating log in zue | |
-- destructible rocks id? | |
local ColorBlocked = 0x40FF0000 | |
local ColorBlockedOutline = 0x80FF0000 | |
local ColorWater = 0x800030FF | |
local ColorOther = 0x40FFFF00 | |
local ColorOtherOutline = 0x50FFFF00 | |
local ColorPassable = 0x2000FFFF | |
local ColorHighground = 0x2000FF00 | |
local tiles = {0x1c} | |
local camx = mainmemory.read_u16_le(0x080e) | |
local camy = mainmemory.read_u16_le(0x0812) | |
local playerx = mainmemory.read_u16_le(0x1000) | |
local playery = mainmemory.read_u16_le(0x1002) | |
local function getCollisionData() | |
camx = mainmemory.read_u16_le(0x080e) | |
camy = mainmemory.read_u16_le(0x0812) | |
playerx = mainmemory.read_u16_le(0x1000) | |
playery = mainmemory.read_u16_le(0x1002) | |
gui.drawText(0, 170, playerx) | |
gui.drawText(0, 200, playery) | |
local width = mainmemory.readbyte(0x0827)*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] = bit.band(mainmemory.readbyte(0xa001+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.drawBox(scrx+7,scry+3,scrx+9,scry+12,0xFF000000,0xFFFFFFFF) | |
end | |
local function renderArrowBodyHorizontal(scrx,scry) | |
gui.drawBox(scrx+3,scry+7,scrx+12,scry+9,0xFF0000FF,0xFFFFFFFF) | |
end | |
local function renderArrowHeadUp(scrx,scry) | |
scry = scry + 2 | |
gui.drawLine(scrx+5,scry+5,scrx+8,scry+2,0xFF000000) | |
gui.drawLine(scrx+11,scry+5,scrx+8,scry+2,0xFF000000) | |
gui.drawLine(scrx+7,scry+6,scrx+5,scry+6,0xFF000000) | |
gui.drawLine(scrx+9,scry+6,scrx+11,scry+6,0xFF000000) | |
gui.drawPixel(scrx+8,scry+3,0xFFFFFFFF) | |
gui.drawLine(scrx+7,scry+4,scrx+9,scry+4,0xFFFFFFFF) | |
gui.drawLine(scrx+6,scry+5,scrx+10,scry+5,0xFFFFFFFF) | |
end | |
local function renderArrowHeadDown(scrx,scry) | |
scry = scry - 2 | |
gui.drawLine(scrx+5,scry+10,scrx+8,scry+13,0xFF000000) | |
gui.drawLine(scrx+11,scry+10,scrx+8,scry+13,0xFF000000) | |
gui.drawLine(scrx+7,scry+9,scrx+5,scry+9,0xFF000000) | |
gui.drawLine(scrx+9,scry+9,scrx+11,scry+9,0xFF000000) | |
gui.drawPixel(scrx+8,scry+12,0xFFFFFFFF) | |
gui.drawLine(scrx+7,scry+11,scrx+9,scry+11,0xFFFFFFFF) | |
gui.drawLine(scrx+6,scry+10,scrx+10,scry+10,0xFFFFFFFF) | |
end | |
local function renderArrowHeadRight(scrx,scry) | |
scrx = scrx - 2 | |
gui.drawLine(scrx+10,scry+5,scrx+13,scry+8,0xFF000000) | |
gui.drawLine(scrx+10,scry+11,scrx+13,scry+8,0xFF000000) | |
gui.drawLine(scrx+9,scry+7,scrx+9,scry+5,0xFF000000) | |
gui.drawLine(scrx+9,scry+9,scrx+9,scry+11,0xFF000000) | |
gui.drawPixel(scrx+12,scry+8,0xFFFFFFFF) | |
gui.drawLine(scrx+11,scry+7,scrx+11,scry+9,0xFFFFFFFF) | |
gui.drawLine(scrx+10,scry+6,scrx+10,scry+10,0xFFFFFFFF) | |
end | |
local function renderArrowHeadLeft(scrx,scry) | |
scrx = scrx + 2 | |
gui.drawLine(scrx+5,scry+5,scrx+2,scry+8,0xFF000000) | |
gui.drawLine(scrx+5,scry+11,scrx+2,scry+8,0xFF000000) | |
gui.drawLine(scrx+6,scry+7,scrx+6,scry+5,0xFF000000) | |
gui.drawLine(scrx+6,scry+9,scrx+6,scry+11,0xFF000000) | |
gui.drawPixel(scrx+3,scry+8,0xFFFFFFFF) | |
gui.drawLine(scrx+4,scry+7,scrx+4,scry+9,0xFFFFFFFF) | |
gui.drawLine(scrx+5,scry+6,scrx+5,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 -- blocked tiles | |
gui.drawBox(scrx-1,scry-1,scrx+16,scry+16,0,ColorBlocked) | |
if not tileBlocked(x,y-1) then gui.drawLine(scrx,scry,scrx+15,scry,ColorBlockedOutline) end | |
if not tileBlocked(x,y+1) then gui.drawLine(scrx,scry+15,scrx+15,scry+15,ColorBlockedOutline) end | |
if not tileBlocked(x-1,y) then gui.drawLine(scrx,scry,scrx,scry+15,ColorBlockedOutline) end | |
if not tileBlocked(x+1,y) then gui.drawLine(scrx+15,scry,scrx+15,scry+15,ColorBlockedOutline) end | |
if not tileBlocked(x-1,y-1) then gui.drawPixel(scrx,scry,ColorBlockedOutline) end | |
if not tileBlocked(x+1,y+1) then gui.drawPixel(scrx+15,scry+15,ColorBlockedOutline) end | |
if not tileBlocked(x-1,y+1) then gui.drawPixel(scrx,scry+15,ColorBlockedOutline) end | |
if not tileBlocked(x+1,y-1) then gui.drawPixel(scrx+15,scry,ColorBlockedOutline) end | |
if tile == 0x18 then gui.drawText(scrx+6,scry+4,"?") end -- 18 is uncertain, see legend up top | |
elseif tile == 0x28 then | |
gui.drawText(scrx+7,scry+4,"X") | |
renderArrowHeadDown(scrx, scry + 3) | |
elseif tile == 0x04 or tile == 0x2c then -- passable terrain | |
gui.drawBox(scrx-1,scry-1,scrx+16,scry+16,0,ColorPassable) | |
elseif tile == 0x02 then -- highground | |
gui.drawBox(scrx-1,scry-1,scrx+16,scry+16,0,ColorHighground) | |
elseif tile == 0x3a then -- stairs | |
gui.drawBox(scrx-1,scry-1,scrx+16,scry+16,0,ColorPassable) | |
renderArrowHeadUp(scrx, scry - 2) | |
renderArrowHeadDown(scrx, scry + 2) | |
elseif tile == 0x26 then -- Water | |
gui.drawBox(scrx-1,scry-1,scrx+16,scry+16,0,ColorWater) | |
elseif tile==0x0c then -- leftdown/rightup | |
gui.drawLine(scrx+15,scry,scrx,scry+15,ColorBlockedOutline) | |
if tileCleared(x,y-1) and tileCleared(x-1,y) then | |
gui.drawLine(scrx+15,scry,scrx,scry,ColorBlockedOutline) | |
gui.drawLine(scrx,scry+1,scrx,scry+15,ColorBlockedOutline) | |
else | |
for i=14,0,-1 do gui.drawLine(scrx,scry+i,scrx+i,scry,ColorBlocked) end | |
end | |
if tileCleared(x,y+1) and tileCleared(x+1,y) then | |
gui.drawLine(scrx+15,scry,scrx+15,scry+15,ColorBlockedOutline) | |
gui.drawLine(scrx+14,scry+15,scrx,scry+15,ColorBlockedOutline) | |
else | |
for i=1,15 do gui.drawLine(scrx+i,scry+15,scrx+15,scry+i,ColorBlocked) end | |
end | |
elseif tile==0x0e then -- leftup/rightdown | |
gui.drawLine(scrx,scry,scrx+15,scry+15,ColorBlockedOutline) | |
if tileCleared(x,y-1) and tileCleared(x+1,y) then | |
gui.drawLine(scrx,scry,scrx+15,scry,ColorBlockedOutline) | |
gui.drawLine(scrx+15,scry+1,scrx+15,scry+15,ColorBlockedOutline) | |
else | |
for i=0,14 do gui.drawLine(scrx+i,scry+i,scrx+15,scry+i,ColorBlocked) end | |
end | |
if tileCleared(x,y+1) and tileCleared(x-1,y) then | |
gui.drawLine(scrx,scry,scrx,scry+15,ColorBlockedOutline) | |
gui.drawLine(scrx+1,scry+15,scrx+15,scry+15,ColorBlockedOutline) | |
else | |
for i=1,15 do gui.drawLine(scrx+0,scry+i,scrx+i,scry+i,ColorBlocked) end | |
end | |
elseif tile==0x10 or tile==0x34 or tile==0x36 then -- Fall/Vine/Crawl | |
gui.drawBox(scrx-1,scry-1,scrx+16,scry+16,0, 0x80000000) | |
if tileExists(x,y-1) and tiles[y-1][x]~=tile then gui.drawLine(scrx,scry,scrx+15,scry,0x000000FF) end | |
if tileExists(x,y+1) and tiles[y+1][x]~=tile then gui.drawLine(scrx,scry+15,scrx+15,scry+15,0x000000FF) end | |
if tileExists(x-1,y) and tiles[y][x-1]~=tile then gui.drawLine(scrx,scry,scrx,scry+15,0x000000FF) end | |
if tileExists(x+1,y) and tiles[y][x+1]~=tile then gui.drawLine(scrx+15,scry,scrx+15,scry+15,0x000000FF) end | |
renderArrowBody(scrx,scry) | |
if tile~=0x10 then renderArrowHeadUp(scrx,scry - 2) end | |
renderArrowHeadDown(scrx,scry + 2) | |
elseif tile ==0x3e then -- claw climb | |
gui.drawBox(scrx-1,scry-1,scrx+16,scry+16,0,0x80000000) | |
renderArrowHeadUp(scrx -4,scry- 3) | |
renderArrowHeadUp(scrx +3,scry+ 4) | |
elseif tile == 0x0a then -- push object | |
gui.drawBox(scrx-1,scry-1,scrx+16,scry+16,0,0x80000000) | |
renderArrowBodyHorizontal(scrx,scry) | |
renderArrowBody(scrx,scry) | |
renderArrowHeadLeft(scrx- 3,scry) | |
renderArrowHeadRight(scrx + 4,scry) | |
renderArrowHeadUp(scrx ,scry- 3) | |
renderArrowHeadDown(scrx ,scry+ 4) | |
elseif bit.band(tiles[y][x],0x80)~=0 then | |
gui.drawBox(scrx,scry,scrx+15,scry+15,0,0x80FF8000) | |
gui.drawText(scrx+2,scry+4,string.format("%02x",tile)) | |
else | |
gui.drawBox(scrx,scry,scrx+15,scry+15,0,0x80FF0000) | |
local tile = "??" | |
if tiles[y] and tiles[y][x] then tile = tiles[y][x] end | |
gui.drawText(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.drawBox(relx-8, rely-17,relx+7, rely-2, 0x8000FF00, 0x8000FF00) | |
gui.drawLine(relx-8, rely-9,relx+7, rely-9,0xFF0000FF) | |
gui.drawLine(relx, rely-2,relx, rely-17,0xFF000000FF) | |
end | |
local prevX = 0 | |
local prevY = 0 | |
local function getPositionData() | |
prevX = mainmemory.read_u16_le(0x1000) | |
prevY = mainmemory.read_u16_le(0x1002) | |
end | |
local dX = 0 | |
local dY = 0 | |
local function getDisplacementData() | |
dX = prevX - mainmemory.read_u16_le(0x1000) | |
dY = prevY - mainmemory.read_u16_le(0x1002) | |
end | |
local function showDisplacement() | |
if dX<0 then | |
gui.drawText(playerx-camx+11,playery-camy-12,-dX,0xFF00FF00) | |
elseif dX>0 then | |
gui.drawText(playerx-camx-14,playery-camy-12,dX,0xFF00FF00) | |
end | |
if dY<0 then | |
gui.drawText(playerx-camx-1,playery-camy+1,-dY,0xFF00FF00) | |
elseif dY>0 then | |
gui.drawText(playerx-camx-1,playery-camy-26,dY,0xFF00FF00) | |
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 | |
while true do | |
my_display() | |
emu.frameadvance() | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment