ElijahCrafter

Block Blast

Jul 12th, 2026 (edited)
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.99 KB | Source Code | 0 0
  1. -- Tetris-style Block Puzzle for CC: Tweaked - Simplified Debug Version
  2.  
  3. local GRID_SIZE = 6
  4. local grid = {}
  5. local score = 0
  6. local gameOver = false
  7. local selectedPiece = nil
  8. local nextPieces = {}
  9.  
  10. local PIECE_SHAPES = {
  11.   {{{1, 1}}},
  12.   {{{1, 1}, {1, 1}}},
  13.   {{{1, 1, 1}}},
  14. }
  15.  
  16. local function initGrid()
  17.   for y = 1, GRID_SIZE do
  18.     grid[y] = {}
  19.     for x = 1, GRID_SIZE do
  20.       grid[y][x] = false
  21.     end
  22.   end
  23. end
  24.  
  25. local function generateNextPieces()
  26.   nextPieces = {}
  27.   for i = 1, 3 do
  28.     table.insert(nextPieces, PIECE_SHAPES[math.random(#PIECE_SHAPES)])
  29.   end
  30. end
  31.  
  32. local function drawGrid()
  33.   term.clear()
  34.   term.setCursorPos(1, 1)
  35.  
  36.   print("=== BLOCK PUZZLE ===")
  37.   print("Score: " .. score)
  38.   print("")
  39.  
  40.   -- Draw grid
  41.   for y = 1, GRID_SIZE do
  42.     write("|")
  43.     for x = 1, GRID_SIZE do
  44.       if grid[y][x] then
  45.         write("##")
  46.       else
  47.         write("  ")
  48.       end
  49.     end
  50.     print("|")
  51.   end
  52.  
  53.   print("")
  54.   print("Commands:")
  55.   print("1/2/3 = Select piece")
  56.   print("Click grid = Place piece")
  57.   print("Q = Quit")
  58.  
  59.   if selectedPiece then
  60.     print("")
  61.     print("SELECTED: Piece " .. selectedPiece)
  62.   end
  63. end
  64.  
  65. local function main()
  66.   initGrid()
  67.   generateNextPieces()
  68.  
  69.   print("Starting game...")
  70.   os.sleep(1)
  71.  
  72.   while not gameOver do
  73.     drawGrid()
  74.  
  75.     local event, param, x, y = os.pullEvent()
  76.  
  77.     if event == "key" then
  78.       if param == keys.q then
  79.         gameOver = true
  80.       elseif param == keys.one then
  81.         selectedPiece = 1
  82.       elseif param == keys.two then
  83.         selectedPiece = 2
  84.       elseif param == keys.three then
  85.         selectedPiece = 3
  86.       end
  87.     elseif event == "mouse_click" then
  88.       if selectedPiece and nextPieces[selectedPiece] then
  89.         grid[y - 2][math.floor(x / 2)] = true
  90.       end
  91.     elseif event == "terminate" then
  92.       gameOver = true
  93.     end
  94.   end
  95.  
  96.   term.clear()
  97.   term.setCursorPos(1, 1)
  98.   print("Game Over!")
  99.   print("Final Score: " .. score)
  100. end
  101.  
  102. main()
  103.  
Advertisement
Add Comment
Please, Sign In to add comment