Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- shape = {}
- shape[1] = {{0,0,0,0,0},
- {0,0,1,0,0},
- {0,0,1,0,0},
- {0,0,1,0,0},
- {0,0,1,0,0}}
- shape[2] = {{0,0,0,0,0},
- {0,0,1,0,0},
- {0,0,1,0,0},
- {0,0,1,0,0},
- {0,1,1,0,0}}
- shape[3] = {{0,0,0,0,0},
- {0,0,1,0,0},
- {0,0,1,0,0},
- {0,0,1,0,0},
- {0,0,1,1,0}}
- shape[4] = {{0,0,0,0,0},
- {0,0,0,0,0},
- {0,0,1,1,0},
- {0,1,1,0,0},
- {0,0,0,0,0}}
- shape[5] = {{0,0,0,0,0},
- {0,0,0,0,0},
- {0,1,1,0,0},
- {0,0,1,1,0},
- {0,0,0,0,0}}
- shape[6] = {{0,0,0,0,0},
- {0,0,0,0,0},
- {0,0,1,0,0},
- {0,1,1,1,0},
- {0,0,0,0,0}}
- shape[7] = {{0,0,0,0,0},
- {0,0,0,0,0},
- {0,1,1,0,0},
- {0,1,1,0,0},
- {0,0,0,0,0}}
- local xMin = 2
- local yMin = 1
- local yL = 4
- local xMax = 23
- local yMax = 18
- local field = {}
- function createField()
- for y = yMin,yMax do
- field[y] = {}
- for x = xMin,xMax do
- val = colors.black
- if y == yMax or x == xMin or x == xMax then
- val = colors.gray
- end
- field[y][x] = val
- end
- end
- end
- function printField()
- for y = yMin,yMax do
- for x = xMin,xMax do
- term.setBackgroundColor(field[y][x])
- term.setCursorPos(x,y)
- term.write(" ")
- end
- end
- end
- function checkCollision(num,dir,xP,yP)
- for y = 1,#shape[num] do
- for x = 1,#shape[num][y] do
- if dir == 1 then
- val = shape[num][y][x]
- elseif dir == 2 then
- val = shape[num][x][y]
- elseif dir == 3 then
- val = shape[num][#shape[num]+1-y][#shape[num][y]+1-x]
- elseif dir == 4 then
- val = shape[num][#shape[num][y]+1-x][#shape[num]+1-y]
- end
- if val == 1 then
- if field[yMin+y+yP-2][xMin+x+xP-2] ~= colors.black then
- return true
- end
- end
- end
- end
- end
- function displayShape(num,dir,xP,yP)
- for y = 1,#shape[num] do
- for x = 1,#shape[num][y] do
- if dir == 1 then
- val = shape[num][y][x]
- elseif dir == 2 then
- val = shape[num][x][y]
- elseif dir == 3 then
- val = shape[num][#shape[num]+1-y][#shape[num][y]+1-x]
- elseif dir == 4 then
- val = shape[num][#shape[num][y]+1-x][#shape[num]+1-y]
- end
- if val == 1 then
- if field[yMin+y+yP-2][xMin+x+xP-2] == colors.black then
- field[yMin+y+yP-2][xMin+x+xP-2] = colors.blue
- end
- end
- end
- end
- end
- function clearShape()
- for yP = yMin,yMax do
- for xP = xMin,xMax do
- if field[yP][xP] == colors.blue then
- field[yP][xP] = colors.black
- end
- end
- end
- end
- function moveArray()
- for yP = yMin,yMax do
- for xP = xMin,xMax do
- if field[yP][xP] == colors.blue then
- if yP <= yMin+yL then
- return true
- else
- field[yP][xP] = colors.red
- end
- end
- end
- end
- end
- function checkLine()
- for yP = yMin,yMax do
- stat = true
- for xP = xMin+1,xMax-1 do
- if field[yP][xP] ~= colors.red then
- stat = false
- end
- end
- if stat == true then
- for y = yP,yMin+1,-1 do
- for xP = xMin+1,xMax-1 do
- field[y][xP] = field[y-1][xP]
- end
- end
- for xP = xMin+1,xMax+1 do
- field[yMin][xP] = colors.black
- end
- end
- end
- end
- function printyL()
- term.setBackgroundColor(colors.lime)
- for xP = xMin+1,xMax-1 do
- term.setCursorPos(xP,yL+yMin)
- term.write(" ")
- end
- end
- createField()
- local xP = math.floor(xMax/2)
- local yP = yMin
- local dir = 1
- local s = math.random(1,7)
- while true do
- event,key = os.pullEvent()
- clearShape()
- if key == keys.q then
- dir = dir+1
- if dir > 4 then
- dir = 1
- end
- if checkCollision(s,dir,xP,yP) then
- dir = dir-1
- if dir < 1 then
- dir = 4
- end
- end
- elseif key == keys.left then
- xP = xP-1
- if checkCollision(s,dir,xP,yP) then
- xP = xP+1
- end
- elseif key == keys.right then
- xP = xP+1
- if checkCollision(s,dir,xP,yP) then
- xP = xP-1
- end
- else
- yP = yP+1
- if checkCollision(s,dir,xP,yP) then
- displayShape(s,dir,xP,yP-1)
- if moveArray() then
- break
- end
- checkLine()
- s = math.random(1,7)
- yP = yMin
- xP = math.floor(xMax/2)
- end
- end
- displayShape(s,dir,xP,yP)
- printField()
- printyL()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement