mirror of
https://github.com/LDDestroier/CC/
synced 2025-03-30 15:26:55 +00:00
Host only sends last two trails placed now
This commit is contained in:
parent
df8b88985f
commit
58c9adf123
34
tron
34
tron
@ -76,6 +76,7 @@ local player
|
|||||||
local resetPlayers = function()
|
local resetPlayers = function()
|
||||||
player = {
|
player = {
|
||||||
[1] = {
|
[1] = {
|
||||||
|
num = 1,
|
||||||
x = -2,
|
x = -2,
|
||||||
y = -5,
|
y = -5,
|
||||||
direction = -1,
|
direction = -1,
|
||||||
@ -95,6 +96,7 @@ local resetPlayers = function()
|
|||||||
putTrail = true
|
putTrail = true
|
||||||
},
|
},
|
||||||
[2] = {
|
[2] = {
|
||||||
|
num = 2,
|
||||||
x = 2,
|
x = 2,
|
||||||
y = -5,
|
y = -5,
|
||||||
direction = -1,
|
direction = -1,
|
||||||
@ -252,15 +254,20 @@ end
|
|||||||
|
|
||||||
local deadGuys = {}
|
local deadGuys = {}
|
||||||
local trail = {}
|
local trail = {}
|
||||||
|
local lastTrails = {}
|
||||||
|
|
||||||
local putTrail = function(p)
|
local putTrailXY = function(x, y, p)
|
||||||
trail[p.y] = trail[p.y] or {}
|
trail[y] = trail[y] or {}
|
||||||
trail[p.y][p.x] = {
|
trail[y][x] = {
|
||||||
player = p,
|
player = player[p],
|
||||||
age = 0
|
age = 0
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local putTrail = function(p)
|
||||||
|
putTrailXY(p.x, p.y, p.num)
|
||||||
|
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
|
||||||
@ -649,7 +656,7 @@ local sendInfo = function(gameID)
|
|||||||
player = player,
|
player = player,
|
||||||
gameID = gameID,
|
gameID = gameID,
|
||||||
keysDown = keysDown,
|
keysDown = keysDown,
|
||||||
trail = isHost and trail or nil,
|
trail = isHost and lastTrails or {},
|
||||||
deadGuys = isHost and deadGuys or {},
|
deadGuys = isHost and deadGuys or {},
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
@ -705,6 +712,10 @@ local moveTick = function(doSend)
|
|||||||
deadGuys[i] = true
|
deadGuys[i] = true
|
||||||
elseif p.putTrail then
|
elseif p.putTrail then
|
||||||
putTrail(p)
|
putTrail(p)
|
||||||
|
lastTrails[#lastTrails+1] = {p.x, p.y, p.num}
|
||||||
|
if #lastTrails > #player then
|
||||||
|
table.remove(lastTrails, 1)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
for a = 1, #player do
|
for a = 1, #player do
|
||||||
@ -720,7 +731,6 @@ local moveTick = function(doSend)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
ageTrails()
|
|
||||||
return deadAnimation(doSend)
|
return deadAnimation(doSend)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -741,6 +751,9 @@ local game = function()
|
|||||||
local outcome
|
local outcome
|
||||||
local p, np
|
local p, np
|
||||||
while true do
|
while true do
|
||||||
|
if not isHost then
|
||||||
|
os.pullEvent("move_tick")
|
||||||
|
end
|
||||||
p = player[you]
|
p = player[you]
|
||||||
np = player[nou]
|
np = player[nou]
|
||||||
|
|
||||||
@ -772,7 +785,7 @@ local game = function()
|
|||||||
else
|
else
|
||||||
outcome = deadAnimation(true)
|
outcome = deadAnimation(true)
|
||||||
end
|
end
|
||||||
|
ageTrails()
|
||||||
if outcome == "end" then
|
if outcome == "end" then
|
||||||
return
|
return
|
||||||
else
|
else
|
||||||
@ -780,9 +793,11 @@ local game = function()
|
|||||||
scrollY = p.y - math.floor(scr_y / 2)
|
scrollY = p.y - math.floor(scr_y / 2)
|
||||||
|
|
||||||
render()
|
render()
|
||||||
|
if isHost then
|
||||||
sleep(gameDelay)
|
sleep(gameDelay)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local decision
|
local decision
|
||||||
@ -818,8 +833,11 @@ 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
|
||||||
trail = msg.trail
|
for i = 1, #msg.trail do
|
||||||
|
putTrailXY(unpack(msg.trail[i]))
|
||||||
|
end
|
||||||
deadGuys = msg.deadGuys
|
deadGuys = msg.deadGuys
|
||||||
|
os.queueEvent("move_tick")
|
||||||
elseif type(msg.keysDown) == "table" then
|
elseif type(msg.keysDown) == "table" then
|
||||||
netKeysDown = msg.keysDown
|
netKeysDown = msg.keysDown
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user