--Tengen Tetris Lua by Blazephlozard and Spikestuff
--If you want to use this for something other than "30 lines" and need help
--feel free to message me on Discord: Blazephlozard#8042
upcomingBlocks = {}
upcomingTotals = { 0, 0, 0, 0, 0, 0, 0 }
longestDrought = 0
currentDrought = 0
--[[
1 - I
2 - T
3 - O
4 - J
5 - L
6 - S
7 - Z
]]
names = { "I", "T", "O", "J", "L", "S", "Z" }
drawings = {"####", "###\n # ", "##\n##", "###\n #", "###\n#", " ##\n##", "##\n ##"}
drawingBoxes = {
{ 1, 1, 1, 1,
0, 0, 0, 0},
{1, 1, 1, 0,
0, 1, 0, 0},
{1, 1, 0, 0,
1, 1, 0, 0},
{1, 1, 1, 0,
0, 0, 1, 0},
{1, 1, 1, 0,
1, 0, 0, 0},
{0, 1, 1, 0,
1, 1, 0, 0},
{1, 1, 0, 0,
0, 1, 1, 0}
}
-- https://en.wikipedia.org/wiki/X11_color_names these work
colors = { "firebrick", "gold", "royalblue", "orange", "violet", "limegreen", "darkcyan" }
prevRNG = 0
initialBlocks = 0
allowScript = true
--Brute force make a list of 80 upcoming blocks (80 blocks = 320 blocks = 32 lines worth)
function makeList()
savestate.saveslot(0)
if (tastudio.engaged()) then tastudio.setplayback(50) end
for i=1,7 do
initialBlocks = initialBlocks + memory.readbyte(0x0052+i)
end
client.speedmode(6399) --maximum?
client.unpause()
local maxPieces = 80
for counter=1,maxPieces do
prevRNG = memory.read_u16_le(0x005C)
curPiece = memory.readbyte(0x0066)
upcomingBlocks[counter] = curPiece
upcomingTotals[curPiece] = upcomingTotals[curPiece] + 1
--I drought
if (curPiece ~= 1) then
currentDrought = currentDrought + 1
if (currentDrought > longestDrought) then longestDrought = currentDrought end
--I drought ended
else
print("drought of " .. currentDrought)
currentDrought = 0
end
while (true) do
memory.write_u8(0x0060, 25)
curRNG = memory.read_u16_le(0x005C)
if (prevRNG ~= curRNG) then
break
end
prevRNG = curRNG
gui.drawText(175, 120, counter .. "/" .. maxPieces, null, 0x00000000, 16, "Courier New")
emu.frameadvance()
end
end
--Forcibly clear the greenzone, because our cheat can linger in tastudio states
if (tastudio.engaged()) then
tastudio.submitinsertframes(40,1)
tastudio.submitdeleteframes(40,1)
tastudio.applyinputchanges()
end
savestate.loadslot(0)
client.speedmode(100)
print("Block totals:")
for i=1,7 do
print(names[i] .. ": " .. upcomingTotals[i])
end
print("Longest I-piece drought: " .. longestDrought)
client.pause()
end
function doTheDraw(block, xpos, ypos)
for i=1,8 do
if (drawingBoxes[block][i] == 1) then
local theColor = colors[block]
local theX = xpos
local theY = ypos
if (i >= 5) then theY = theY + 6 end
--special I-block x and y shifting
if (block == 1) then
theX = theX - 3
theY = theY + 3
end
gui.drawRectangle(theX + ((i-1)%4)*6,theY,5,5,theColor,theColor)
end
end
end
--allowScript = false
makeList()
--for testing
--[[for counter=1,80 do
upcomingBlocks[counter] = counter%7 + 1
end]]
while (allowScript) do
--003D = 64 when not in menus, as far as we can tell
if (memory.readbyte(0x003D) == 64 or memory.readbyte(0x003D) == 6) and (memory.readbyte(0x067C) ~= 30) then
--Cover up where we're putting info
gui.drawRectangle(112,80,30,144,"black","black")
gui.drawRectangle(112,200,60,24,"black","black")
--spikestuff stuff (border line, NEXT text, cover up base game next
gui.drawBox(160,65,240,224,"black","black");
gui.drawLine(16,65,96,65,"red");
gui.pixelText(112,80,"NEXT","red","clear");
gui.drawBox(16,16,49,39,"black","black");
--
local totalBlocks = -initialBlocks + 1
for i=1,7 do
totalBlocks = totalBlocks + memory.readbyte(0x0052+i)
gui.drawText(160, 80+(i-1)*15, names[i] .. ": " .. memory.readbyte(0x0052+i), null, 0x00000000, 16, "Courier New")
end
--[[test
for i=1,7 do
gui.text(55+(i*50),40,drawings[i], colors[i])
end]]
for i=1,10 do
temp = totalBlocks+i-1
if (temp <= 80 and temp > 0) then
num = upcomingBlocks[temp]
--gui.text(55+(i*50),40,drawings[num], colors[num])
local xpos = 120
local ypos = 87+(i-1)*24
if (i >= 7) then
xpos = 124 + (i-6)*24
ypos = 87 + 5*24
end
doTheDraw(num, xpos, ypos)
--gui.drawRectangle(55+(i*50),40,10,10,"red","red")
end
end
end
emu.frameadvance()
end