ÎÌÌÌ̈ˆˆ¬ªªª¬ˆˆˆ¬ÌÌ̬ÌÀ̬ÌÀ̬ÌÀÌÌÌìÌÀÀî̬ÀÌÀ¬ÀÀÀ¬ÀÀÀ¬ÀÀÎÌÌÌ̈ˆˆ¬ªªª¬ˆˆˆ¬ÌÌ̬ÌÌ̬ÌÀ̬ÌÀÌÌÌìÌÀÀî̬ÀÌ̬ÀÀÀ¬ÀÀÀ¬ÀÀ¬ÌÌ̬ªªª¬ª¬ª¬ªÊ̬ªªªŒˆˆˆÌÀÌÎÌÌÎ̬̪ªÀ쬪ÀÀÀÌîÀìîÌÌîî¬ÌÌ̬ªªª¬ª¬ª¬ªÊ̬ªªªŒˆˆˆÌÀÌÎÌÌÎ̬̪ªÀ쬪ÀÀÀÌîÀìîÌÌîî >S°» »»» » ° °» » ° ° °° °° ° °°»° ° °° °»° °» ° °»»° °° ° °»»° ° °» ° °» »»»»»» °» °» »» »»» »»°» °»»»»»» » »» » »° ° °°»»» » ° » » »»°»°»° ° ° °» »» » ° »»»»»» » »° ° °°»»»» »»° »» »» »»»»»» ° » °» »» » ° q-- title: STACKO -- author: Jesse Cochran (With Help From ChatGPT) -- desc: A block stacking game for TIC-80 -- script: lua -- Stacko - TIC-80 Port -- Constants WIDTH, HEIGHT = 35, 15 -- Grid size grid = {} block = {x = WIDTH // 2, y = 0} blockChar = "#" gridChar = "." laserChar = "|" blockSpeed = 15 -- Speed of movement direction = 1 -- 1 = Right, -1 = Left score = 0 gameOver = false lastDropTime = 0 timeLimit = 600 -- 10 seconds in frames (60FPS * 10) currentTime = 0 defaultSpeed = 15 -- Reset speed gameStarted = false gamePhase = "logo" -- Prevent early movement -- Initialize Grid function initGrid() for y = 1, HEIGHT do grid[y] = {} for x = 1, WIDTH do grid[y][x] = gridChar end end end -- Draw the Grid function drawGrid() for y = 1, HEIGHT do for x = 1, WIDTH do if (y == block.y and x == block.x) or (y == 1 and x == block.x) then print(blockChar, x * 6 + 10, y * 6 + 20, 12) elseif grid[y][x] == blockChar then print(blockChar, x * 6 + 10, y * 6 + 20, 12) else print(gridChar, x * 6 + 10, y * 6 + 20, 7) end end end print("SCORE: "..score, 2, 2, 15) print("TIME: "..math.max(0, timeLimit - currentTime), 2, 12, 15) if gameOver then print("GAME OVER!", WIDTH * 3, HEIGHT * 6 + 30, 11) end end -- Move Block function moveBlock() if gameOver or not gameStarted then return end block.x = math.max(1, math.min(WIDTH, block.x + direction)) if block.x <= 1 or block.x >= WIDTH then direction = -direction -- Change direction at edges end end -- Drop Block function dropBlock() if gameOver or not gameStarted then return end currentTime = 0 -- Reset timer on block drop local bx = block.x local by = 1 while by < HEIGHT and grid[by + 1][bx] == gridChar do by = by + 1 end grid[by][bx] = blockChar block.y = 0 block.x = bx direction = -direction score = score + 1 checkRows() -- Check if a column is full to the top local columnFull = true for y = 1, HEIGHT do if grid[y][bx] == gridChar then columnFull = false break end end if columnFull then gameOver = true end end -- Check for full rows and clear them function checkRows() for y = HEIGHT, 1, -1 do local full = true for x = 1, WIDTH do if grid[y][x] ~= blockChar then full = false break end end if full then for yy = y, 2, -1 do grid[yy] = grid[yy - 1] end grid[1] = {} for x = 1, WIDTH do grid[1][x] = gridChar end score = score * 2 -- Bonus for clearing end end end -- Restart the Game function restartGame() gameOver = false score = 0 initGrid() block.x = WIDTH // 2 block.y = 0 direction = 1 blockSpeed = defaultSpeed currentTime = 0 timeLimit = 600 -- Reset timer gameStarted = false end -- TIC-80 Update Function function TIC() -- Clear screen and draw instructions cls(0) if gamePhase == "logo" then print("S T A C K O", 90, 30, 11) print("PRESS Z TO START", 80, 60, 11) if btnp(4) then gamePhase = "instructions" end return elseif gamePhase == "instructions" then cls(0) print("HOW TO PLAY:", 50, 20, 11) print("- Block moves side to side", 50, 30, 11) print("- Press Z to drop block", 50, 40, 11) print("- Fill rows to clear them", 50, 50, 11) print("- Score increases as you play", 50, 60, 11) print("- Time resets with each drop", 50, 70, 11) print("- Press X to restart", 50, 80, 11) print("PRESS Z TO CONTINUE", 50, 100, 11) if btnp(4) then gamePhase = "game"; gameStarted = true end return end currentTime = currentTime + 1 if currentTime >= timeLimit then gameOver = true end if not gameOver then if currentTime % blockSpeed == 0 then moveBlock() end if btnp(5) then dropBlock() end -- Z button (Drop block) else if btnp(4) then restartGame() end -- X button (Restart) end drawGrid() end initGrid()