Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Stacc, An game.
- -- Written by djm
- -- Don't look inside if you're easily disturbed by poor code.
- -- You have been warned.
- local xSize = 7
- local ySize = 12
- local tileColour = colors.blue
- local bgColour = colours.black
- local blockChr = " "
- local twoRow = 9 --row at which two squares is forced
- local oneRow = 5 --row at which one square is forced
- local jua = require("jua")
- local mon = peripheral.find("monitor")
- local gameState = "idle"
- -- Possible modes: SUBJECT TO CHANGE
- -- idle -- no game in progress
- -- play -- gameplay active
- -- wait -- pauses in gameplay (maybe dont need)
- local tiles = {} -- grid of tiles
- local scrollTiles = {}
- local scrollRow = {}
- local currentSize = 0
- local scrollDirection = ""
- local counter
- local delay -- smaller values are faster
- function setup() -- for setting up / resetting game
- tiles = {} -- grid of tiles
- for i = 1, ySize do
- tiles[i] = {}
- for j = 1, xSize do
- tiles[i][j] = false
- end
- end
- scrollTiles = tiles[1] -- storage for current line
- scrollRow = ySize+1
- currentSize = 3
- scrollDirection = "right"
- delay = 10
- counter = 0
- gameState = "play"
- end
- function displayTiles()
- mon.clear()
- for i = 1, ySize do
- for j = 1, xSize do
- if tiles[i][j] == true then
- mon.setBackgroundColour(tileColour)
- else
- mon.setBackgroundColour(bgColour)
- end
- mon.setCursorPos(j, i)
- mon.write(blockChr)
- end
- end
- end
- function newBlock()
- local block = {}
- for i = 1, xSize do
- if i <= currentSize then
- block[i] = true
- else
- block[i] = false
- end
- end
- return block
- end
- function scrollBlock()
- counter = counter +1 --count every time is run
- if counter % delay ~= 0 then return scrollTiles end -- only change when counter matches delay
- local block = table.pack(table.unpack(scrollTiles)) --copying tables hahahah wtf
- if block[1] == true then
- scrollDirection = "right"
- elseif block[xSize] == true then
- scrollDirection = "left"
- end
- for i = 1, xSize do
- if scrollDirection == "right" then
- if i == 1 then
- block[i] = false
- else
- local nextT = i-1
- block[i] = scrollTiles[nextT]
- end
- elseif scrollDirection == "left" then
- if i == xSize then
- block[i] = false
- else
- block[i] = scrollTiles[i+1]
- end
- end
- end
- return block
- end
- function displayScroll()
- for i = 1, xSize do
- if scrollTiles[i] == true then
- mon.setBackgroundColour(tileColour)
- else
- mon.setBackgroundColour(bgColour)
- end
- mon.setCursorPos(i, scrollRow)
- mon.write(blockChr)
- end
- end
- function nextRow()
- scrollRow = scrollRow-1
- currentSize = 3
- if scrollRow <= oneRow then currentSize = 1
- elseif scrollRow <= twoRow then currentSize = 2 end
- scrollTiles = newBlock()
- end
- function placeRow() --something broke
- local tilesLeft = {}
- for i = 1, xSize do
- tilesLeft[i] = false
- if scrollTiles[i] == true then
- if scrollRow == ySize then
- tilesLeft[i] = true
- elseif tiles[scrollRow+1][i] == true then
- print(".")
- tilesLeft[i] = true
- elseif scrollRow == 1 then
- --last row
- end
- end
- end
- return tilesLeft
- end
- function setTile(row, tile, val)
- if tiles[row] ~= nil then
- if tiles[row][tile] ~= nil then
- tiles[row][tile] = val
- end
- end
- end
- setup()
- jua.setInterval(function()
- displayScroll()
- scrollTiles = scrollBlock()
- end, 0.01)
- jua.on("terminate", function()
- printError("Terminated *_*")
- mon.setBackgroundColour(bgColour)
- mon.clear()
- jua.stop()
- end)
- jua.on("monitor_touch", function()
- print("touched")
- if gameState == "play" then
- local row = placeRow()
- nextRow()
- tiles[scrollRow+1] = row
- end
- end)
- jua.go(function()
- print("go")
- nextRow()
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement