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