Browse Source

fix??

tags/online
madiwka3 4 years ago
parent
commit
bb7b784031
2 changed files with 20 additions and 7 deletions
  1. +19
    -6
      main.lua
  2. +1
    -1
      src/baseGame.lua

+ 19
- 6
main.lua View File

@@ -744,7 +744,7 @@ function love.update(dt)
if ts > updaterate then if ts > updaterate then
clienttest(dt) clienttest(dt)
ts = ts - updaterate ts = ts - updaterate
end
end
end end


@@ -783,14 +783,20 @@ function nettest(dt)
"|HOST") "|HOST")
print("SENT: " .. lastSentKey) print("SENT: " .. lastSentKey)
end end
data = udp:receive()

local data
local datanumtest = 0
repeat
datanumtest = datanumtest + 1
print("LATENCY: " .. tostring(datanumtest))
data = udp:receive()
if data then if data then
confirmation = "N" confirmation = "N"
local p = split(data, '|') local p = split(data, '|')
if p[3] ~= "CLIENT" then if p[3] ~= "CLIENT" then
confirmation = "U" confirmation = "U"
end end
if tonumber(p[4]) > 5 then
if tonumber(p[4]) > 90 then
confirmation = "L" confirmation = "L"
end end
lastSentKeyClient = p[1] lastSentKeyClient = p[1]
@@ -801,6 +807,7 @@ function nettest(dt)
confirmation = "D" confirmation = "D"
print("NO PLAYER 2!!") print("NO PLAYER 2!!")
end end
until not data
end end
function clienttest(dt) function clienttest(dt)
if clientinit == false then if clientinit == false then
@@ -810,14 +817,20 @@ function clienttest(dt)
udp = socket.udp() udp = socket.udp()
udp:setpeername(address, port) udp:setpeername(address, port)
udp:settimeout(0) udp:settimeout(0)
udp:send(tostring(lastSentKey) .. '|' .. tostring(player2.y) .. "|CLIENT")
clientinit = true clientinit = true
end end
udp:send(tostring(lastSentKey) .. '|' .. tostring(player2.y) .. "|CLIENT")
print("SENT TO SERVER:" .. lastSentKey)
local data
local datanumtest = 0
repeat
datanumtest = datanumtest + 1
print("LATENCY: " .. tostring(datanumtest))
data = udp:receive() data = udp:receive()
if data then if data then
print(data) print(data)
udp:send(tostring(lastSentKey) .. '|' .. tostring(player2.y) .. "|CLIENT")
print("SENT TO SERVER:" .. lastSentKey)
confirmation = "N" confirmation = "N"
local p = split(data, '|') local p = split(data, '|')
if p[13] then if p[13] then
@@ -836,7 +849,7 @@ function clienttest(dt)
confirmation = "D" confirmation = "D"
end end
print("GOT: " .. lastSentKeyClient) print("GOT: " .. lastSentKeyClient)
until not data
end end
function wallbreaker(x, y) function wallbreaker(x, y)
if (gameState == "editor") then if (gameState == "editor") then


+ 1
- 1
src/baseGame.lua View File

@@ -995,7 +995,7 @@ function clientsBaseGame(dt)
print("moving player1 down") print("moving player1 down")
else else
player1.dy = 0 player1.dy = 0
print("stopping player")
-- print("stopping player")
end end
if ((love.keyboard.isDown(p2control.up))) then if ((love.keyboard.isDown(p2control.up))) then
player2.dy = (paddle_SPEED + p2bonus) * -1 player2.dy = (paddle_SPEED + p2bonus) * -1


Loading…
Cancel
Save