Browse Source

C

tags/online
madiwka3 4 years ago
parent
commit
ddb095eec0
4 changed files with 50 additions and 35 deletions
  1. +1
    -1
      main.lua
  2. +1
    -1
      readme.md
  3. +47
    -32
      server/server.lua
  4. +1
    -1
      src/baseGame.lua

+ 1
- 1
main.lua View File

@@ -1361,7 +1361,7 @@ function love.draw()
baseDraw()
if (globalState == "nettest" or globalState == "clienttest") and confirmation == "D" then
love.graphics.clear(50 / 255, 50 / 255, 50 / 255, 255)
love.graphics.printf("WAIT FOR PLAYER 2", 0, VIRTUAL_HEIGHT / 2, VIRTUAL_WIDTH, "center")
love.graphics.printf("WAIT FOR OPPONENT", 0, VIRTUAL_HEIGHT / 2, VIRTUAL_WIDTH, "center")
end
if (globalState == "nettest" or globalState == "clienttest") and confirmation == "U" then
love.graphics.clear(50 / 255, 50 / 255, 50 / 255, 255)


+ 1
- 1
readme.md View File

@@ -32,4 +32,4 @@ To play on Windows, download and install <a href = "https://love2d.org">Love</a>
To play an old, outdated EXE version on Windows, head to <a href = "https://madi-wka.club/Downloads.php">my website</a>, and download the old, outdated game.

# Changes
<p>0.7.6 is here! With this update, I improved the AI, allowing it to follow 2 balls at the same time! I also added "Smart" difficulty, where the AI uses physics and math to pre-calculate where the ball is going to land. Alpha-testing of the Online gameplay is now here, although its stupid and doesnt work. </p>
<p>0.7.7 is here! Wiht this uodate, Online mode FINALLY, FINALLY WORKS! The default IP is my server, but you can launch the server from anywhere! The code for the server is under the server/ directory. The client is kind of laggy, though. I am trying my best to fix the issue. </p>

+ 47
- 32
server/server.lua View File

@@ -1,15 +1,20 @@
local running = true
local socket = require 'socket'
local udp = socket.udp()
local player1ip, player2ip, p1data, p2data, player1port, player2port = "none", "none", nil, nil, nil, nil
local player1ip, player2ip, player1port, player2port = "none", "none", nil, nil
udp:settimeout(0)
udp:setsockname('*', 12345)
local p1ping = 0
local p2ping = 0
local data, msg_or_ip, port_or_nil
while running do
local data, msg_or_ip, port_or_nil
local p1data, p2data
repeat
data, msg_or_ip, port_or_nil = udp:receivefrom()
if data then
print(string.sub(data,1,1) .. "Playerlist: " .. player1ip .. " " .. player2ip)
if (player1ip == msg_or_ip) then
p1ping = 0
p1data = data
@@ -20,11 +25,13 @@ while running do
if (player1ip == "none") then
player1ip = msg_or_ip
p1data = data
p1ping = 0
player1port = port_or_nil
print("CONNECTED: PLAYER 1 FROM: " .. player1ip)
elseif player2ip == "none" and msg_or_ip ~= player1ip then
player2ip = msg_or_ip
p2data = data
p2ping = 0
player2port = port_or_nil
print("CONNECTED: PLAYER 2 FROM: " .. player2ip)
elseif (player1ip ~= msg_or_ip and player2ip ~= msg_or_ip) then
@@ -32,38 +39,46 @@ while running do
end
end


elseif player1ip ~= "none" then
p1ping = p1ping + 1
if p1ping > 5 then
if p2data then
udp:sendto(p2data .. '|' .. p1ping, player1ip, player1port)
end
print("PLAYER 1 DISCONNECTED")
p1data = nil
player1ip = "none"
player1port = nil
end
elseif player2ip ~= "none" then
p2ping = p2ping + 1
if p2ping > 5 then
if p1data then
udp:sendto(p1data .. '|' .. p2ping, player2ip, player2port)
end
print("PLAYER 2 DISCONNECTED")
p2data = nil
player2ip = "none"
player2port = nil
else
end
until not data
if player1ip ~= "none" then
p1ping = p1ping + 1
if p1ping > 100 then
if p2data then
udp:sendto(p2data .. '|' .. p1ping, player1ip, player1port)
end
print("PLAYER 1 DISCONNECTED")
p1data = nil
player1ip = "none"
player1port = nil
end
if data then
print(data .. "FROM " .. msg_or_ip .. "Playerlist: " .. player1ip .. " " .. player2ip)
end
if p1data and p2data then
end
if player2ip ~= "none" then
p2ping = p2ping + 1
if p2ping > 100 then
if p1data then
udp:sendto(p1data .. '|' .. p2ping, player2ip, player2port)
udp:sendto(p2data .. '|' .. p1ping, player1ip, player1port)
print("SENT1: " .. player2ip .. " " .. player2port .. " " .. p1data)
print("SENT2: " .. player1ip .. " " .. player1port .. " " .. p2data)
end
print("PLAYER 2 DISCONNECTED")
p2data = nil
player2ip = "none"
player2port = nil
end
socket.sleep(0.01)
end
if p1data and player2port then
udp:sendto(p1data .. '|' .. p2ping, player2ip, player2port)
print("SENT TO " .. player2ip .. ":" .. player2port .. " : " .. string.sub(p1data,1,1))
end
if p2data and player1port then
udp:sendto(p2data .. '|' .. p1ping, player1ip, player1port)
print("SENT TO " .. player1ip .. ":" .. player1port .. " : " .. string.sub(p2data,1,1))
--print("1::" .. p1data)
--print("2::" .. p2data)
--print("SENT1: " .. player2ip .. " " .. player2port .. " " .. p1data)
--print("SENT2: " .. player1ip .. " " .. player1port .. " " .. p2data)
end
socket.sleep(0.015)

end

+ 1
- 1
src/baseGame.lua View File

@@ -355,7 +355,7 @@ end
function debugCheck(dt)
if (gameState == "menu") then
updateTEXT = "0.7.6 Chalkboard Update"
updateTEXT = "0.7.7 Chalkboard Update"
end
dangerChecker()
elapsed = elapsed + dt


Loading…
Cancel
Save