mirror of
https://github.com/LDDestroier/CC/
synced 2025-08-29 09:02:27 +00:00
Improved host P1 designation, --update argument
+ Host will now always be P1, since sometimes it would act up and give host P2, especially on skynet. + How to Play has been updated with mouse controls + Update argument now runs the updated version of TRON instantly instead of waiting for a re-run.
This commit is contained in:
parent
a313b6364d
commit
fed06ed6e2
187
tron.lua
187
tron.lua
@ -24,8 +24,8 @@ local gridID = 1 -- determines which grid is used
|
|||||||
local initGrid = {
|
local initGrid = {
|
||||||
x1 = -100,
|
x1 = -100,
|
||||||
y1 = -100,
|
y1 = -100,
|
||||||
x2 = 40,
|
x2 = 100,
|
||||||
y2 = 40,
|
y2 = 100,
|
||||||
border = "#",
|
border = "#",
|
||||||
voidcol = "f",
|
voidcol = "f",
|
||||||
forecol = "8",
|
forecol = "8",
|
||||||
@ -322,68 +322,6 @@ if argumentName then
|
|||||||
argumentName = argumentName:sub(1, 15) -- gotta enforce that limit
|
argumentName = argumentName:sub(1, 15) -- gotta enforce that limit
|
||||||
end
|
end
|
||||||
|
|
||||||
if doUpdateGame then
|
|
||||||
print("Downloading...")
|
|
||||||
local net = http.get("https://github.com/LDDestroier/CC/raw/master/tron.lua")
|
|
||||||
if net then
|
|
||||||
local file = fs.open(shell.getRunningProgram(), "w")
|
|
||||||
file.write(net.readAll())
|
|
||||||
file.close()
|
|
||||||
print("Updated!")
|
|
||||||
else
|
|
||||||
printError("Couldn't update!")
|
|
||||||
end
|
|
||||||
if useOnce then
|
|
||||||
return
|
|
||||||
else
|
|
||||||
sleep(0.2)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local modem, skynet
|
|
||||||
if not doGridDemo then
|
|
||||||
if useSkynet then
|
|
||||||
if fs.exists(skynetPath) then
|
|
||||||
skynet = dofile(skynetPath)
|
|
||||||
skynet.open(port)
|
|
||||||
else
|
|
||||||
local prog = http.get(skynetURL)
|
|
||||||
if prog then
|
|
||||||
local file = fs.open(skynetPath, "w")
|
|
||||||
file.write(prog.readAll())
|
|
||||||
file.close()
|
|
||||||
skynet = dofile(skynetPath)
|
|
||||||
skynet.open(port)
|
|
||||||
else
|
|
||||||
error("Could not download Skynet.")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
|
||||||
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
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local transmit = function(port, message)
|
|
||||||
if useSkynet then
|
|
||||||
skynet.send(port, message)
|
|
||||||
else
|
|
||||||
modem.transmit(port, port, message)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local gamename = ""
|
|
||||||
local isHost
|
|
||||||
|
|
||||||
local waitingForGame = true
|
|
||||||
local toblit = {
|
local toblit = {
|
||||||
[0] = " ",
|
[0] = " ",
|
||||||
[colors.white] = "0",
|
[colors.white] = "0",
|
||||||
@ -466,6 +404,80 @@ local round = function(num, places)
|
|||||||
return math.floor(num * 10^places) / 10^places
|
return math.floor(num * 10^places) / 10^places
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if doUpdateGame then
|
||||||
|
print("Downloading...")
|
||||||
|
local net = http.get("https://github.com/LDDestroier/CC/raw/master/tron.lua")
|
||||||
|
if net then
|
||||||
|
local file = fs.open(shell.getRunningProgram(), "w")
|
||||||
|
file.write(net.readAll())
|
||||||
|
file.close()
|
||||||
|
print("Updated!")
|
||||||
|
else
|
||||||
|
printError("Couldn't update!")
|
||||||
|
end
|
||||||
|
if useOnce then
|
||||||
|
return
|
||||||
|
else
|
||||||
|
sleep(0.2)
|
||||||
|
shell.run( shell.getRunningProgram(), table.concat({...}, " "):gsub("--update", "") )
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local cwrite = function(text, y, xdiff, wordPosCheck)
|
||||||
|
wordPosCheck = wordPosCheck or #text
|
||||||
|
termsetCursorPos(mathfloor(scr_x / 2 - (#text + (xdiff or 0)) / 2), y or (scr_y - 2))
|
||||||
|
term.write(text)
|
||||||
|
return (scr_x / 2) - (#text / 2) + wordPosCheck
|
||||||
|
end
|
||||||
|
|
||||||
|
local modem, skynet
|
||||||
|
if not doGridDemo then
|
||||||
|
if useSkynet then
|
||||||
|
if fs.exists(skynetPath) then
|
||||||
|
skynet = dofile(skynetPath)
|
||||||
|
skynet.open(port)
|
||||||
|
else
|
||||||
|
term.clear()
|
||||||
|
cwrite("Downloading Skynet...", scr_y / 2)
|
||||||
|
local prog = http.get(skynetURL)
|
||||||
|
if prog then
|
||||||
|
local file = fs.open(skynetPath, "w")
|
||||||
|
file.write(prog.readAll())
|
||||||
|
file.close()
|
||||||
|
skynet = dofile(skynetPath)
|
||||||
|
skynet.open(port)
|
||||||
|
else
|
||||||
|
error("Could not download Skynet.")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
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
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local transmit = function(port, message)
|
||||||
|
if useSkynet then
|
||||||
|
skynet.send(port, message)
|
||||||
|
else
|
||||||
|
modem.transmit(port, port, message)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local gamename = ""
|
||||||
|
local isHost
|
||||||
|
|
||||||
|
local waitingForGame = true
|
||||||
|
|
||||||
-- used in skynet matches if you are player 2
|
-- used in skynet matches if you are player 2
|
||||||
local ping = 0
|
local ping = 0
|
||||||
|
|
||||||
@ -678,7 +690,7 @@ for k,v in pairs(images) do
|
|||||||
-- give them easy-to-access x and y sizes
|
-- give them easy-to-access x and y sizes
|
||||||
v.x = #v[1][1]
|
v.x = #v[1][1]
|
||||||
v.y = #v[1]
|
v.y = #v[1]
|
||||||
-- remove all that white bullshit that artifacts on cc:tweaked
|
-- fix white artifacting that occurs due to " " correlating to WHITE in term.blit
|
||||||
for y = 1, v.y do
|
for y = 1, v.y do
|
||||||
for x = 1, v.x do
|
for x = 1, v.x do
|
||||||
if v[2][y]:sub(x,x) ~= "" and v[3][y]:sub(x,x) ~= "" then
|
if v[2][y]:sub(x,x) ~= "" and v[3][y]:sub(x,x) ~= "" then
|
||||||
@ -769,13 +781,6 @@ local dirArrow = {
|
|||||||
[2] = "<"
|
[2] = "<"
|
||||||
}
|
}
|
||||||
|
|
||||||
local cwrite = function(text, y, xdiff, wordPosCheck)
|
|
||||||
wordPosCheck = wordPosCheck or #text
|
|
||||||
termsetCursorPos(mathfloor(scr_x / 2 - (#text + (xdiff or 0)) / 2), y or (scr_y - 2))
|
|
||||||
term.write(text)
|
|
||||||
return (scr_x / 2) - (#text / 2) + wordPosCheck
|
|
||||||
end
|
|
||||||
|
|
||||||
local doesIntersectBorder = function(x, y)
|
local doesIntersectBorder = function(x, y)
|
||||||
return mathfloor(x) == grid.x1 or mathfloor(x) == grid.x2 or mathfloor(y) == grid.y1 or mathfloor(y) == grid.y2
|
return mathfloor(x) == grid.x1 or mathfloor(x) == grid.x2 or mathfloor(y) == grid.y1 or mathfloor(y) == grid.y2
|
||||||
end
|
end
|
||||||
@ -1096,7 +1101,7 @@ local nameChange = function(scrollInfo)
|
|||||||
["3d6"] = colors.lime,
|
["3d6"] = colors.lime,
|
||||||
["lyqyd"] = colors.red,
|
["lyqyd"] = colors.red,
|
||||||
["squiddev"] = colors.cyan,
|
["squiddev"] = colors.cyan,
|
||||||
["oeed"] = colors.green,
|
["oeed"] = colors.lime,
|
||||||
["dog"] = colors.purple,
|
["dog"] = colors.purple,
|
||||||
["nothy"] = colors.lightGray,
|
["nothy"] = colors.lightGray,
|
||||||
["kepler"] = colors.cyan,
|
["kepler"] = colors.cyan,
|
||||||
@ -1116,7 +1121,13 @@ local nameChange = function(scrollInfo)
|
|||||||
["dannysmc"] = colors.purple,
|
["dannysmc"] = colors.purple,
|
||||||
["kingdaro"] = colors.blue,
|
["kingdaro"] = colors.blue,
|
||||||
["valithor"] = colors.orange,
|
["valithor"] = colors.orange,
|
||||||
["logandark"] = colors.lightGray
|
["logandark"] = colors.lightGray,
|
||||||
|
["lupus590"] = colors.lightGray,
|
||||||
|
["nitrogenfingers"] = colors.green,
|
||||||
|
["gravityscore"] = colors.lime,
|
||||||
|
["1lann"] = colors.gray,
|
||||||
|
["konlab"] = colors.brown,
|
||||||
|
["elvishjerricco"] = colors.pink
|
||||||
}
|
}
|
||||||
local prevName = argumentName or player[you].initName
|
local prevName = argumentName or player[you].initName
|
||||||
for x = 1, #prevName do
|
for x = 1, #prevName do
|
||||||
@ -1244,8 +1255,8 @@ local cleanExit = function()
|
|||||||
termsetBackgroundColor(colors.black)
|
termsetBackgroundColor(colors.black)
|
||||||
termsetTextColor(colors.white)
|
termsetTextColor(colors.white)
|
||||||
termclear()
|
termclear()
|
||||||
termsetCursorPos(1,1)
|
cwrite("Thanks for playing!", 2)
|
||||||
print("Thanks for playing!")
|
termsetCursorPos(1, scr_y)
|
||||||
end
|
end
|
||||||
|
|
||||||
local parseMouseInput = function(button, x, y, direction)
|
local parseMouseInput = function(button, x, y, direction)
|
||||||
@ -1365,7 +1376,7 @@ local gridDemo = function()
|
|||||||
end
|
end
|
||||||
drawGrid(scrollX, scrollY, false, true)
|
drawGrid(scrollX, scrollY, false, true)
|
||||||
ageTrails()
|
ageTrails()
|
||||||
sleep(gameDelay)
|
sleep(0.05)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1567,6 +1578,7 @@ local game = function()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local cTime -- current UTC time when looking for game
|
||||||
local networking = function()
|
local networking = function()
|
||||||
local evt, side, channel, repchannel, msg, distance
|
local evt, side, channel, repchannel, msg, distance
|
||||||
while true do
|
while true do
|
||||||
@ -1580,7 +1592,7 @@ local networking = function()
|
|||||||
if waitingForGame and (type(msg.time) == "number") then
|
if waitingForGame and (type(msg.time) == "number") then
|
||||||
|
|
||||||
-- called while waiting for match
|
-- called while waiting for match
|
||||||
if msg.time < os.epoch("utc") then
|
if msg.time < cTime then
|
||||||
isHost = false
|
isHost = false
|
||||||
you, nou = nou, you
|
you, nou = nou, you
|
||||||
gamename = msg.gameID
|
gamename = msg.gameID
|
||||||
@ -1597,7 +1609,7 @@ local networking = function()
|
|||||||
transmit(port, {
|
transmit(port, {
|
||||||
player = player,
|
player = player,
|
||||||
gameID = gamename,
|
gameID = gamename,
|
||||||
time = isHost and (-math.huge) or (math.huge),
|
time = cTime,
|
||||||
name = argumentName,
|
name = argumentName,
|
||||||
grid = initGrid
|
grid = initGrid
|
||||||
})
|
})
|
||||||
@ -1640,17 +1652,19 @@ local helpScreen = function()
|
|||||||
termclear()
|
termclear()
|
||||||
termsetCursorPos(1,2)
|
termsetCursorPos(1,2)
|
||||||
print([[
|
print([[
|
||||||
Move with arrow keys.
|
Move your lightcycle with WASD
|
||||||
Pan the camera with WASD.
|
or by tapping left click.
|
||||||
Hold SPACE to create gaps.
|
|
||||||
This takes fuel, which will
|
Pan the camera with arrows
|
||||||
recharge over time..
|
or by holding middle click.
|
||||||
|
|
||||||
|
Release the trail with spacebar
|
||||||
|
or by holding right click.
|
||||||
|
|
||||||
If you're P2 (red), a gray circle
|
If you're P2 (red), a gray circle
|
||||||
will indicate where you'll turn,
|
will indicate where you'll turn,
|
||||||
to help with Skynet's netlag.
|
to help with Skynet's netlag.
|
||||||
|
|
||||||
That's basically it.
|
|
||||||
Press any key to go back.
|
Press any key to go back.
|
||||||
]])
|
]])
|
||||||
waitForKey(0.25)
|
waitForKey(0.25)
|
||||||
@ -1677,11 +1691,12 @@ local startGame = function()
|
|||||||
end
|
end
|
||||||
|
|
||||||
waitingForGame = true
|
waitingForGame = true
|
||||||
|
cTime = os.epoch("utc")
|
||||||
transmit(port, {
|
transmit(port, {
|
||||||
player = player,
|
player = player,
|
||||||
gameID = gamename,
|
gameID = gamename,
|
||||||
gameDelay = gameDelayInit,
|
gameDelay = gameDelayInit,
|
||||||
time = os.epoch("utc"),
|
time = cTime,
|
||||||
name = argumentName,
|
name = argumentName,
|
||||||
grid = initGrid
|
grid = initGrid
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user