Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Example: {x,y,width}
- local tower = {}
- local x,y,i,w = 1,1,1,3
- local delay = 0.1
- local MaxX,MaxY = term.getSize()
- function Draw()
- term.setTextColour(colors.black)
- term.setBackgroundColour(colors.white)
- term.clear()
- -- Tower
- for i,u in pairs(tower) do
- paintutils.drawLine(u[1],MaxY-u[2], u[1]+u[3],MaxY-u[2], colors.blue)
- end
- --platform
- paintutils.drawLine(x,MaxY-y, x+w,MaxY-y, colors.blue)
- end
- function Move()
- x = x+i
- if (x+w > MaxX) then
- x = MaxX-w
- i = -1
- elseif (x<1) then
- x = 1
- i = 1
- end
- end
- function Logic()
- if (#tower == 0) then
- return w
- end
- local last = tower[#tower]
- if (x<last[1]) then
- return w - 1
- elseif((x+w)>(last[1]+last[3])) then
- return w - 1
- end
- return w
- end
- while (true) do
- parallel.waitForAny(function()
- while(true) do
- if (w <= 0) then
- error("Game Over")
- elseif (y==MaxY) then
- error("Winner!")
- end
- Move()
- Draw()
- sleep(delay)
- end
- end,
- function()
- os.pullEvent("key")
- local nW = Logic()
- table.insert(tower, {x,y,w})
- w = nW
- y = y+1
- x=0
- delay = delay - 0.01
- end
- )
- end
Advertisement
Add Comment
Please, Sign In to add comment