mirror of https://github.com/LDDestroier/CC/
Update tron
This commit is contained in:
parent
bb64f8ebc2
commit
ee107a46b9
85
tron
85
tron
|
@ -22,6 +22,7 @@ end
|
||||||
|
|
||||||
local gamename = ""
|
local gamename = ""
|
||||||
local isHost
|
local isHost
|
||||||
|
local squareGrid = true
|
||||||
|
|
||||||
local waitingForGame = true
|
local waitingForGame = true
|
||||||
|
|
||||||
|
@ -41,18 +42,18 @@ deepCopy = function(tbl, ...)
|
||||||
return output
|
return output
|
||||||
end
|
end
|
||||||
|
|
||||||
local gridInit = {
|
local initGrid = {
|
||||||
x1 = -80,
|
x1 = -100,
|
||||||
y1 = -80,
|
y1 = -100,
|
||||||
x2 = 80,
|
x2 = 100,
|
||||||
y2 = 80,
|
y2 = 100,
|
||||||
border = "#",
|
border = "#",
|
||||||
voidcol = "f",
|
voidcol = "f",
|
||||||
forecol = "8",
|
forecol = "8",
|
||||||
backcol = "7",
|
backcol = "7",
|
||||||
edgecol = "0"
|
edgecol = "0"
|
||||||
}
|
}
|
||||||
grid = deepCopy(gridInit)
|
grid = deepCopy(initGrid)
|
||||||
|
|
||||||
local you = 1
|
local you = 1
|
||||||
local nou = 2
|
local nou = 2
|
||||||
|
@ -324,27 +325,45 @@ local control = {
|
||||||
-- keeps track of where you are
|
-- keeps track of where you are
|
||||||
local gamemode = ""
|
local gamemode = ""
|
||||||
|
|
||||||
-- foreground grid
|
|
||||||
local gridFore = {
|
|
||||||
"+-------",
|
|
||||||
"| ",
|
|
||||||
"| ",
|
|
||||||
"| ",
|
|
||||||
"| "
|
|
||||||
|
|
||||||
}
|
local gridFore, gridBack
|
||||||
|
if squareGrid then
|
||||||
-- background grid
|
gridFore = {
|
||||||
local gridBack = {
|
"+-------",
|
||||||
"+------------",
|
"| ",
|
||||||
"| ",
|
"| ",
|
||||||
"| ",
|
"| ",
|
||||||
"| ",
|
"| "
|
||||||
"| ",
|
}
|
||||||
"| ",
|
gridBack = {
|
||||||
"| ",
|
"+------------",
|
||||||
"| "
|
"| ",
|
||||||
}
|
"| ",
|
||||||
|
"| ",
|
||||||
|
"| ",
|
||||||
|
"| ",
|
||||||
|
"| ",
|
||||||
|
"| "
|
||||||
|
}
|
||||||
|
else
|
||||||
|
gridFore = {
|
||||||
|
" / ",
|
||||||
|
" / ",
|
||||||
|
" / ",
|
||||||
|
" / ",
|
||||||
|
"/__________"
|
||||||
|
}
|
||||||
|
gridBack = {
|
||||||
|
" / ",
|
||||||
|
" / ",
|
||||||
|
" / ",
|
||||||
|
" / ",
|
||||||
|
" / ",
|
||||||
|
" / ",
|
||||||
|
" / ",
|
||||||
|
"/_______________"
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
local dirArrow = {
|
local dirArrow = {
|
||||||
[-1] = "^",
|
[-1] = "^",
|
||||||
|
@ -482,7 +501,7 @@ local makeMenu = function(x, y, options)
|
||||||
evt = {os.pullEvent()}
|
evt = {os.pullEvent()}
|
||||||
if evt[1] == "key" then
|
if evt[1] == "key" then
|
||||||
if evt[2] == keys.up then
|
if evt[2] == keys.up then
|
||||||
cpos = (cpos - 1) % #options
|
cpos = (cpos - 2) % #options + 1
|
||||||
elseif evt[2] == keys.down then
|
elseif evt[2] == keys.down then
|
||||||
cpos = (cpos % #options) + 1
|
cpos = (cpos % #options) + 1
|
||||||
elseif evt[2] == keys.enter then
|
elseif evt[2] == keys.enter then
|
||||||
|
@ -577,8 +596,6 @@ local sendInfo = function(gameID)
|
||||||
keysDown = keysDown,
|
keysDown = keysDown,
|
||||||
trail = isHost and trail or nil,
|
trail = isHost and trail or nil,
|
||||||
deadGuys = isHost and deadGuys or {},
|
deadGuys = isHost and deadGuys or {},
|
||||||
gameDelay = (gameDelay or gameDelayInit),
|
|
||||||
grid = grid
|
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -659,7 +676,6 @@ end
|
||||||
|
|
||||||
local game = function()
|
local game = function()
|
||||||
local outcome
|
local outcome
|
||||||
-- os.pullEvent("new_game")
|
|
||||||
local p, np
|
local p, np
|
||||||
while true do
|
while true do
|
||||||
p = player[you]
|
p = player[you]
|
||||||
|
@ -718,7 +734,7 @@ local networking = function()
|
||||||
gamename = msg.gameID
|
gamename = msg.gameID
|
||||||
isHost = false
|
isHost = false
|
||||||
gameDelay = tonumber(msg.gameDelay) or 0.05
|
gameDelay = tonumber(msg.gameDelay) or 0.05
|
||||||
grid = deepCopy(msg.grid or gridInit)
|
grid = msg.grid or deepCopy(initGrid)
|
||||||
else
|
else
|
||||||
you, nou = nou, you
|
you, nou = nou, you
|
||||||
isHost = true
|
isHost = true
|
||||||
|
@ -727,11 +743,13 @@ local networking = function()
|
||||||
modem.transmit(port, port, {
|
modem.transmit(port, port, {
|
||||||
player = player,
|
player = player,
|
||||||
gameID = gamename,
|
gameID = gamename,
|
||||||
new = isHost and (-math.huge) or (math.huge)
|
new = isHost and (-math.huge) or (math.huge),
|
||||||
|
grid = initGrid
|
||||||
})
|
})
|
||||||
waitingForGame = false
|
waitingForGame = false
|
||||||
netKeysDown = {}
|
netKeysDown = {}
|
||||||
os.queueEvent("new_game", gameID)
|
os.queueEvent("new_game", gameID)
|
||||||
|
|
||||||
elseif msg.gameID == gamename then
|
elseif msg.gameID == gamename then
|
||||||
if not isHost then
|
if not isHost then
|
||||||
player = msg.player
|
player = msg.player
|
||||||
|
@ -770,6 +788,7 @@ while true do
|
||||||
trail = {}
|
trail = {}
|
||||||
deadGuys = {}
|
deadGuys = {}
|
||||||
gameDelay = gameDelayInit
|
gameDelay = gameDelayInit
|
||||||
|
grid = deepCopy(initGrid)
|
||||||
resetPlayers()
|
resetPlayers()
|
||||||
you, nou = 1, 2
|
you, nou = 1, 2
|
||||||
gamename = ""
|
gamename = ""
|
||||||
|
@ -782,7 +801,7 @@ while true do
|
||||||
gameID = gamename,
|
gameID = gamename,
|
||||||
new = os.time(),
|
new = os.time(),
|
||||||
gameDelay = gameDelayInit,
|
gameDelay = gameDelayInit,
|
||||||
grid = gridInit
|
grid = initGrid
|
||||||
})
|
})
|
||||||
parallel.waitForAny(pleaseWait, networking)
|
parallel.waitForAny(pleaseWait, networking)
|
||||||
parallel.waitForAny(getInput, game, networking)
|
parallel.waitForAny(getInput, game, networking)
|
||||||
|
|
Loading…
Reference in New Issue