yeeeeeeeeeeeee

part 2

Mar 20th, 2025
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.23 KB | None | 0 0
  1. local width, height = 20, 10 -- Size of the drawing grid
  2. local grid = {}
  3. for y = 1, height do
  4.     grid[y] = {}
  5.     for x = 1, width do
  6.         grid[y][x] = " " -- Empty cell
  7.     end
  8. end
  9. local cursorX, cursorY = 1, 1 -- Starting cursor position
  10. local function drawGrid()
  11.     term.clear()
  12.     term.setCursorPos(1, 1)
  13.     for y = 1, height do
  14.         for x = 1, width do
  15.             if x == cursorX and y == cursorY then
  16.                 term.write("X")
  17.             else
  18.                 term.write(grid[y][x])
  19.             end
  20.         end
  21.         print()
  22.     end
  23. end
  24. local function saveArt(filename)
  25.     local file = fs.open(filename, "w")
  26.     for y = 1, height do
  27.         file.writeLine(table.concat(grid[y]))
  28.     end
  29.     file.close()
  30.     print("Drawing saved as " .. filename)
  31. end
  32. local function loadArt(filename)
  33.     if not fs.exists(filename) then
  34.         print("File not found.")
  35.         return
  36.     end
  37.     local file = fs.open(filename, "r")
  38.     for y = 1, height do
  39.         local line = file.readLine()
  40.         for x = 1, #line do
  41.             grid[y][x] = line:sub(x, x)
  42.         end
  43.     end
  44.     file.close()
  45.     print("Drawing loaded!")
  46. end
  47. while true do
  48.     drawGrid()
  49.     print("Controls: WASD to move, Space to draw, C to clear, Save, Load, Exit")
  50.     write("Command: ")
  51.     local input = read()
  52.     if input == "w" and cursorY > 1 then
  53.         cursorY = cursorY - 1
  54.     elseif input == "s" and cursorY < height then
  55.         cursorY = cursorY + 1
  56.     elseif input == "a" and cursorX > 1 then
  57.         cursorX = cursorX - 1
  58.     elseif input == "d" and cursorX < width then
  59.         cursorX = cursorX + 1
  60.     elseif input == " " then
  61.         grid[cursorY][cursorX] = "#"
  62.     elseif input == "c" then
  63.         for y = 1, height do
  64.             for x = 1, width do
  65.                 grid[y][x] = " "
  66.             end
  67.         end
  68.         print("Canvas cleared.")
  69.     elseif input == "save" then
  70.         write("Enter filename: ")
  71.         local filename = read()
  72.         saveArt(filename)
  73.     elseif input == "load" then
  74.         write("Enter filename: ")
  75.         local filename = read()
  76.         loadArt(filename)
  77.     elseif input == "exit" then
  78.         break
  79.     else
  80.         print("Unknown command.")
  81.     end
  82. end
  83.  
Add Comment
Please, Sign In to add comment