Posted 12 December 2014 - 12:44 AM
It is somehow impossible to die in this hitbox testing thingy I did. I'm not sure how, or why it's not registering, but it's not.
Spoiler
local baddies = {}
local maxx, maxy = term.getSize()
for i = 1, maxx, 3 do
baddies[ #baddies + 1 ] = {x = i, y = math.random( 1, maxy / 2 ), v = math.random( 1, 3 ) }
end
local player = { x = maxx/2, y = maxy - 3 }
function drawPlayer()
term.setBackgroundColor( colors.green )
term.setCursorPos( player.x, player.y )
term.write( " " )
end
local id
while true do
id = os.startTimer( 0.01 )
term.setBackgroundColor( colors.black )
term.clear()
drawPlayer()
term.setBackgroundColor( colors.red )
for _, bad in ipairs( baddies ) do
local doesMove = math.random( 0, bad.v ) ~= 0
bad.y = bad.y + (doesMove and 1 or 0)
if bad.y > maxy then
bad.y = 1
bad.x = bad.x + math.random( -1, 1 )
end
term.setCursorPos( bad.x, bad.y )
term.write( " " )
if bad.y == player.y and bad.x == player.x then
term.setBackgroundColor( colors.red )
term.clear()
term.setTextColor( colors.black )
term.setCursorPos( 1, 1 )
print( "You lose!" )
error()
end
end
while true do
local event = {os.pullEvent()}
if event[ 1 ] == 'timer' and event[ 2 ] == id then
break
elseif event[ 1 ] == 'key' and event[ 2 ] == keys.right then
player.x = player.x + 1
if player.x > maxx then
player.x = maxx
end
elseif event[ 1 ] == 'key' and event[ 2 ] == keys.left then
player.x = player.x - 1
if player.x < 1 then
player.x = 1
end
end
end
end