@@ -30,13 +30,14 @@ hitNum = {}  
														
													
														
															
																hitNum[1] = 0 hitNum[1] = 0  
														
													
														
															
																hitNum[2] = 0 hitNum[2] = 0  
														
													
														
															
																hitNum[3] = 0 hitNum[3] = 0  
														
													
														
															
																confirmation = "disconnected "  
														
													
														
															
																confirmation = "N "  
														
													
														
															
																hitNum[4] = 0 hitNum[4] = 0  
														
													
														
															
																p1bonus = 0 p1bonus = 0  
														
													
														
															
																p2bonus = 0 p2bonus = 0  
														
													
														
															
																hitNum[5] = 0 hitNum[5] = 0  
														
													
														
															
																hitNum[6] = 0 hitNum[6] = 0  
														
													
														
															
																GREEN = 255 GREEN = 255  
														
													
														
															
																IP = '45.76.95.31'  
														
													
														
															
																BLUE = 255 BLUE = 255  
														
													
														
															
																updateTEXT = "Chalkboard Update" updateTEXT = "Chalkboard Update"  
														
													
														
															
																maxBalls = 1 maxBalls = 1  
														
													
												
													
														
															
																
																	
																		 
																@@ -125,6 +126,7 @@ function newWall(wallx, wally, wallwidth, wallheight)  
														
													
														
															
																end end  
														
													
														
															
																speedParameters = {} speedParameters = {}  
														
													
														
															
																buttons = {} buttons = {}  
														
													
														
															
																IPselect = {}  
														
													
														
															
																difbuttons = {} difbuttons = {}  
														
													
														
															
																settings = {} settings = {}  
														
													
														
															
																walls = {} walls = {}  
														
													
												
													
														
															
																
																	
																	
																	
																		 
																@@ -140,6 +142,7 @@ function controlChanger()  
														
													
														
															
																    end     end  
														
													
														
															
																end end  
														
													
														
															
																function love.load() function love.load()  
														
													
														
															
																    love.keyboard.setKeyRepeat(true)  
														
													
														
															
																    simpleScale.setWindow(VIRTUAL_WIDTH, VIRTUAL_HEIGHT, WINDOW_WIDTH, WINDOW_HEIGHT)     simpleScale.setWindow(VIRTUAL_WIDTH, VIRTUAL_HEIGHT, WINDOW_WIDTH, WINDOW_HEIGHT)  
														
													
														
															
																    configfile = io.open("config.lua", "r")     configfile = io.open("config.lua", "r")  
														
													
														
															
																    configsave = io.open("config.lua", "w")     configsave = io.open("config.lua", "w")  
														
													
												
													
														
															
																
																	
																		 
																@@ -196,7 +199,16 @@ function love.load()  
														
													
														
															
																    table.insert(     table.insert(  
														
													
														
															
																        buttons,         buttons,  
														
													
														
															
																        newButton(         newButton(  
														
													
														
															
																            "Online Test",  
														
													
														
															
																            "Online",  
														
													
														
															
																            function()  
														
													
														
															
																                gameState = "chooseIP"  
														
													
														
															
																            end  
														
													
														
															
																        )  
														
													
														
															
																    )  
														
													
														
															
																    table.insert(  
														
													
														
															
																        IPselect,  
														
													
														
															
																        newButton(  
														
													
														
															
																            "Host",  
														
													
														
															
																            function()             function()  
														
													
														
															
																                globalState = "nettest"                 globalState = "nettest"  
														
													
														
															
																                AGAINST_AI = 0                  AGAINST_AI = 0   
														
													
												
													
														
															
																
																	
																	
																	
																		 
																@@ -205,9 +217,9 @@ function love.load()  
														
													
														
															
																        )         )  
														
													
														
															
																    )     )  
														
													
														
															
																    table.insert(     table.insert(  
														
													
														
															
																        buttons ,  
														
													
														
															
																        IPselect ,  
														
													
														
															
																        newButton(         newButton(  
														
													
														
															
																            "Client T est",  
														
													
														
															
																            "Gu est",  
														
													
														
															
																            function()             function()  
														
													
														
															
																                globalState = "clienttest"                 globalState = "clienttest"  
														
													
														
															
																                AGAINST_AI = 0                  AGAINST_AI = 0   
														
													
												
													
														
															
																
																	
																		 
																@@ -700,7 +712,7 @@ function love.update(dt)  
														
													
														
															
																    print("IMPORTANT!!!!!" .. globalState .. gameState)     print("IMPORTANT!!!!!" .. globalState .. gameState)  
														
													
														
															
																    staticanimatorcounter(dt)     staticanimatorcounter(dt)  
														
													
														
															
																    musicController('norm', 1)     musicController('norm', 1)  
														
													
														
															
																    ts = ts + dt    
														
													
														
															
																      
														
													
														
															
																    if debug then     if debug then  
														
													
														
															
																        displayFPS()         displayFPS()  
														
													
														
															
																    end     end  
														
													
												
													
														
															
																
																	
																	
																	
																		 
																@@ -712,7 +724,11 @@ function love.update(dt)  
														
													
														
															
																    end     end  
														
													
														
															
																           
														
													
														
															
																    if globalState == "nettest" then      if globalState == "nettest" then   
														
													
														
															
																        basegame(dt)  
														
													
														
															
																        print("Confcode: " .. confirmation)  
														
													
														
															
																        ts = ts + dt   
														
													
														
															
																        if confirmation == "N" then   
														
													
														
															
																            basegame(dt)  
														
													
														
															
																        end  
														
													
														
															
																        if ts > updaterate then          if ts > updaterate then   
														
													
														
															
																            nettest(dt)             nettest(dt)  
														
													
														
															
																            ts = ts - updaterate             ts = ts - updaterate  
														
													
												
													
														
															
																
																	
																	
																	
																		 
																@@ -720,7 +736,8 @@ function love.update(dt)  
														
													
														
															
																                   
														
													
														
															
																    end     end  
														
													
														
															
																    if globalState == "clienttest" then     if globalState == "clienttest" then  
														
													
														
															
																        if confirmation ~= "disconnected" then   
														
													
														
															
																        ts = ts + dt   
														
													
														
															
																        if confirmation == "N" then   
														
													
														
															
																            lastSentKeyP1 = lastSentKeyClient             lastSentKeyP1 = lastSentKeyClient  
														
													
														
															
																        clientsBaseGame(dt)          clientsBaseGame(dt)   
														
													
														
															
																        end         end  
														
													
												
													
														
															
																
																	
																	
																	
																		 
																@@ -734,10 +751,16 @@ function love.update(dt)  
														
													
														
															
																end end  
														
													
														
															
																serverinit = false  serverinit = false   
														
													
														
															
																clientinit = false  clientinit = false   
														
													
														
															
																function love.textinput(t)  
														
													
														
															
																    if gameState == "chooseIP" then   
														
													
														
															
																    IP = IP .. t   
														
													
														
															
																    end   
														
													
														
															
																end  
														
													
														
															
																function nettest(dt) function nettest(dt)  
														
													
														
															
																    if serverinit == false then      if serverinit == false then   
														
													
														
															
																        local socket = require "socket"         local socket = require "socket"  
														
													
														
															
																        local address, port = '45.76.95.31', 12345  
														
													
														
															
																        local address, port = IP, 12345  
														
													
														
															
																        print(address)  
														
													
														
															
																        udp = socket.udp()         udp = socket.udp()  
														
													
														
															
																        udp:setpeername(address, port)         udp:setpeername(address, port)  
														
													
														
															
																        udp:settimeout(0)         udp:settimeout(0)  
														
													
												
													
														
															
																
																	
																	
																	
																		 
																@@ -745,39 +768,59 @@ function nettest(dt)  
														
													
														
															
																    end      end   
														
													
														
															
																    for i = 1, maxBalls do      for i = 1, maxBalls do   
														
													
														
															
																        print (tostring(ball[i].dy))         print (tostring(ball[i].dy))  
														
													
														
															
																    udp:send(tostring(lastSentKey) ..'|'.. tostring(ball[i].dy) .. '|' .. tostring(player2.y) .. '|' .. tostring(player1.y) .. '|' .. tostring(player1score) .. '|' .. tostring(player2score) .. '|' .. tostring(player1nukescore) .. '|' .. tostring(player2nukescore) .. "|confirmed|" ..  tostring(ball[i].x) .. '|' .. tostring(ball[i].y) .. '|' .. gameState .. '|' .. tostring(ball[i].dx))  
														
													
														
															
																    print("SENT: " .. lastSentKey)  
														
													
														
															
																    udp:send(tostring(lastSentKey) ..'|'.. tostring(ball[i].dy) .. '|' .. tostring(player2.y) .. '|' .. tostring(player1.y) .. '|' .. tostring(player1score) .. '|' .. tostring(player2score) .. '|' .. tostring(player1nukescore) .. '|' .. tostring(player2nukescore) .. tostring(ball[i].x) .. '|' .. tostring(ball[i].y) .. '|' .. gameState .. '|' .. tostring(ball[i].dx) .. "|HOST" )  
														
													
														
															
																    print("SENT: " .. lastSentKey .. " TO ADDRESS: " .. IP )  
														
													
														
															
																    end      end   
														
													
														
															
																    data = udp:receive()      data = udp:receive()   
														
													
														
															
																	if data then  
														
													
														
															
																		local p = split(data, '|')  
														
													
														
															
																    if data then  
														
													
														
															
																        confirmation = "N"  
														
													
														
															
																        local p = split(data, '|')  
														
													
														
															
																        if p[3] ~= "CLIENT" then   
														
													
														
															
																            confirmation = "U"  
														
													
														
															
																        end  
														
													
														
															
																        if tonumber(p[4]) > 5 then   
														
													
														
															
																            confirmation = "L"  
														
													
														
															
																        end  
														
													
														
															
																        lastSentKeyClient = p[1]         lastSentKeyClient = p[1]  
														
													
														
															
																	end  
														
													
														
															
																        player2.y = tonumber(p[2])  
														
													
														
															
																          
														
													
														
															
																          
														
													
														
															
																    else   
														
													
														
															
																        confirmation = "D"  
														
													
														
															
																        print("NO PLAYER 2!!")  
														
													
														
															
																    end   
														
													
														
															
																end end  
														
													
														
															
																function clienttest(dt)  function clienttest(dt)   
														
													
														
															
																    if clientinit == false then      if clientinit == false then   
														
													
														
															
																        local socket = require "socket"         local socket = require "socket"  
														
													
														
															
																        local address, port = '45.76.95.31', 12345  
														
													
														
															
																        local address, port = IP, 12345  
														
													
														
															
																          
														
													
														
															
																        udp = socket.udp()         udp = socket.udp()  
														
													
														
															
																        udp:setpeername(address, port)         udp:setpeername(address, port)  
														
													
														
															
																        udp:settimeout(0)         udp:settimeout(0)  
														
													
														
															
																        clientinit = true          clientinit = true   
														
													
														
															
																    end     end  
														
													
														
															
																    udp:send(tostring(lastSentKey))  
														
													
														
															
																    print("SENT TO SERVER:" ..  lastSentKey)  
														
													
														
															
																    udp:send(tostring(lastSentKey) .. '|' .. tostring(player2.y) .. "|CLIENT" )  
														
													
														
															
																    print("SENT TO SERVER:" ..  lastSentKey .. " AT ADDRESS: " .. IP )  
														
													
														
															
																    data = udp:receive()     data = udp:receive()  
														
													
														
															
																    --print(data)     --print(data)  
														
													
														
															
																	if data then  
														
													
														
															
																    if data then  
														
													
														
															
																        confirmation = "N"  
														
													
														
															
																        local p = split(data, '|')         local p = split(data, '|')  
														
													
														
															
																        for i = 1, maxBalls do   
														
													
														
															
																        local die = tonumber(p[2])  
														
													
														
															
																        print(p[2])  
														
													
														
															
																        print(p[2] + 0)  
														
													
														
															
																        print(tonumber(p[11]))  
														
													
														
															
																        lastSentKeyClient, ball[i].dy, player2.y, player1.y, player1score, player2score, player1nukescore, player2nukescore, confirmation, ball[i].x, ball[i].y, gameState, ball[i].dx = p[1], die, tonumber(p[3]), tonumber(p[4]), tonumber(p[5]), tonumber(p[6]), tonumber(p[7]), tonumber(p[8]), p[9], tonumber(p[10]), tonumber(p[11]), p[12], tonumber(p[13])  
														
													
														
															
																        if p[13] then   
														
													
														
															
																            if p[13] ~= "HOST" then   
														
													
														
															
																                confirmation = "U"  
														
													
														
															
																            end  
														
													
														
															
																            if tonumber(p[14]) > 5 then   
														
													
														
															
																                confirmation = "L"  
														
													
														
															
																            end   
														
													
														
															
																            for i = 1, maxBalls do   
														
													
														
															
																            local die = tonumber(p[2])  
														
													
														
															
																            lastSentKeyClient, ball[i].dy, player2.y, player1.y, player1score, player2score, player1nukescore, player2nukescore, ball[i].x, ball[i].y, gameState, ball[i].dx = p[1], die, tonumber(p[3]), 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])  
														
													
														
															
																            end   
														
													
														
															
																        end          end   
														
													
														
															
																    else      else   
														
													
														
															
																        confirmation = "disconnected"  
														
													
														
															
																        confirmation = "D "  
														
													
														
															
																    end     end  
														
													
														
															
																    print(confirmation .. " recieved " .. lastSentKeyClient .. " AND ")     print(confirmation .. " recieved " .. lastSentKeyClient .. " AND ")  
														
													
														
															
																 
														
													
												
													
														
															
																
																	
																		 
																@@ -902,6 +945,18 @@ function dangerChecker() --CHECK IF CONTROLS ARE DUPLICATING  
														
													
														
															
																end end  
														
													
														
															
																function love.keypressed(key) function love.keypressed(key)  
														
													
														
															
																    lastSentKey = key      lastSentKey = key   
														
													
														
															
																    if gameState == "chooseIP" then   
														
													
														
															
																        if key == "backspace" then  
														
													
														
															
																            -- get the byte offset to the last UTF-8 character in the string.  
														
													
														
															
																            local byteoffset = utf8.offset(IP, -1)  
														
													
														
															
																       
														
													
														
															
																            if byteoffset then  
														
													
														
															
																                -- remove the last UTF-8 character.  
														
													
														
															
																                -- string.sub operates on bytes rather than UTF-8 characters, so we couldn't do string.sub(text, 1, -2).  
														
													
														
															
																                IP = string.sub(IP, 1, byteoffset - 1)  
														
													
														
															
																            end  
														
													
														
															
																        end  
														
													
														
															
																    end  
														
													
														
															
																    if gameState == "assign" then     if gameState == "assign" then  
														
													
														
															
																        if (req == "p1up") then         if (req == "p1up") then  
														
													
														
															
																            p1control.up = key             p1control.up = key  
														
													
												
													
														
															
																
																	
																		 
																@@ -1254,8 +1309,21 @@ end  
														
													
														
															
																 
														
													
														
															
																function love.draw() function love.draw()  
														
													
														
															
																    simpleScale.set()     simpleScale.set()  
														
													
														
															
																     
														
													
														
															
																 
														
													
														
															
																      
														
													
														
															
																        baseDraw()         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")  
														
													
														
															
																        end  
														
													
														
															
																        if (globalState == "nettest" or globalState == "clienttest") and confirmation == "U" then   
														
													
														
															
																            love.graphics.clear(50 / 255, 50 / 255, 50 / 255, 255)  
														
													
														
															
																            love.graphics.printf("LOBBY FULL OR WRONG MODE CHOSEN", 0, VIRTUAL_HEIGHT / 2, VIRTUAL_WIDTH, "center")  
														
													
														
															
																        end  
														
													
														
															
																        if (globalState == "nettest" or globalState == "clienttest") and confirmation == "L" then   
														
													
														
															
																            love.graphics.clear(50 / 255, 50 / 255, 50 / 255, 255)  
														
													
														
															
																            love.graphics.printf("POOR CONNECTION TO SERVER", 0, VIRTUAL_HEIGHT / 2, VIRTUAL_WIDTH, "center")  
														
													
														
															
																        end  
														
													
														
															
																                   
														
													
														
															
																    simpleScale.unSet()     simpleScale.unSet()  
														
													
														
															
																end end