diff --git a/tron b/tron index da70593..730012c 100644 --- a/tron +++ b/tron @@ -1,8 +1,17 @@ -local scr_x, scr_y = term.getSize() -local modemID = 712 -local gamename = "" +local port = 701 -waitingForGame = true +local scr_x, scr_y = term.getSize() +local modem = peripheral.find("modem") +if (not modem) and ccemux then + ccemux.attach("top", "wireless_modem") + modem = peripheral.find("modem") +end + +if modem then + modem.open(port) +else +-- error("You should attach a modem.") +end local grid = { x1 = -80, @@ -16,9 +25,6 @@ local grid = { edgecol = "0" } -local you = 1 -local nou = 2 - local scrollX = 0 local scrollY = 0 @@ -123,6 +129,9 @@ local toblit = { [colors.black] = "f" } +local you = 1 +local nou = 2 + local control = { up = keys.up, down = keys.down, @@ -245,8 +254,6 @@ end local render = function() local p = player[you] drawGrid(scrollX + scrollAdjX, scrollY + scrollAdjY) - term.setCursorPos(1,1) - term.write(gamename) end local deepCopy @@ -367,7 +374,6 @@ local evt local keysDown = {} local getInput = function() - os.pullEvent("new_game") while true do evt = {os.pullEvent()} if lockInput then @@ -463,29 +469,9 @@ local moveTick = function() ageTrails() end -if ccemux and not peripheral.find("modem") then - ccemux.attach("top","wireless_modem") -end - -local modem = peripheral.find("modem") - -if modem then - modem.open(modemID) -else - error("You need a modem.") -end - -local sendInfo = function(gameID) - modem.transmit(modemID, modemID, { - player = player, - gameID = gameID - }) -end - local game = function() - local outcome - os.pullEvent("new_game") local p = player[you] + local outcome while true do p.putTrail = not keysDown[control.release] if keysDown[control.left] and p.direction ~= 0 then @@ -515,7 +501,6 @@ local game = function() scrollAdjY = scrollAdjY * 0.8 outcome = moveTick() - sendInfo(gameID) if outcome == "end" then return @@ -531,54 +516,13 @@ end local decision -local networking = function() - local evt, side, channel, repchannel, msg, distance - while true do - evt, side, channel, repchannel, msg, distance = os.pullEvent("modem_message") - if channel == modemID and repchannel == modemID and type(msg) == "table" then - if type(msg.player) == "table" and type(msg.gameID) == "string" then - - if waitingForGame and (type(msg.new) == "number") then - local time = os.time() - if msg.new < time then - you, nou = nou, you - gamename = msg.gameID - --error("okay what") - end - you, nou = nou, you - modem.transmit(modemID, modemID, { - player = player, - gameID = gamename, - new = (msg.new < time) and (os.time() + 10) or (os.time() - 10) - }) - waitingForGame = false - os.queueEvent("new_game", gameID) - elseif msg.gameID == gamename then - player[nou] = msg.player[nou] - end - - end - end - end -end - while true do decision = titleScreen() lockInput = false if decision == "start" then trail = {} resetPlayers() - gamename = "" - for i = 1, 32 do - gamename = gamename .. string.char(math.random(1,126)) - end - waitingForGame = true - modem.transmit(modemID, modemID, { - player = player, - gameID = gamename, - new = os.time() - }) - parallel.waitForAny(getInput, game, networking) + parallel.waitForAny(getInput, game) elseif decision == "demo" then parallel.waitForAny(getInput, gridDemo) elseif decision == "exit" then