1
0
mirror of https://github.com/LDDestroier/CC/ synced 2024-12-14 12:10:29 +00:00

Update tron

This commit is contained in:
LDDestroier 2018-11-15 00:19:10 -05:00 committed by GitHub
parent fa9bbaabfa
commit cc0a92f5a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

45
tron
View File

@ -598,9 +598,10 @@ local gridDemo = function()
end end
end end
local sendInfo = function(gameID) local sendInfo = function(gameID, nextTurn)
modem.transmit(port, port, { modem.transmit(port, port, {
player = player, player = player,
nextTurn = nextTurn,
gameID = gameID, gameID = gameID,
keysDown = keysDown, keysDown = keysDown,
trail = isHost and trail or nil, trail = isHost and trail or nil,
@ -613,13 +614,16 @@ local waitForKey = function(time)
os.pullEvent("key") os.pullEvent("key")
end end
-- to counter P2's ability to turn twice in one tick
local nextTurn, nextPut
local deadAnimation = function(doSend) local deadAnimation = function(doSend)
for k,v in pairs(deadGuys) do for k,v in pairs(deadGuys) do
player[k].char = "X" player[k].char = "X"
lockInput = true lockInput = true
end end
if doSend then if doSend then
sendInfo(gamename) sendInfo(gamename, nextTurn)
end end
if deadGuys[you] or deadGuys[nou] then if deadGuys[you] or deadGuys[nou] then
term.setTextColor(colors.white) term.setTextColor(colors.white)
@ -669,23 +673,22 @@ local moveTick = function(doSend)
return deadAnimation(doSend) return deadAnimation(doSend)
end end
local setDirection = function(keylist, p) local setDirection = function(keylist, checkDir)
p.putTrail = not keylist[control.release] local outTrail = not keylist[control.release]
if keylist[control.left] and p.direction ~= 0 then local outDir
p.direction = 2 if keylist[control.left] and checkDir ~= 0 then
elseif keylist[control.right] and p.direction ~= 2 then outDir = 2
p.direction = 0 elseif keylist[control.right] and checkDir ~= 2 then
outDir = 0
end end
if keylist[control.up] and p.direction ~= 1 then if keylist[control.up] and checkDir ~= 1 then
p.direction = -1 outDir = -1
elseif keylist[control.down] and p.direction ~= -1 then elseif keylist[control.down] and checkDir ~= -1 then
p.direction = 1 outDir = 1
end end
return outTrail, outDir
end end
-- to counter P2's ability to turn twice in one tick
local inMidTurn = false
local game = function() local game = function()
local outcome local outcome
local p, np local p, np
@ -693,13 +696,11 @@ local game = function()
p = player[you] p = player[you]
np = player[nou] np = player[nou]
if isHost then if isHost then
setDirection(keysDown, p) p.putTrail, p.direction = setDirection(keysDown, p.direction)
setDirection(netKeysDown, np) np.putTrail, np.direction = setDirection(netKeysDown, np.direction)
elseif not inMidTurn then else
setDirection(keysDown, p) nextPut, nextTurn = setDirection(keysDown, p.direction)
inMidTurn = true
end end
if keysDown[control.lookLeft] then if keysDown[control.lookLeft] then
@ -771,10 +772,10 @@ local networking = function()
player = msg.player player = msg.player
trail = msg.trail trail = msg.trail
deadGuys = msg.deadGuys deadGuys = msg.deadGuys
inMidTurn = false
elseif type(msg.keysDown) == "table" then elseif type(msg.keysDown) == "table" then
netKeysDown = msg.keysDown netKeysDown = msg.keysDown
end end
nextTurn = nil
end end
end end