mirror of
https://github.com/LDDestroier/CC/
synced 2024-12-14 20:20:29 +00:00
Update tron
This commit is contained in:
parent
d43f4cfe6b
commit
f2bc46852a
48
tron
48
tron
@ -598,10 +598,9 @@ local gridDemo = function()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local sendInfo = function(gameID, nextTurn)
|
local sendInfo = function(gameID)
|
||||||
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,
|
||||||
@ -614,16 +613,13 @@ 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, nextTurn)
|
sendInfo(gamename)
|
||||||
end
|
end
|
||||||
if deadGuys[you] or deadGuys[nou] then
|
if deadGuys[you] or deadGuys[nou] then
|
||||||
term.setTextColor(colors.white)
|
term.setTextColor(colors.white)
|
||||||
@ -673,22 +669,23 @@ local moveTick = function(doSend)
|
|||||||
return deadAnimation(doSend)
|
return deadAnimation(doSend)
|
||||||
end
|
end
|
||||||
|
|
||||||
local setDirection = function(keylist, checkDir)
|
local setDirection = function(keylist, p)
|
||||||
local outTrail = not keylist[control.release]
|
p.putTrail = not keylist[control.release]
|
||||||
local outDir
|
if keylist[control.left] and p.direction ~= 0 then
|
||||||
if keylist[control.left] and checkDir ~= 0 then
|
p.direction = 2
|
||||||
outDir = 2
|
elseif keylist[control.right] and p.direction ~= 2 then
|
||||||
elseif keylist[control.right] and checkDir ~= 2 then
|
p.direction = 0
|
||||||
outDir = 0
|
|
||||||
end
|
end
|
||||||
if keylist[control.up] and checkDir ~= 1 then
|
if keylist[control.up] and p.direction ~= 1 then
|
||||||
outDir = -1
|
p.direction = -1
|
||||||
elseif keylist[control.down] and checkDir ~= -1 then
|
elseif keylist[control.down] and p.direction ~= -1 then
|
||||||
outDir = 1
|
p.direction = 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
|
||||||
@ -696,11 +693,13 @@ local game = function()
|
|||||||
p = player[you]
|
p = player[you]
|
||||||
np = player[nou]
|
np = player[nou]
|
||||||
|
|
||||||
|
|
||||||
if isHost then
|
if isHost then
|
||||||
p.putTrail, p.direction = setDirection(keysDown, p.direction)
|
setDirection(keysDown, p)
|
||||||
np.putTrail, np.direction = setDirection(netKeysDown, np.direction)
|
setDirection(netKeysDown, np)
|
||||||
else
|
elseif not inMidTurn then
|
||||||
nextPut, nextTurn = setDirection(keysDown, p.direction)
|
setDirection(keysDown, p)
|
||||||
|
inMidTurn = true
|
||||||
end
|
end
|
||||||
|
|
||||||
if keysDown[control.lookLeft] then
|
if keysDown[control.lookLeft] then
|
||||||
@ -770,15 +769,12 @@ local networking = function()
|
|||||||
elseif msg.gameID == gamename then
|
elseif msg.gameID == gamename then
|
||||||
if not isHost then
|
if not isHost then
|
||||||
player = msg.player
|
player = msg.player
|
||||||
if nextTurn then
|
|
||||||
player[nou].direction = nextTurn
|
|
||||||
end
|
|
||||||
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
|
||||||
|
Loading…
Reference in New Issue
Block a user