paramus

Brick tower

Aug 26th, 2025 (edited)
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.35 KB | None | 0 0
  1. --Example: {x,y,width}
  2. local tower = {}
  3. local x,y,i,w = 1,1,1,3
  4. local delay = 0.1
  5. local MaxX,MaxY = term.getSize()
  6.  
  7. function Draw()
  8.     term.setTextColour(colors.black)
  9.     term.setBackgroundColour(colors.white)
  10.     term.clear()
  11.    
  12.     -- Tower
  13.     for i,u in pairs(tower) do
  14.         paintutils.drawLine(u[1],MaxY-u[2], u[1]+u[3],MaxY-u[2], colors.blue)
  15.     end
  16.    
  17.     --platform
  18.     paintutils.drawLine(x,MaxY-y, x+w,MaxY-y, colors.blue)
  19. end
  20.  
  21. function Move()
  22.     x = x+i
  23.     if (x+w > MaxX) then
  24.         x = MaxX-w
  25.         i = -1
  26.     elseif (x<1) then
  27.         x = 1
  28.         i = 1
  29.     end
  30. end
  31.  
  32. function Logic()
  33.     if (#tower == 0) then
  34.         return w
  35.     end
  36.    
  37.     local last = tower[#tower]
  38.     if (x<last[1]) then
  39.         return w - 1
  40.     elseif((x+w)>(last[1]+last[3])) then
  41.         return w - 1
  42.     end
  43.    
  44.     return w
  45. end
  46.  
  47. while (true) do
  48.     parallel.waitForAny(function()
  49.         while(true) do
  50.             if (w <= 0) then
  51.                 error("Game Over")
  52.             elseif (y==MaxY) then
  53.                 error("Winner!")
  54.             end
  55.             Move()
  56.             Draw()
  57.             sleep(delay)
  58.         end
  59.     end,
  60.     function()
  61.         os.pullEvent("key")
  62.         local nW = Logic()
  63.         table.insert(tower, {x,y,w})
  64.         w = nW
  65.         y = y+1
  66.         x=0
  67.         delay = delay - 0.01
  68.     end
  69.     )
  70. end
Advertisement
Add Comment
Please, Sign In to add comment