Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- 0 = UP, 1 = RIGHT, 2 = DOWN, 3 = LEFT
- local ecran = peripheral.wrap("right")
- term.redirect(ecran)
- local i = 0
- local direction = 1
- local temp = 0
- local isPoint = 0
- local pointX = 0
- local pointY = 0
- snakeX = {}
- snakeY = {}
- tempX = {}
- tempY = {}
- diff = 0.5
- for i=1, 100 do
- snakeX[i] = 0
- snakeY[i] = 0
- tempX[i] = 0
- tempY[i] = 0
- end
- local snakeLength = 1
- local continue = 0
- local game = 1
- while game == 1 do
- continue = 0
- snakeLength = 0
- direction = 1
- while continue == 0 do
- paintutils.drawFilledBox(0,0,73,26,1)
- term.setCursorPos(36, 10)
- term.setTextColor(64)
- term.write("NEW GAME ?")
- temp = redstone.getAnalogInput("bottom")
- if temp == 2 then
- continue = 1
- end
- sleep(1)
- end
- snakeX[1] = 3
- snakeY[1] = 3
- while continue == 1 do
- paintutils.drawFilledBox(0,0,73,26,1)
- temp = redstone.getAnalogInput("bottom")
- if temp == 3 and direction ~= 3 then
- direction = 1
- elseif temp == 5 and direction ~= 0 then
- direction = 2
- elseif temp == 7 and direction ~= 1 then
- direction = 3
- elseif temp == 12 and direction ~= 2 then
- direction = 0
- end
- if direction == 0 then
- snakeY[1] = snakeY[1] - 1
- elseif direction == 1 then
- snakeX[1] = snakeX[1] + 1
- elseif direction == 2 then
- snakeY[1] = snakeY[1] + 1
- elseif direction == 3 then
- snakeX[1] = snakeX[1] - 1
- end
- for i=2, snakeLength, 1
- do
- paintutils.drawPixel(snakeX[i],snakeY[i], 256)
- end
- if snakeX[1] > 70 or snakeX[1] < 1 or snakeY[1] > 25 or snakeY[1] < 1 then
- continue = 0
- end
- for i=1, snakeLength, 1
- do
- tempX[i] = snakeX[i]
- tempY[i] = snakeY[i]
- end
- for i=2, snakeLength, 1
- do
- snakeX[i] = tempX[i-1]
- snakeY[i] = tempY[i-1]
- end
- if isPoint == 0 then
- isPoint = 1
- pointX = math.random(71)
- pointY = math.random(26)
- end
- paintutils.drawPixel(pointX,pointY, 16384)
- if snakeX[1] == pointX and snakeY[1] == pointY then
- snakeLength = snakeLength + 1
- diff = diff - 0.05
- isPoint = 0
- end
- paintutils.drawPixel(snakeX[1],snakeY[1], 32768)
- for i=2, snakeLength, 1 do
- if snakeX[1] == tempX[i] and snakeY[1] == tempY[i] then
- continue = 0
- end
- end
- sleep(diff)
- end
- paintutils.drawFilledBox(0,0,73,26,1)
- term.setCursorPos(36, 10)
- term.setTextColor(64)
- term.write("GAME OVER")
- sleep(5)
- paintutils.drawFilledBox(0,0,73,26,32768)
- end
Add Comment
Please, Sign In to add comment