Browse Source

Trying to compensate lag

tags/online1.1
Madiwka 4 years ago
parent
commit
a55b6ced92
2 changed files with 116 additions and 23 deletions
  1. +48
    -12
      main.lua
  2. +68
    -11
      src/baseGame.lua

+ 48
- 12
main.lua View File

@@ -201,6 +201,7 @@ function love.load()
newButton( newButton(
"Online", "Online",
function() function()
MAP_TYPE = 0
gameState = "chooseIP" gameState = "chooseIP"
end end
) )
@@ -291,15 +292,15 @@ function love.load()
end end
) )
) )
table.insert(
settings,
newButton(
"Change Map",
function()
MAP_TYPE = MAP_TYPE + 1
end
)
)
--table.insert(
-- settings,
-- newButton(
-- "Change Map",
-- function()
-- MAP_TYPE = MAP_TYPE + 1
-- end
-- )
--)
table.insert( table.insert(
settings, settings,
newButton( newButton(
@@ -588,6 +589,7 @@ function love.load()
function() function()
gameState = "1serve" gameState = "1serve"
gameMode = "reversegame" gameMode = "reversegame"
globalState = "base"
end end
) )
) )
@@ -796,14 +798,23 @@ function nettest(dt)
print("ReceivedINFO: " .. data) print("ReceivedINFO: " .. data)
confirmation = "N" confirmation = "N"
local p = split(data, '|') local p = split(data, '|')
if p[3] ~= "CLIENT" then
if p[3] ~= "CLIENT" and not p[15] then
confirmation = "U" confirmation = "U"
end end
if p[15] then
if p[15] ~= "CLIENT" then
confirmation = "U"
end
end
if tonumber(p[4]) > 90 then if tonumber(p[4]) > 90 then
confirmation = "L" confirmation = "L"
end end
if ball[1].dx <= 0 then
lastSentKeyClient = p[1] lastSentKeyClient = p[1]
player2.y = tonumber(p[2]) player2.y = tonumber(p[2])
elseif ball[1].dx > 0 then
lastSentKeyClient, ball[i].dy, player2.y, player1score, player2score, player1nukescore, player2nukescore, ball[i].x, ball[i].y, gameState, ball[i].dx, ballSpeed, paddle_SPEED = p[1], die, tonumber(p[4]), tonumber(p[5]), tonumber(p[6]), tonumber(p[7]), tonumber(p[8]), tonumber(p[9]), tonumber(p[10]), p[11], tonumber(p[12]), tonumber(p[13]), tonumber(p[14])
end
end end
until not data until not data
@@ -830,7 +841,25 @@ function clienttest(dt)
end end
ts = ts + dt ts = ts + dt
if ts > updaterate then if ts > updaterate then
if ball[1].dx <= 0 then
udp:send(tostring(lastSentKey) ..'|' .. player2.y .. "|CLIENT") udp:send(tostring(lastSentKey) ..'|' .. player2.y .. "|CLIENT")
elseif ball[1].dx > 0 then
udp:send(tostring(lastSentKey) ..
'|' .. tostring(ball[1].dy) ..
'|' .. tostring(player1.y) ..
'|' .. tostring(player2.y) ..
'|' .. tostring(player1score) ..
'|' .. tostring(player2score) ..
'|' .. tostring(player1nukescore) ..
'|' .. tostring(player2nukescore) ..
'|' .. tostring(ball[1].x) ..
'|' .. tostring(ball[1].y) ..
'|' .. gameState ..
'|' .. tostring(ball[1].dx) ..
'|' .. tostring(ballSpeed) ..
'|' .. tostring(paddle_SPEED) ..
"|CLIENT")
end
ts = 0 ts = 0
end end
local data local data
@@ -856,9 +885,16 @@ function clienttest(dt)
end end
for i = 1, maxBalls do for i = 1, maxBalls do
local die = tonumber(p[2]) local die = tonumber(p[2])
lastSentKeyClient, ball[i].dy, player1.y, player1score, player2score, player1nukescore, player2nukescore, ball[i].x, ball[i].y, gameState, ball[i].dx, ballSpeed, paddle_SPEED = p[1], die, tonumber(p[4]), tonumber(p[5]), tonumber(p[6]), tonumber(p[7]), tonumber(p[8]), tonumber(p[9]), tonumber(p[10]), p[11], tonumber(p[12]), tonumber(p[13]), tonumber(p[14])
if ball[i].dx <= 0 then
lastSentKeyClient, ball[i].dy, player1.y, player1score, player2score, player1nukescore, player2nukescore, ball[i].x, ball[i].y, gameState, ball[i].dx, ballSpeed, paddle_SPEED = p[1], die, tonumber(p[4]), tonumber(p[5]), tonumber(p[6]), tonumber(p[7]), tonumber(p[8]), tonumber(p[9]), tonumber(p[10]), p[11], tonumber(p[12]), tonumber(p[13]), tonumber(p[14])
elseif ball[i].dx > 0 then
lastSentKeyClient = p[1]
player1.y = tonumber(p[4])
end end
end
end
elseif p[3] ~= "HOST" then
confirmation = "U"
end
end end
print("GOT: " .. lastSentKeyClient) print("GOT: " .. lastSentKeyClient)
until not data until not data


+ 68
- 11
src/baseGame.lua View File

