1
0
mirror of https://github.com/LDDestroier/CC/ synced 2024-11-06 01:56:22 +00:00

Update tron

This commit is contained in:
LDDestroier 2018-11-13 23:29:59 -05:00 committed by GitHub
parent 5d4d78e89b
commit d79bf6cf5e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

27
tron
View File

@ -16,6 +16,9 @@ local grid = {
edgecol = "0" edgecol = "0"
} }
local you = 1
local nou = 2
local scrollX = 0 local scrollX = 0
local scrollY = 0 local scrollY = 0
@ -120,9 +123,6 @@ local toblit = {
[colors.black] = "f" [colors.black] = "f"
} }
local you = 1
local nou = 2
local control = { local control = {
up = keys.up, up = keys.up,
down = keys.down, down = keys.down,
@ -245,6 +245,8 @@ end
local render = function() local render = function()
local p = player[you] local p = player[you]
drawGrid(scrollX + scrollAdjX, scrollY + scrollAdjY) drawGrid(scrollX + scrollAdjX, scrollY + scrollAdjY)
term.setCursorPos(1,1)
term.write(gamename)
end end
local deepCopy local deepCopy
@ -481,9 +483,9 @@ local sendInfo = function(gameID)
end end
local game = function() local game = function()
local p = player[you]
local outcome local outcome
os.pullEvent("new_game") os.pullEvent("new_game")
local p = player[you]
while true do while true do
p.putTrail = not keysDown[control.release] p.putTrail = not keysDown[control.release]
if keysDown[control.left] and p.direction ~= 0 then if keysDown[control.left] and p.direction ~= 0 then
@ -535,14 +537,26 @@ local networking = function()
evt, side, channel, repchannel, msg, distance = os.pullEvent("modem_message") evt, side, channel, repchannel, msg, distance = os.pullEvent("modem_message")
if channel == modemID and repchannel == modemID and type(msg) == "table" then if channel == modemID and repchannel == modemID and type(msg) == "table" then
if type(msg.player) == "table" and type(msg.gameID) == "string" then if type(msg.player) == "table" and type(msg.gameID) == "string" then
if waitingForGame and (type(msg.new) == "number") then if waitingForGame and (type(msg.new) == "number") then
if msg.new < os.time() then local time = os.time()
you, nou = you, nou if msg.new < time then
you, nou = nou, you
gamename = msg.gameID gamename = msg.gameID
--error("okay what")
end 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 waitingForGame = false
os.queueEvent("new_game", gameID) os.queueEvent("new_game", gameID)
elseif msg.gameID == gamename then
player[nou] = msg.player[nou]
end end
end end
end end
end end
@ -558,6 +572,7 @@ while true do
for i = 1, 32 do for i = 1, 32 do
gamename = gamename .. string.char(math.random(1,126)) gamename = gamename .. string.char(math.random(1,126))
end end
waitingForGame = true
modem.transmit(modemID, modemID, { modem.transmit(modemID, modemID, {
player = player, player = player,
gameID = gamename, gameID = gamename,