shell.run("clear")
function checkforWalls()
x = 1
while true do
if walls[x][1] == wanttox and walls[x][2] == wanttoy then return false end
if walls[x] == nil then return true end
x = x + 1
end
end
function move()
wanttodir = math.random(1,4)
if wanttodir == 1 then wanttox = xpos wanttoy = ypos - 1 end
if wanttodir == 2 then wanttox = xpos wanttoy = ypos + 1 end
if wanttodir == 3 then wanttox = xpos - 1 wanttoy = ypos end
if wanttodir == 4 then wanttox = xpos + 1 wanttoy = ypos end
if checkforWalls() then
xpos = wanttox
ypos = wanttoy
end
end
function load()
shell.run(read())
end
function draw()
term.setBackgroundColor(colors.green)
term.clear()
term.setCursorPos(1,1)
x = 1
while true do
term.setBackgroundColor(colors.red)
term.setCursorPos(walls[x][1],walls[x][2])
term.write("X")
x = x + 1
if walls[x] == nil then break end
end
end
function drawBug()
term.setCursorPos(xpos,ypos)
term.setBackgroundColor(colors.blue)
term.write("#")
end
load()
while true do
term.setBackgroundColor(colors.black)
draw()
term.setBackgroundColor(colors.black)
drawBug()
term.setBackgroundColor(colors.black)
move()
sleep(0,5)
end
level program:
walls = {{1,1},{1,2},{1,3},{1,4},{1,5},{2,5},{3,5},{4,5},{5,5},{5,4},{5,3},{5,2},{5,1},{4,1},{3,1},{2,1}}
xPos = 2
yPos = 2
I started the program and entered the name of the level program. and then this error came:
[string "window"]:247: bad argument #1 to 'floor' (number expected, got nil)
Here's a short video:
Download