Can now cancel out of "waiting for game"

Trail data is also now optimized, now only sending the player number instead of the whole value.
This also fixes the "X" animation upon losing, as only P1 could see that before.
This commit is contained in:
LDDestroier 2018-11-20 18:08:40 -05:00 committed by GitHub
parent e05d0f6131
commit 8420a5392d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 19 deletions

View File

@ -373,7 +373,7 @@ isPuttingDown = false
local putTrailXY = function(x, y, p) local putTrailXY = function(x, y, p)
trail[y] = trail[y] or {} trail[y] = trail[y] or {}
trail[y][x] = { trail[y][x] = {
player = player[p], player = p,
age = 0 age = 0
} }
end end
@ -385,10 +385,7 @@ end
local getTrail = function(x, y) local getTrail = function(x, y)
if trail[y] then if trail[y] then
if trail[y][x] then if trail[y][x] then
if doAge then return player[trail[y][x].player].char, player[trail[y][x].player].color, trail[y][x].age
trail[y][x].age = trail[y][x].age + 1
end
return trail[y][x].player.char, trail[y][x].player.color, trail[y][x].age
end end
end end
return false return false
@ -554,14 +551,12 @@ local drawGrid = function(x, y, onlyDrawGrid, useSetVisible)
end end
end end
local render = function() local render = function(useSetVisible)
tsv(false)
local p = player[you] local p = player[you]
drawGrid(scrollX + scrollAdjX, scrollY + scrollAdjY) drawGrid(scrollX + scrollAdjX, scrollY + scrollAdjY, false, useSetVisible)
termsetCursorPos(1,1) termsetCursorPos(1,1)
termsetTextColor(player[you].color[1]) termsetTextColor(player[you].color[1])
term.write("P" .. you) term.write("P" .. you)
tsv(true)
end end
local pleaseWait = function() local pleaseWait = function()
@ -583,9 +578,9 @@ local pleaseWait = function()
tID = os.startTimer(0.5) tID = os.startTimer(0.5)
periods = (periods % maxPeriods) + 1 periods = (periods % maxPeriods) + 1
term.clearLine() term.clearLine()
elseif evt[1] == "new_game" then elseif evt[1] == "key" and evt[2] == keys.q then
return evt[2] return
end end
end end
end end
@ -603,7 +598,7 @@ local startCountdown = function()
scrollX = player[you].x - mathfloor(scr_x / 2) scrollX = player[you].x - mathfloor(scr_x / 2)
scrollY = player[you].y - mathfloor(scr_y / 2) scrollY = player[you].y - mathfloor(scr_y / 2)
for i = 3, 1, -1 do for i = 3, 1, -1 do
render() render(true)
termsetTextColor(colors.white) termsetTextColor(colors.white)
for x = 1, #cMessage+1 do for x = 1, #cMessage+1 do
termsetCursorPos(-1 + x + mathfloor(scr_x / 2 - (#cMessage + #cName) / 2), mathfloor(scr_y / 2) + 2) termsetCursorPos(-1 + x + mathfloor(scr_x / 2 - (#cMessage + #cName) / 2), mathfloor(scr_y / 2) + 2)
@ -742,7 +737,7 @@ local scrollToPosition = function(x, y)
for i = 1, 16 do for i = 1, 16 do
scrollX = (scrollX + x - (scr_x/2)) / 2 scrollX = (scrollX + x - (scr_x/2)) / 2
scrollY = (scrollY + y - (scr_y/2)) / 2 scrollY = (scrollY + y - (scr_y/2)) / 2
render() render(true)
sleep(0.05) sleep(0.05)
end end
end end
@ -765,7 +760,7 @@ local gridDemo = function()
if keysDown[keys.q] then if keysDown[keys.q] then
return "end" return "end"
end end
drawGrid(scrollX, scrollY) drawGrid(scrollX, scrollY, false, true)
ageTrails() ageTrails()
sleep(gameDelay) sleep(gameDelay)
end end
@ -917,7 +912,7 @@ local game = function()
scrollX = p.x - mathfloor(scr_x / 2) scrollX = p.x - mathfloor(scr_x / 2)
scrollY = p.y - mathfloor(scr_y / 2) scrollY = p.y - mathfloor(scr_y / 2)
render() render(true)
end end
end end
end end
@ -955,6 +950,7 @@ local networking = function()
waitingForGame = false waitingForGame = false
netKeysDown = {} netKeysDown = {}
os.queueEvent("new_game", gameID) os.queueEvent("new_game", gameID)
return gameID
elseif msg.gameID == gamename then elseif msg.gameID == gamename then
if not isHost then if not isHost then
@ -997,6 +993,7 @@ local helpScreen = function()
end end
local main = function() local main = function()
local rVal
while true do while true do
decision = titleScreen() decision = titleScreen()
lockInput = false lockInput = false
@ -1023,10 +1020,12 @@ local main = function()
gameDelay = gameDelayInit, gameDelay = gameDelayInit,
grid = initGrid grid = initGrid
}) })
parallel.waitForAny(pleaseWait, networking) rVal = parallel.waitForAny(pleaseWait, networking)
sleep(0.1) sleep(0.1)
startCountdown() if rVal == 2 then
parallel.waitForAny(getInput, game, networking) startCountdown()
parallel.waitForAny(getInput, game, networking)
end
elseif decision == "help" then elseif decision == "help" then
helpScreen() helpScreen()
elseif decision == "demo" then elseif decision == "demo" then