SHOW:
|
|
- or go back to the newest paste.
| 1 | term.clear() | |
| 2 | term.setCursorPos(1,1) | |
| 3 | ||
| 4 | local currentX = 25 | |
| 5 | local currentY = 9 | |
| 6 | local currentX2 = 24 | |
| 7 | local currentY2 = 8 | |
| 8 | local sprite = "1" | |
| 9 | local sprite2 = "2" | |
| 10 | local tries = "0" | |
| 11 | local player = 0 | |
| 12 | ||
| 13 | function drawSprite() | |
| 14 | term.clear() | |
| 15 | term.setCursorPos(currentX,currentY) | |
| 16 | write(sprite) | |
| 17 | movement() | |
| 18 | end | |
| 19 | ||
| 20 | function drawSpriteMulti() | |
| 21 | term.clear() | |
| 22 | term.setCursorPos(currentX,currentY) | |
| 23 | write(sprite) | |
| 24 | term.setCursorPos(currentX2,currentY2) | |
| 25 | write(sprite2) | |
| 26 | if player == 1 then | |
| 27 | movementMulti() | |
| 28 | elseif player == 2 then | |
| 29 | movementMulti2() | |
| 30 | end | |
| 31 | end | |
| 32 | ||
| 33 | function connect() | |
| 34 | print "1:) Host" | |
| 35 | print "2:) Join" | |
| 36 | input = read() | |
| 37 | if input == "1" then | |
| 38 | player = 1 | |
| 39 | print "OK... Waiting for IP to join" | |
| 40 | while true do | |
| 41 | id, msg = rednet.receive() | |
| 42 | sleep(.1) | |
| 43 | tries = tries + 1 | |
| 44 | if tries > 1000 then | |
| 45 | print "Timed out" | |
| 46 | elseif msg == "connect" then | |
| 47 | local player2 = id | |
| 48 | drawSpriteMulti() | |
| 49 | end | |
| 50 | end | |
| 51 | elseif input == "2" then | |
| 52 | player = 2 | |
| 53 | write "Enter the ip of who you want to connect to: " | |
| 54 | local c = tonumber(read()) | |
| 55 | while true do | |
| 56 | sleep(.1) | |
| 57 | rednet.send(c, "connect") | |
| 58 | sleep(1) | |
| 59 | drawSpriteMulti() | |
| 60 | end | |
| 61 | end | |
| 62 | end | |
| 63 | ||
| 64 | function open() | |
| 65 | rednet.open("top")
| |
| 66 | rednet.open("back")
| |
| 67 | rednet.open("left")
| |
| 68 | rednet.open("right")
| |
| 69 | rednet.open("left")
| |
| 70 | end | |
| 71 | ||
| 72 | function movementMulti() | |
| 73 | while true do | |
| 74 | event, key, command = os.pullEvent() | |
| 75 | if event == "key" and key == 17 and currentY >= 1 then | |
| 76 | currentY = currentY - 1 | |
| 77 | rednet.send(player2, "up") | |
| 78 | drawSpriteMulti() | |
| 79 | elseif event == "key" and key == 31 and currentY <= 18 then | |
| 80 | currentY = currentY + 1 | |
| 81 | rednet.send(player2, "down") | |
| 82 | drawSpriteMulti() | |
| 83 | elseif event == "key" and key == 30 and currentX >= 1 then | |
| 84 | currentX = currentX - 1 | |
| 85 | rednet.send(player2, "left") | |
| 86 | drawSpriteMulti() | |
| 87 | elseif event == "key" and key == 32 and currentX <= 50 then | |
| 88 | currentX = currentX + 1 | |
| 89 | rednet.send(player2, "right") | |
| 90 | drawSpriteMulti() | |
| 91 | elseif event == "rednet_message" then | |
| 92 | if key == player2 and command == "up" then | |
| 93 | currentY2 = currentY2 - 1 | |
| 94 | drawSpriteMulti() | |
| 95 | elseif key == player2 and command == "down" then | |
| 96 | currentY2 = currentY2 + 1 | |
| 97 | drawSpriteMulti() | |
| 98 | elseif key == player2 and command == "left" then | |
| 99 | currentX2 = currentX2 - 1 | |
| 100 | drawSpriteMulti() | |
| 101 | elseif key == player2 and command == "right" then | |
| 102 | currentX2 = currentX2 + 1 | |
| 103 | drawSpriteMulti() | |
| 104 | else | |
| 105 | drawSpriteMulti() | |
| 106 | end | |
| 107 | end | |
| 108 | end | |
| 109 | ||
| 110 | while true do | |
| 111 | id, command = rednet.receive() | |
| 112 | if id == player2 and command == "up" then | |
| 113 | currentY2 = currentY2 - 1 | |
| 114 | drawSpriteMulti() | |
| 115 | elseif id == player2 and command == "down" then | |
| 116 | currentY2 = currentY2 + 1 | |
| 117 | drawSpriteMulti() | |
| 118 | elseif id == player2 and command == "left" then | |
| 119 | currentX2 = currentX2 - 1 | |
| 120 | drawSpriteMulti() | |
| 121 | elseif id == player2 and command == "right" then | |
| 122 | currentX2 = currentX2 + 1 | |
| 123 | drawSpriteMulti() | |
| 124 | else | |
| 125 | drawSpriteMulti() | |
| 126 | end | |
| 127 | end | |
| 128 | end | |
| 129 | ||
| 130 | function movementMulti2() | |
| 131 | while true do | |
| 132 | event, key = os.pullEvent() | |
| 133 | if event == "key" and key == 17 then | |
| 134 | currentY2 = currentY2 - 1 | |
| 135 | rednet.send(c, "up") | |
| 136 | drawSpriteMulti() | |
| 137 | elseif event == "key" and key == 31 then | |
| 138 | currentY2 = currentY2 + 1 | |
| 139 | rednet.send(c, "down") | |
| 140 | drawSpriteMulti() | |
| 141 | elseif event == "key" and key == 30 then | |
| 142 | currentX2 = currentX2 - 1 | |
| 143 | rednet.send(c, "left") | |
| 144 | drawSpriteMulti() | |
| 145 | elseif event == "key" and key == 32 then | |
| 146 | currentX2 = currentX2 + 1 | |
| 147 | rednet.send(c, "right") | |
| 148 | drawSpriteMulti() | |
| 149 | end | |
| 150 | end | |
| 151 | ||
| 152 | while true do | |
| 153 | id, command = rednet.receive() | |
| 154 | if id == c and command == "up" then | |
| 155 | currentY = currentY - 1 | |
| 156 | drawSpriteMulti() | |
| 157 | elseif id == c and command == "down" then | |
| 158 | currentY = currentY + 1 | |
| 159 | drawSpriteMulti() | |
| 160 | elseif id == c and command == "left" then | |
| 161 | currentX = currentX - 1 | |
| 162 | drawSpriteMulti() | |
| 163 | elseif id == c and command == "right" then | |
| 164 | currentX = currentX + 1 | |
| 165 | drawSpriteMulti() | |
| 166 | end | |
| 167 | end | |
| 168 | end | |
| 169 | ||
| 170 | function movement() | |
| 171 | event, key = os.pullEvent() | |
| 172 | if event == "key" and key == 17 and currentY >= 1 then | |
| 173 | currentY = currentY - 1 | |
| 174 | drawSprite() | |
| 175 | elseif event == "key" and key == 31 and currentY <= 18 then | |
| 176 | currentY = currentY + 1 | |
| 177 | drawSprite() | |
| 178 | elseif event == "key" and key == 30 and currentX >= 1 then | |
| 179 | currentX = currentX - 1 | |
| 180 | drawSprite() | |
| 181 | elseif event == "key" and key == 32 and currentX <= 50 then | |
| 182 | currentX = currentX + 1 | |
| 183 | drawSprite() | |
| 184 | end | |
| 185 | end | |
| 186 | ||
| 187 | open() | |
| 188 | print "How would you like to play?" | |
| 189 | print "1:) Singleplayer (boring)" | |
| 190 | print "2:) Multiplayer (EPIC)" | |
| 191 | input = read() | |
| 192 | if input == "1" then | |
| 193 | drawSprite() | |
| 194 | elseif input == "2" then | |
| 195 | connect() | |
| 196 | end |