Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- term.clear() -- clear the screen before we start
- foundblock = false -- Just to be sure we haven't found the block
- width, height = term.getSize() -- We need to know the size of your computer screen
- blocks = {} -- No blocks yet, creating the table.
- blocksy = {} -- Same as above
- blocksy2 = {} -- Same as above
- blocksy3 = {} -- Same as Above
- blocksy4 = {} -- Same as Above
- blocksx = {} -- same as above
- blocksx2 = {} -- same as above
- blocksx3 = {} -- same as... above!
- blocksx4 = {} -- Same as above
- blocksshape = {} -- Same as above
- rotation = {} -- same as the above
- blockscreated = 0 -- We haven't created any blocks yet
- debug = true -- As this is not finished, I need to debug the program
- function align() -- This function is so big, Im not going to bother to explain it.
- for a = 1, blockscreated do
- if blocksshape[blockscreated] == "L" then
- if rotation[blockscreated] == 1 then
- blocksy2[blockscreated] = blocksy[blockscreated]
- blocksy3[blockscreated] = blocksy[blockscreated] -1
- blocksy4[blockscreated] = blocksy[blockscreated] -2
- blocksx2[blockscreated] = blocksx[blockscreated] +1
- blocksx3[blockscreated] = blocksx[blockscreated]
- blocksx4[blockscreated] = blocksx[blockscreated]
- elseif rotation[blockscreated] == 2 then
- blocksy2[blockscreated] = blocksy[blockscreated] -1
- blocksy3[blockscreated] = blocksy[blockscreated]
- blocksy4[blockscreated] = blocksy[blockscreated]
- blocksx2[blockscreated] = blocksx[blockscreated]
- blocksx3[blockscreated] = blocksx[blockscreated] -1
- blocksx4[blockscreated] = blocksx[blockscreated] -2
- elseif rotation[blockscreated] == 3 then
- blocksy2[blockscreated] = blocksy[blockscreated]
- blocksy3[blockscreated] = blocksy[blockscreated] +1
- blocksy4[blockscreated] = blocksy[blockscreated] +2
- blocksx2[blockscreated] = blocksx[blockscreated] +1
- blocksx3[blockscreated] = blocksx[blockscreated]
- blocksx4[blockscreated] = blocksx[blockscreated]
- elseif rotation[blockscreated] == 4 then
- blocksy2[blockscreated] = blocksy[blockscreated] +1
- blocksy3[blockscreated] = blocksy[blockscreated]
- blocksy4[blockscreated] = blocksy[blockscreated]
- blocksx2[blockscreated] = blocksx[blockscreated]
- blocksx3[blockscreated] = blocksx[blockscreated] +1
- blocksx4[blockscreated] = blocksx[blockscreated] +2
- end
- end
- end
- end
- function newblock() -- Create a new block
- foundblock = false -- We haven't found an uncreated block yet
- i = 0 -- We haven't started looking for a block yet, so make sure it knows that
- while not foundblock == true do -- Keep doing this until we find a block we haven't created yet
- i = i+1 -- Let search for a different block
- if blocks[i] == true then -- This block isn't new!
- --Do nothing
- else -- It is new!
- blocks[i] = true --Lets make sure we record the new block
- newblocknum = i -- For later use
- blockscreated = i -- Just so we know how many blocks we have created
- foundblock = true -- We found the block!
- end -- End that if statement
- end -- End the while loop
- shape = math.random(1, 7) -- Randomly set the shape
- if shape == 1 then -- Define the blocks shape
- shape = "L" -- Make it shaped Like an L
- elseif shape == 2 then -- If its not an L, then maybe its a...
- shape = "J" -- Backwards L
- elseif shape == 3 then -- Guess not, maybe its a
- shape = "Z" -- Z, or in our case |## |
- elseif shape == 4 then-- | ##| If its not a z, then
- shape = "S" -- Its a backwards z!
- elseif shape == 5 then -- Guess not, its probably a
- shape = "T" -- T
- elseif shape == 6 then -- Or not, Probably a
- shape = "O" -- Square
- elseif shape == 7 then -- Lastly, it must be a
- shape = "I" -- Square
- end -- End the shape defining if statement
- blocksshape[newblocknum] = shape -- Make the block have a shape
- blocksx[newblocknum] = 5 --Set the block in the middle
- blocksy[newblocknum] = 3 --Set the block high up
- end -- End the function
- function blockfall() --Makes all blocks fall
- for b = 1, blockscreated do --Go through all the blocks
- if blocksshape[b] then -- Too lazy to do anything with this yet
- if blocksy[b] == 19 then --Only drop the block if not touching the bottom
- --do nothing
- else -- Do something!
- if blocksy[b] then
- blocksy[b] = blocksy[b] +1 --Make the selected block fall 1 space, currently does not collide
- end -- End the if statement
- end -- End the if statement
- end -- End the if statement
- end -- End the for statement
- end -- End the function
- function draw() --Draw the screen
- term.clear()
- for z = 1, blockscreated do --Go through all the blocks
- if blocksshape[z] == "L" then -- Is the block L-shaped?
- term.setTextColor(colors.red) -- L blocks are now red
- term.setCursorPos(blocksx[z], blocksy[z]) --All Of
- write("#") -- This
- term.setCursorPos(blocksx4[z], blocksy2[z])
- write("3")
- term.setCursorPos(blocksx2[z], blocksy2[z])-- Draws
- write("#") -- The
- term.setCursorPos(blocksx3[z], blocksy3[z])-- L
- write("#") -- Block
- elseif blocksshape[z] == "J" then -- Is the block J-shaped?
- term.setTextColor(colors.blue) -- J blocks are now blue
- term.setCursorPos(blocksx[z]-1, blocksy[z])--All Of
- write("##") -- This
- term.setCursorPos(blocksx[z], blocksy[z]-1)-- Draws
- write("#") -- The
- term.setCursorPos(blocksx[z], blocksy[z]-1)-- J
- write("#") -- Block
- elseif blocksshape[z] == "Z" then -- Is the block Z-shaped?
- term.setTextColor(colors.pink) -- Z blocks are now pink
- term.setCursorPos(blocksx[z], blocksy[z]) --All Of
- write("##") -- This Draws
- term.setCursorPos(blocksx[z]-1, blocksy[z]-1)-- The Z
- write("##") -- Block
- elseif blocksshape[z] == "S" then -- Is the block S-shaped?
- term.setTextColor(colors.orange) -- S blocks are now orange
- term.setCursorPos(blocksx[z]-1, blocksy[z]) -- All Of
- write("##") -- This Draws
- term.setCursorPos(blocksx[z], blocksy[z]-1) -- The Z
- write("##") -- Block
- elseif blocksshape[z] == "I" then -- Is the block I-shaped?
- term.setTextColor(colors.lime) -- I blocks are now green
- term.setCursorPos(blocksx[z], blocksy[z]) -- All
- write("#") -- of
- term.setCursorPos(blocksx[z], blocksy[z]-1)-- This
- write("#") -- Draws
- term.setCursorPos(blocksx[z], blocksy[z]-2)-- The
- write("#") -- I
- term.setCursorPos(blocksx[z], blocksy[z]-3)-- Block
- write("#")
- elseif blocksshape[z] == "O" then -- Is the block O-shaped?
- term.setTextColor(colors.cyan) -- O blocks are now cyan
- term.setCursorPos(blocksx[z], blocksy[z]) -- All Of
- write("##") -- This Draws
- term.setCursorPos(blocksx[z], blocksy[z]-1)-- The
- write("##") -- O block
- elseif blocksshape[z] == "T" then -- Is the block T-shaped?
- term.setTextColor(colors.purple) -- T blocks are now purple
- term.setCursorPos(blocksx[z],blocksy[z]) -- All of
- write("#") -- This draws
- term.setCursorPos(blocksx[z]-1, blocksy[z]-1)-- The
- write("###") -- T block
- end --End the if statement
- end --End the For loop
- end -- End the function
- if debug == true then -- Lets debug the program.
- align()
- newblock() -- create the first block
- wait = 0 --Create the variable for later
- while true do -- Debug forever!
- draw() -- Draw the new area
- os.startTimer(0.3) -- Start a timer in case the player doesn't do anything
- oldtime = os.clock() -- Start!
- args = {os.pullEvent()} -- Rednet will mess this up, will fix that later
- newtime = os.clock() -- How long did the event take to happen
- oldtime = tonumber(oldtime) -- Just in case
- newtime = tonumber(newtime) -- Just in case
- time = newtime - oldtime --Calculate how long that took
- time = tonumber(time) -- Just in case
- if time == 0.35 then -- Boring
- sleept = 0 -- Boring
- elseif time == 0.30 then -- Boring
- sleept = 0.05 -- Boring
- elseif time == 0.25 then -- Boring
- sleept = 0.10 -- Boring
- elseif time == 0.20 then -- Boring
- sleept = 0.15 -- Boring
- elseif time == 0.15 then -- Boring
- sleept = 0.20 -- Boring
- elseif time == 0.10 then -- Boring
- sleept = 0.25 -- Boring
- elseif time == 0.5 then -- Boring
- sleept = 0.3 -- Boring
- elseif time == 0 then -- Boring
- sleept = 0.30 -- Boring
- end --End the boring if statement.
- sleept = tonumber(sleept) -- Just in case
- if args[2] == 208 and args[1] == "key" and blocks[blockscreated] then -- move piece down
- if blocksy[blockscreated] >= 17 then -- Make sure its not near the bottom
- --do nothing
- elseif blocksy == 16 then -- If its close, but not too close
- blocksy[blockscreated] = blocksy[blockscreated] +1 -- Go down 1
- else -- If its higher up then that,
- blocksy[blockscreated] = blocksy[blockscreated] +2 -- go down 2
- end -- End the if statement
- end -- End the if statement
- if args[2] == 205 and args[1] == "key" then -- move piece right
- if blocksx[blockscreated] == 10 then -- leave room for edge, score, level, etc.
- -- do nothing
- else -- Do something
- if blocks[blockscreated] == true then -- make sure it exist to move it
- blocksx[blockscreated] = blocksx[blockscreated] +1 -- Move it right
- draw() --redraw
- end -- end if statement
- end -- end the if statement
- end -- end if statement
- if args[1] == "key" and args[2] == 203 then -- move piece left
- if blocksx[blockscreated] == 2 then -- Leave room for edge
- -- do nothing
- else -- Do something
- if blocks[blockscreated] == true and args[2] == 203 then -- make sure it exist to move it
- blocksx[blockscreated] = blocksx[blockscreated] -1 -- move it left
- draw() --redraw
- end -- end the if statement
- end -- end if statement
- end -- end if statement
- if sleept then -- It said it couldn't find a number somewhere, was it here?
- sleep(sleept) -- I try to pause .3 of a second every loop
- end -- End that if statement
- if blocksy[blockscreated] == 19 then -- Make sure it has reached the bottom
- newblock() -- it reached the bottom, time for a new block.
- else -- Not statements keep messing up
- blockfall() -- Make the blocks fall
- end -- End if statement
- end -- End if statement
- end -- End while loop
Advertisement
Add Comment
Please, Sign In to add comment