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(
"Online",
function()
MAP_TYPE = 0
gameState = "chooseIP"
end
)
@@ -291,15 +292,15 @@ function love.load()
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(
settings,
newButton(
@@ -588,6 +589,7 @@ function love.load()
function()
gameState = "1serve"
gameMode = "reversegame"
globalState = "base"
end
)
)
@@ -796,14 +798,23 @@ function nettest(dt)
print("ReceivedINFO: " .. data)
confirmation = "N"
local p = split(data, '|')
if p[3] ~= "CLIENT" then
if p[3] ~= "CLIENT" and not p[15] then
confirmation = "U"
end
if p[15] then
if p[15] ~= "CLIENT" then
confirmation = "U"
end
end
if tonumber(p[4]) > 90 then
confirmation = "L"
end
if ball[1].dx <= 0 then
lastSentKeyClient = p[1]
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
until not data
@@ -830,7 +841,25 @@ function clienttest(dt)
end
ts = ts + dt
if ts > updaterate then
if ball[1].dx <= 0 then
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
end
local data
@@ -856,9 +885,16 @@ function clienttest(dt)
end
for i = 1, maxBalls do
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
elseif p[3] ~= "HOST" then
confirmation = "U"
end
end
print("GOT: " .. lastSentKeyClient)
until not data


+ 68
- 11
src/baseGame.lua View File

@@ -1,5 +1,5 @@
function basegame(dt)
if gameMode == "reverse" then
if gameMode == "reversegame" then
reversegame(dt)
end
if player1nukescore > 300 then
@@ -89,7 +89,7 @@ function basegame(dt)
end
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
@@ -604,12 +604,7 @@ function normalDraw()
end
end

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

@@ -1056,13 +1051,19 @@ function clientsBaseGame(dt)
end
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
AI_SPEED = AI_SPEED * 1.10
end
if (synctype == 1) then
AI_SPEED = ballSpeed * 1.1 / 10
end
ballSpeed = ballSpeed * 1.10
end
player1nukescore = player1nukescore + 10
ball[i].dx = -ball[i].dx
@@ -1142,6 +1143,61 @@ function clientsBaseGame(dt)
player2nukescore = player2nukescore + 10
ball[i].dx = -ball[i].dx
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
hitIdentifier()
if ball[i].y <= 0 then
@@ -1149,7 +1205,7 @@ function clientsBaseGame(dt)
sounds["wallhit"]:setPitch(ballSpeed / 250)
sounds["wallhit"]:play()
ball[i].y = 0
ball[i].dy = -ball[i].dy
end

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


Loading…
Cancel
Save