Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- term.clear()
- term.setCursorPos(1,1)
- local currentX = 25
- local currentY = 9
- local currentX2 = 24
- local currentY2 = 8
- local sprite = "1"
- local sprite2 = "2"
- local tries = "0"
- local player = 0
- function drawSprite()
- term.clear()
- term.setCursorPos(currentX,currentY)
- write(sprite)
- movement()
- end
- function drawSpriteMulti()
- term.clear()
- term.setCursorPos(currentX,currentY)
- write(sprite)
- term.setCursorPos(currentX2,currentY2)
- write(sprite2)
- if player == 1 then
- movementMulti()
- elseif player == 2 then
- movementMulti2()
- end
- end
- function connect()
- print "1:) Host"
- print "2:) Join"
- input = read()
- if input == "1" then
- player = 1
- print "OK... Waiting for IP to join"
- while true do
- id, msg = rednet.receive()
- sleep(.1)
- tries = tries + 1
- if tries > 1000 then
- print "Timed out"
- elseif msg == "connect" then
- local player2 = id
- drawSpriteMulti()
- end
- end
- elseif input == "2" then
- player = 2
- write "Enter the ip of who you want to connect to: "
- local c = tonumber(read())
- while true do
- sleep(.1)
- rednet.send(c, "connect")
- sleep(1)
- drawSpriteMulti()
- end
- end
- end
- function open()
- rednet.open("top")
- rednet.open("back")
- rednet.open("left")
- rednet.open("right")
- rednet.open("left")
- end
- function movementMulti()
- while true do
- event, key, command = os.pullEvent()
- if event == "key" and key == 17 and currentY >= 1 then
- currentY = currentY - 1
- rednet.send(player2, "up")
- drawSpriteMulti()
- elseif event == "key" and key == 31 and currentY <= 18 then
- currentY = currentY + 1
- rednet.send(player2, "down")
- drawSpriteMulti()
- elseif event == "key" and key == 30 and currentX >= 1 then
- currentX = currentX - 1
- rednet.send(player2, "left")
- drawSpriteMulti()
- elseif event == "key" and key == 32 and currentX <= 50 then
- currentX = currentX + 1
- rednet.send(player2, "right")
- drawSpriteMulti()
- elseif event == "rednet_message" then
- if key == player2 and command == "up" then
- currentY2 = currentY2 - 1
- drawSpriteMulti()
- elseif key == player2 and command == "down" then
- currentY2 = currentY2 + 1
- drawSpriteMulti()
- elseif key == player2 and command == "left" then
- currentX2 = currentX2 - 1
- drawSpriteMulti()
- elseif key == player2 and command == "right" then
- currentX2 = currentX2 + 1
- drawSpriteMulti()
- else
- drawSpriteMulti()
- end
- end
- end
- while true do
- id, command = rednet.receive()
- if id == player2 and command == "up" then
- currentY2 = currentY2 - 1
- drawSpriteMulti()
- elseif id == player2 and command == "down" then
- currentY2 = currentY2 + 1
- drawSpriteMulti()
- elseif id == player2 and command == "left" then
- currentX2 = currentX2 - 1
- drawSpriteMulti()
- elseif id == player2 and command == "right" then
- currentX2 = currentX2 + 1
- drawSpriteMulti()
- else
- drawSpriteMulti()
- end
- end
- end
- function movementMulti2()
- while true do
- event, key = os.pullEvent()
- if event == "key" and key == 17 then
- currentY2 = currentY2 - 1
- rednet.send(c, "up")
- drawSpriteMulti()
- elseif event == "key" and key == 31 then
- currentY2 = currentY2 + 1
- rednet.send(c, "down")
- drawSpriteMulti()
- elseif event == "key" and key == 30 then
- currentX2 = currentX2 - 1
- rednet.send(c, "left")
- drawSpriteMulti()
- elseif event == "key" and key == 32 then
- currentX2 = currentX2 + 1
- rednet.send(c, "right")
- drawSpriteMulti()
- end
- end
- while true do
- id, command = rednet.receive()
- if id == c and command == "up" then
- currentY = currentY - 1
- drawSpriteMulti()
- elseif id == c and command == "down" then
- currentY = currentY + 1
- drawSpriteMulti()
- elseif id == c and command == "left" then
- currentX = currentX - 1
- drawSpriteMulti()
- elseif id == c and command == "right" then
- currentX = currentX + 1
- drawSpriteMulti()
- end
- end
- end
- function movement()
- event, key = os.pullEvent()
- if event == "key" and key == 17 and currentY >= 1 then
- currentY = currentY - 1
- drawSprite()
- elseif event == "key" and key == 31 and currentY <= 18 then
- currentY = currentY + 1
- drawSprite()
- elseif event == "key" and key == 30 and currentX >= 1 then
- currentX = currentX - 1
- drawSprite()
- elseif event == "key" and key == 32 and currentX <= 50 then
- currentX = currentX + 1
- drawSprite()
- end
- end
- open()
- print "How would you like to play?"
- print "1:) Singleplayer (boring)"
- print "2:) Multiplayer (EPIC)"
- input = read()
- if input == "1" then
- drawSprite()
- elseif input == "2" then
- connect()
- end
Advertisement
Add Comment
Please, Sign In to add comment