Posted 18 December 2014 - 03:40 AM
I'm currently making a game called 'stacker', which I first encountered on miniclip. However, I've got a glitch that I cannot get rid of, and I have no idea why it happens. It only happens on the second line, once I'm above that I cannot reproduce the behavior. Basically, if you manage to get it perfectly aligned, it cuts off the last pixel on the right:
[attachment=2013:Screen Shot 2014-12-17 at 9.33.24 PM.png]
[attachment=2013:Screen Shot 2014-12-17 at 9.33.24 PM.png]
My messey and very much unfinished code
local stack = {}
local maxx, maxy = term.getSize()
local nSize = 8
local bNew = true
stack[ 0 ] = { maxx/2 - 4, maxx/2 + 4 }
function renderStack()
term.setBackgroundColor( colors.white )
for i = 0, #stack do
term.setCursorPos( stack[ i ][ 1 ], maxy - i )
term.write( string.rep( " ", stack[ i ][2] - stack[ i ][1] ) )
end
term.setBackgroundColor( colors.black )
end
function getInput()
local new = bNew and { 1, nSize + 1 } or stack[ #stack ]
local id = os.startTimer( 0.1 )
while true do
local event = { os.pullEvent() }
if event[ 1 ] == "timer" and event[ 2 ] == id then
new[ 1 ] = new[ 1 ] + 1
new[ 2 ] = new[ 2 ] + 1
if bNew then
stack[ #stack + 1 ] = new
bNew = false
end
break
elseif event[ 1 ] == "key" and event[ 2 ] == keys.space then
if new[ 1 ] < ( bNew and stack[ #stack ][ 1 ] or stack[ #stack - 1 ][ 1 ] ) then
new[ 1 ] = ( bNew and stack[ #stack ][ 1 ] or stack[ #stack - 1 ][ 1 ] )
end
if new[ 2 ] > ( bNew and stack[ #stack ][ 2 ] or stack[ #stack - 1 ][ 2 ] ) then
new[ 2 ] = ( bNew and stack[ #stack ][ 2 ] or stack[ #stack - 1 ][ 2 ] )
end
if new[ 2 ] - new[ 1 ] <= 0 then
error( "Game Over", 0 )
end
nSize = new[ 2 ] - new[ 1 ]
if bNew then
stack[ #stack + 1 ] = new
else
stack[ #stack ] = new
bNew = true
end
break
end
end
end
while true do
term.clear()
renderStack()
getInput()
end