Somewhat proper working script :)
This commit is contained in:
parent
fc80518568
commit
81d4767443
|
@ -1,12 +1,15 @@
|
||||||
-- unfinished mario bros 2 script
|
-- unfinished mario bros 2 script
|
||||||
-- shows (proper!) grid for horizontal levels (b0rks in vertical levels for now)
|
-- shows (proper!) grid and contents. disable grid by setting variable to false
|
||||||
-- shows any non-air grid's tile-id
|
-- shows any non-air grid's tile-id
|
||||||
-- is sloooow :p
|
-- can be heavy on light systems
|
||||||
|
|
||||||
-- Super Mario Bros. 2 (U) (PRG0) [!].rom
|
-- Super Mario Bros. 2 (U) (PRG0) [!].rom
|
||||||
-- qFox
|
-- qFox
|
||||||
-- 31 july 2008
|
-- 31 july 2008
|
||||||
|
|
||||||
|
local angrybirdo = false; -- makes birdo freak, but can skew other creatures with timing :)
|
||||||
|
local drawgrid = true; -- draws a green grid
|
||||||
|
|
||||||
local function box(x1,y1,x2,y2,color)
|
local function box(x1,y1,x2,y2,color)
|
||||||
-- gui.text(50,50,x1..","..y1.." "..x2..","..y2);
|
-- gui.text(50,50,x1..","..y1.." "..x2..","..y2);
|
||||||
if (x1 > 0 and x1 < 0xFF and x2 > 0 and x2 < 0xFF and y1 > 0 and y1 < 239 and y2 > 0 and y2 < 239) then
|
if (x1 > 0 and x1 < 0xFF and x2 > 0 and x2 < 0xFF and y1 > 0 and y1 < 239 and y2 > 0 and y2 < 239) then
|
||||||
|
@ -24,7 +27,7 @@ local function toHexStr(n)
|
||||||
end;
|
end;
|
||||||
|
|
||||||
while (true) do
|
while (true) do
|
||||||
if (memory.readbyte(0x0010) > 0x81) then memory.writebyte(0x0010, 0x6D); end; -- birdo fires eggs constantly :p
|
if (angrybirdo and memory.readbyte(0x0010) > 0x81) then memory.writebyte(0x0010, 0x6D); end; -- birdo fires eggs constantly :p
|
||||||
|
|
||||||
-- px = horzizontal page of current level
|
-- px = horzizontal page of current level
|
||||||
-- x = page x (relative to current page)
|
-- x = page x (relative to current page)
|
||||||
|
@ -50,12 +53,84 @@ while (true) do
|
||||||
box(playersx, playersy, playersx+16, playersy+16, "green");
|
box(playersx, playersy, playersx+16, playersy+16, "green");
|
||||||
end;
|
end;
|
||||||
|
|
||||||
text(2,10,"x:"..screenoffsetx);
|
if (memory.readbyte(0x00D8) == 0) then -- not scrolling vertically
|
||||||
text(2,25,"y: "..screenoffsety);
|
-- show environment
|
||||||
|
-- i have playerrx, which is my real position in this level
|
||||||
|
-- i have the level, which is located at 0x6000 (the SRAM)
|
||||||
|
-- each tile (denoted by one byte) is 16x16 pixels
|
||||||
|
-- each screen is 15 tiles high and about 16 tiles wide
|
||||||
|
-- to get the right column, we add our playerrx/16 to 0x6000
|
||||||
|
-- to be exact:
|
||||||
|
-- 0x6000 + (math.floor(playerrx/16) * 0xF0) + math.mod(playerx,0x0F)
|
||||||
|
|
||||||
|
local levelstart = 0x6000; -- start of level layout in RAM
|
||||||
|
|
||||||
|
-- ok, here we have two choices. either this is a horizontal level or
|
||||||
|
-- it is a vertical level. We have no real way of checking this, but
|
||||||
|
-- luckily levels are either horizontal or vertical :)
|
||||||
|
-- so there are three possibilities
|
||||||
|
-- 1: you're in 0:0, no worries
|
||||||
|
-- 2: you're in x:0, you're in a horizontal level
|
||||||
|
-- 3: you're in 0:y, you're in a vertical level
|
||||||
|
|
||||||
|
|
||||||
|
local addleftcrap = math.mod(screenoffsetx,16)*-1; -- works as padding to keep the grid aligned
|
||||||
|
local leftsplitrx = (memory.readbyte(0x04BE)*0x100) + (screenoffsetx + addleftcrap); -- column start left. add addleftcrap to iterative stuff to build up
|
||||||
|
local addtopcrap = math.mod(screenoffsety,15); -- works as padding to keep the grid aligned
|
||||||
|
local columns = math.floor(leftsplitrx/16); -- column x of the level is on the left side of the screen
|
||||||
|
|
||||||
|
if (drawgrid) then -- print grid?
|
||||||
|
for i=0,15 do
|
||||||
|
-- text(addleftcrap+(i*16)-1, 37, toHexStr(columns+i)); -- print colnumber in each column
|
||||||
|
for j=0,17 do
|
||||||
|
box(addleftcrap+(i*16), addtopcrap+(j*16), addleftcrap+(i*16)+16, addtopcrap+(j*16)+16, "green"); -- draw green box for each cell
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
-- 42=mushroom if you go sub
|
||||||
|
-- 45=small
|
||||||
|
-- 44=big
|
||||||
|
-- 49=subspace
|
||||||
|
-- 6c=pow
|
||||||
|
-- 4e=cherry
|
||||||
|
|
||||||
|
local topsplitry = (screenoffsety);
|
||||||
|
|
||||||
|
-- starting page (might flow into next page). if the number of columns
|
||||||
|
-- is > 16, its a horizontal level, else its a vertical level. in either
|
||||||
|
-- case, the other will not up this value.
|
||||||
|
local levelpage =
|
||||||
|
levelstart +
|
||||||
|
((math.floor(columns/16))*0xF0) +
|
||||||
|
(memory.readbyte(0x00CA)*0x100) +
|
||||||
|
topsplitry;
|
||||||
|
local levelcol = math.mod(columns,16); -- this is our starting column
|
||||||
|
|
||||||
|
--text(10,150,toHexStr(topsplitry).." "..toHexStr(levelcol).." "..toHexStr(levelpage+levelcol).." "..toHexStr(leftsplitrx));
|
||||||
|
|
||||||
|
for j=0,15 do -- 16 columns
|
||||||
|
if (levelcol + j > 15) then -- go to next page
|
||||||
|
levelpage = levelpage + 0xF0;
|
||||||
|
levelcol = -j;
|
||||||
|
end;
|
||||||
|
for i=0,14 do -- 15 rows
|
||||||
|
local tile = memory.readbyte(levelpage+(levelcol+j)+(i*0x10));
|
||||||
|
if (tile ~= 0x40) then
|
||||||
|
text(-2+addleftcrap+(j*16),5+(i*16),toHexStr(tile));
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end; -- not scrolling if
|
||||||
|
|
||||||
|
-- print some generic stats
|
||||||
|
text(2,10,"x:"..toHexStr(screenoffsetx));
|
||||||
|
text(2,25,"y: "..toHexStr(screenoffsety));
|
||||||
text(230,10,memory.readbyte(0x04C1));
|
text(230,10,memory.readbyte(0x04C1));
|
||||||
text(100,10,"Page: "..playerpx..","..playerpy);
|
text(100,10,"Page: "..playerpx..","..playerpy);
|
||||||
text(playersx,playersy,playerrx.."\n"..playery);
|
text(playersx,playersy,playerrx.."\n"..playery);
|
||||||
|
|
||||||
|
-- draw enemy info
|
||||||
local startpx = 0x0015;
|
local startpx = 0x0015;
|
||||||
local startpy = 0x001F;
|
local startpy = 0x001F;
|
||||||
local startx = 0x0029;
|
local startx = 0x0029;
|
||||||
|
@ -89,40 +164,8 @@ while (true) do
|
||||||
box(esx, esy, esx+16, esy+16, "blue");
|
box(esx, esy, esx+16, esy+16, "blue");
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end; -- enemy info
|
end;
|
||||||
|
end; -- enemy info
|
||||||
|
|
||||||
-- show environment
|
|
||||||
-- i have playerrx, which is my real position in this level
|
|
||||||
-- i have the level, which is located at 0x6000 (the SRAM)
|
|
||||||
-- each tile (denoted by one byte) is 16x16 pixels
|
|
||||||
-- each screen is 15 tiles high and about 16 tiles wide
|
|
||||||
-- to get the right column, we add our playerrx/16 to 0x6000
|
|
||||||
-- to be exact:
|
|
||||||
-- 0x6000 + (math.floor(playerrx/16) * 0xF0) + math.mod(playerx,0x0F)
|
|
||||||
|
|
||||||
local levelstart = 0x6000; -- start of level layout in RAM
|
|
||||||
local addleftcrap = math.mod(screenoffsetx,16)*-1;
|
|
||||||
local leftsplitrx = (memory.readbyte(0x04BE)*0xFF) + (screenoffsetx + addleftcrap); -- column start left. add addleftcrap to iterative stuff to build up
|
|
||||||
local columns = leftsplitrx/16; -- column x of the level is on the left side of the screen
|
|
||||||
|
|
||||||
for i=0,15 do
|
|
||||||
text(addleftcrap+(i*16)-1, 37, toHexStr(columns+i));
|
|
||||||
for j=0,17 do
|
|
||||||
box(addleftcrap+(i*16), 1+(j*16), addleftcrap+(i*16)+16, 1+(j*16)+16, "green");
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
local columntop = levelstart + ((math.floor(columns/16))*0xF0) + math.mod(columns,16);
|
|
||||||
text(10,80,toHexStr(columns).." "..toHexStr(columntop));
|
|
||||||
for i=0,14 do
|
|
||||||
for j=0,15 do
|
|
||||||
local tile = memory.readbyte(columntop+(i*0x10)+j);
|
|
||||||
if (tile ~= 0x40) then
|
|
||||||
text(-2+addleftcrap+(j*16),21+(i*16),toHexStr(tile));
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
end;
|
|
||||||
FCEU.frameadvance();
|
FCEU.frameadvance();
|
||||||
end;
|
end;
|
Loading…
Reference in New Issue