@@ -1,5 +1,5 @@
function basegame(dt) function basegame(dt)
if gameMode == "reverse" then
if gameMode == "reversegame" then
reversegame(dt) reversegame(dt)
end end
if player1nukescore > 300 then if player1nukescore > 300 then
@@ -89,7 +89,7 @@ function basegame(dt)
end end
if (striken == 1) then if (striken == 1) then
player1nukescore = player1nukescore * 1.2
player1nukescore = player1nukescore * 1.5
if (synctype == 0) then if (synctype == 0) then
paddle_SPEED = paddle_SPEED * 1.10 paddle_SPEED = paddle_SPEED * 1.10
elseif (synctype == 1) then elseif (synctype == 1) then
@@ -604,12 +604,7 @@ function normalDraw()
end end
end end


if gameMode == 'practice' then
practiceDraw()
end
if gameMode == 'normal' then
pongDraw()
end
pongDraw()
love.graphics.setFont(smallfont) love.graphics.setFont(smallfont)
for i = 1, maxBalls do for i = 1, maxBalls do
if areanuclear == 1 then if areanuclear == 1 then
@@ -743,7 +738,7 @@ function baseDraw()
nuclearDraw() nuclearDraw()
end end
if gameState == 'play' or gameState == '1serve' or gameState == '2serve' or gameState == 'done' then if gameState == 'play' or gameState == '1serve' or gameState == '2serve' or gameState == 'done' then
--print("Drawing normally")
print("Drawing normally")
normalDraw() normalDraw()
end end


@@ -1056,13 +1051,19 @@ function clientsBaseGame(dt)
end end
if (striken == 1) then if (striken == 1) then
player1nukescore = player1nukescore * 1.2
player1nukescore = player1nukescore * 1.5
if (synctype == 0) then
paddle_SPEED = paddle_SPEED * 1.10
elseif (synctype == 1) then
paddle_SPEED = ballSpeed / 10
end
if (synctype == 0) then if (synctype == 0) then
AI_SPEED = AI_SPEED * 1.10 AI_SPEED = AI_SPEED * 1.10
end end
if (synctype == 1) then if (synctype == 1) then
AI_SPEED = ballSpeed * 1.1 / 10 AI_SPEED = ballSpeed * 1.1 / 10
end end
ballSpeed = ballSpeed * 1.10
end end
player1nukescore = player1nukescore + 10 player1nukescore = player1nukescore + 10
ball[i].dx = -ball[i].dx ball[i].dx = -ball[i].dx
@@ -1142,6 +1143,61 @@ function clientsBaseGame(dt)
player2nukescore = player2nukescore + 10 player2nukescore = player2nukescore + 10
ball[i].dx = -ball[i].dx ball[i].dx = -ball[i].dx
ball[i].x = player2.x - 30 ball[i].x = player2.x - 30
if ((love.keyboard.isDown(p2control.up))) then
select = math.random(1, 5)
if select == 1 then
ball[i].dy = -1
elseif select == 2 then
ball[i].dy = -1.2
elseif select == 3 then
ball[i].dy = -1.5
elseif select == 4 then
ball[i].dy = -1.8
elseif select == 5 then
ball[i].dy = -2
end
elseif (love.keyboard.isDown(p2control.down))then
select = math.random(1, 5)
if select == 1 then
ball[i].dy = 1
elseif select == 2 then
ball[i].dy = 1.2
elseif select == 3 then
ball[i].dy = 1.5
elseif select == 4 then
ball[i].dy = 1.8
elseif select == 5 then
ball[i].dy = 2
end
else
if ball[i].dy < 0 then
select = math.random(1, 5)
if select == 1 then
ball[i].dy = -1
elseif select == 2 then
ball[i].dy = -1.2
elseif select == 3 then
ball[i].dy = -1.5
elseif select == 4 then
ball[i].dy = -1.8
elseif select == 5 then
ball[i].dy = -2
end
else
select = math.random(1, 5)
if select == 1 then
ball[i].dy = 1
elseif select == 2 then
ball[i].dy = 1.2
elseif select == 3 then
ball[i].dy = 1.5
elseif select == 4 then
ball[i].dy = 1.8
elseif select == 5 then
ball[i].dy = 2
end
end
end
end end
hitIdentifier() hitIdentifier()
if ball[i].y <= 0 then if ball[i].y <= 0 then
@@ -1149,7 +1205,7 @@ function clientsBaseGame(dt)
sounds["wallhit"]:setPitch(ballSpeed / 250) sounds["wallhit"]:setPitch(ballSpeed / 250)
sounds["wallhit"]:play() sounds["wallhit"]:play()
ball[i].y = 0 ball[i].y = 0
ball[i].dy = -ball[i].dy
end end


-- -4 to account for the ball's size -- -4 to account for the ball's size
@@ -1158,6 +1214,7 @@ function clientsBaseGame(dt)
sounds["wallhit"]:setPitch(ballSpeed / 250) sounds["wallhit"]:setPitch(ballSpeed / 250)
sounds["wallhit"]:play() sounds["wallhit"]:play()
ball[i].y = VIRTUAL_HEIGHT - 40 ball[i].y = VIRTUAL_HEIGHT - 40
ball[i].dy = -ball[i].dy
end end
--love.window.setTitle('Trying to update the ball') --love.window.setTitle('Trying to update the ball')


Loading…
Cancel
Save