Browse Source

Bug fixes

tags/crossplatform
madiwka3 4 years ago
parent
commit
1a3f973a87
4 changed files with 1198 additions and 1404 deletions
  1. +7
    -0
      dualdebug.sh
  2. +35
    -21
      main.lua
  3. +1100
    -1361
      main2.lua
  4. +56
    -22
      src/baseGame.lua

+ 7
- 0
dualdebug.sh View File

@@ -0,0 +1,7 @@
rm game.love
rm game.zip
zip -r game *
mv game.zip game.love
love game.love &
love game.love
rm game.love

+ 35
- 21
main.lua View File

@@ -13,6 +13,7 @@ vec4 effect(vec4 color, Image image, vec2 uvs, vec2 screen_coords) {
debug = true debug = true
--GLOBAL VARIABLES --GLOBAL VARIABLES
gameMode = "normal" gameMode = "normal"
ts = 0
globalState = "menu" globalState = "menu"
timeIsSlow = false timeIsSlow = false
timeIsSlow2 = false timeIsSlow2 = false
@@ -23,6 +24,7 @@ wall1width = 30
nuclearanimation = 3 nuclearanimation = 3
easternum = 0 easternum = 0
ball_DIR = 0 ball_DIR = 0
updaterate = 0.03
RED = 255 RED = 255
hitNum = {} hitNum = {}
hitNum[1] = 0 hitNum[1] = 0
@@ -695,9 +697,10 @@ function speedControl()
end end


function love.update(dt) function love.update(dt)
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
@@ -707,65 +710,76 @@ function love.update(dt)
if globalState == "menu" then if globalState == "menu" then
debugCheck(dt) debugCheck(dt)
end end
if globalState == "nettest" then if globalState == "nettest" then
basegame(dt) basegame(dt)
nettest(dt)
if ts > updaterate then
nettest(dt)
ts = ts - updaterate
end
end end
if globalState == "clienttest" then if globalState == "clienttest" then
if confirmation ~= "disconnected" then if confirmation ~= "disconnected" then
if confirmation == "up1" then lastSentKeyP2 = lastSentKeyClient lastSentKeyP1 = lastSentKey else
lastSentKeyP1 = lastSentKeyClient lastSentKeyP2 = lastSentKey end
lastSentKeyP1 = lastSentKeyClient
clientsBaseGame(dt) clientsBaseGame(dt)
end end
if ts > updaterate then
clienttest(dt) clienttest(dt)
ts = ts - updaterate
end
end end

end end
serverinit = false serverinit = false
clientinit = false clientinit = false
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
udp = socket.udp() udp = socket.udp()
udp:setsockname('localhost', 142)
udp:setpeername(address, port)
udp:settimeout(0) udp:settimeout(0)
serverinit = true serverinit = true
end end
data, msg_or_ip, port_or_nil = udp:receivefrom()
if data then
print(data .. "FROM " .. msg_or_ip)
for i = 1, maxBalls do
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)
end end
data = udp:receive()
if data then if data then
local p = split(data, '|') local p = split(data, '|')
lastSentKeyClient = p[1] lastSentKeyClient = p[1]
for i = 1, maxBalls do
print (tostring(ball[i].dy))
udp:sendto(tostring(lastSentKey) ..'|'.. tostring(ball[i].dy) .. '|' .. tostring(player2.y) .. '|' .. tostring(player1.y) .. '|' .. tostring(player1score) .. '|' .. tostring(player2score) .. '|' .. tostring(player1nukescore) .. '|' .. tostring(player2nukescore), msg_or_ip, port_or_nil)
print("SENT: " .. lastSentKey)
end
end 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 = '45.76.95.31', 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)) udp:send(tostring(lastSentKey))
print(lastSentKey)
print("SENT TO SERVER:" .. lastSentKey)
data = udp:receive() data = udp:receive()
print(data)
--print(data)
if data then if data then
local p = split(data, '|') local p = split(data, '|')
for i = 1, maxBalls do for i = 1, maxBalls do
local die = tonumber(p[2]) local die = tonumber(p[2])
print(p[2]) print(p[2])
print(p[2] + 0) print(p[2] + 0)
lastSentKeyClient, ball[i].dy, player2.y, player1.y, player1score, player2score, player1nukescore, player2nukescore, confirmation = p[1], die, tonumber(p[3]), tonumber(p[4]), tonumber(p[5]), tonumber(p[6]), tonumber(p[7]), tonumber(p[8]), p[9]
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])
end end
end
else
confirmation = "disconnected"
end
print(confirmation .. " recieved " .. lastSentKeyClient .. " AND ")


end end
function wallbreaker(x, y) function wallbreaker(x, y)
@@ -1299,7 +1313,7 @@ function serveBot() --THIS IS USED TO CHANGE TEXT/BALL DIRECTION ON DIFFERENT SE
if (gameMode ~= "practice") then if (gameMode ~= "practice") then
TEXT = "PLAYER 1, serve!(q)" TEXT = "PLAYER 1, serve!(q)"
end end
if ((globalState ~= "clienttest" and love.keyboard.isDown("q")) or gameMode == "practice" or (confirmation == "up1" and love.keyboard.isDown("q")) or (confirmation == "up2" and lastSentKeyP1 == "q") == "q" and globalState == "clienttest")) then
if ((globalState ~= "clienttest" and love.keyboard.isDown("q")) or (globalState == "clienttest" and lastSentKeyP1 == "q")) then
TEXT = "Lets Begin!" TEXT = "Lets Begin!"
ball_DIR = 1 ball_DIR = 1
for i = 1, maxBalls do for i = 1, maxBalls do
@@ -1321,7 +1335,7 @@ function serveBot() --THIS IS USED TO CHANGE TEXT/BALL DIRECTION ON DIFFERENT SE
gameState = "play" gameState = "play"
end end
if (((confirmation == "up1" and lastSentKeyP2 == "p") or ((globalState ~= "clienttest" or confirmation == "up2") and love.keyboard.isDown("p")))and AGAINST_AI == 0) then
if (((globalState == "nettest" and lastSentKeyClient == "p") or ((globalState ~= "nettest") and love.keyboard.isDown("p")))and AGAINST_AI == 0) then
TEXT = "Lets Begin" TEXT = "Lets Begin"
ball_DIR = -1 ball_DIR = -1
for i = 1, maxBalls do for i = 1, maxBalls do


+ 1100
- 1361
main2.lua
File diff suppressed because it is too large
View File


+ 56
- 22
src/baseGame.lua View File

@@ -28,9 +28,9 @@ function basegame(dt)
player1.dy = 0 player1.dy = 0
end end
if (AGAINST_AI == 0) then if (AGAINST_AI == 0) then
if ((confirmation == "up2" and love.keyboard.isDown(p2control.up)) or lastSentKeyP2 == p2control.up) then
if ((globalState ~= "nettest" and love.keyboard.isDown(p2control.up)) or lastSentKeyClient == p2control.up) then
player2.dy = (paddle_SPEED + p2bonus) * -1 player2.dy = (paddle_SPEED + p2bonus) * -1
elseif ((confirmation == "up2" and love.keyboard.isDown(p2control.down)) or lastSentKeyP2 == p2control.down) then
elseif ((globalState ~= "nettest" and love.keyboard.isDown(p2control.down)) or lastSentKeyClient == p2control.down) then
player2.dy = paddle_SPEED + p2bonus player2.dy = paddle_SPEED + p2bonus
else else
player2.dy = 0 player2.dy = 0
@@ -42,6 +42,7 @@ function basegame(dt)
if (areanuclear == 0 and striken == 1 and (player1score > ptw-2 or player2score > ptw-2)) then if (areanuclear == 0 and striken == 1 and (player1score > ptw-2 or player2score > ptw-2)) then
--print("Calling animation") --print("Calling animation")
print("AREA NUCLEAR?" .. areanuclear)
superanimator("tensehit", 1) superanimator("tensehit", 1)
end end
if gameMode == "practice" then if gameMode == "practice" then
@@ -73,7 +74,10 @@ function basegame(dt)
sounds["nuclearhit"]:setPitch(1) sounds["nuclearhit"]:setPitch(1)
sounds["nuclearhit"]:play() sounds["nuclearhit"]:play()
end end
print("AREA NUCLEAR?" .. areanuclear)
if areanuclear == 0 then
superanimator("tensehit", 1) superanimator("tensehit", 1)
end
else else
if areanuclear == 0 then if areanuclear == 0 then
sounds["beep"]:setPitch(ballSpeed / 250) sounds["beep"]:setPitch(ballSpeed / 250)
@@ -167,6 +171,7 @@ function basegame(dt)
(areanuclear == 0 and (areanuclear == 0 and
(striken == 1 and (player1score > ptw-2 or player2score > ptw-2))) (striken == 1 and (player1score > ptw-2 or player2score > ptw-2)))
then then
print("AREA NUCLEAR?" .. areanuclear)
superanimator("tensehit", 2) superanimator("tensehit", 2)
end end
if (ballSpeed > 200) then if (ballSpeed > 200) then
@@ -186,7 +191,10 @@ function basegame(dt)
potentialnuke2 = 0 potentialnuke2 = 0
player2nukescore = 0 player2nukescore = 0
potentialstrike2 = 0 potentialstrike2 = 0
print("AREA NUCLEAR?" .. areanuclear)
if areanuclear == 0 then
superanimator("tensehit", 2) superanimator("tensehit", 2)
end
if areanuclear == 0 then if areanuclear == 0 then
sounds["striking"]:setPitch(ballSpeed / 250) sounds["striking"]:setPitch(ballSpeed / 250)
sounds["striking"]:play() sounds["striking"]:play()
@@ -230,7 +238,7 @@ function basegame(dt)
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 ((confirmation == "up2" and love.keyboard.isDown(p2control.up) ) or AI_SPEED < 0 or lastSentKeyP2 == p2control.up) then
if ((globalState ~= "nettest" and love.keyboard.isDown(p2control.up) ) or AI_SPEED < 0 or lastSentKeyClient == p2control.up) then
select = math.random(1, 5) select = math.random(1, 5)
if select == 1 then if select == 1 then
ball[i].dy = -1 ball[i].dy = -1
@@ -243,7 +251,7 @@ function basegame(dt)
elseif select == 5 then elseif select == 5 then
ball[i].dy = -2 ball[i].dy = -2
end end
elseif (confirmation == "up2" and love.keyboard.isDown(p2control.down)) or AI_SPEED > 0 or lastSentKeyP2 == p2control.down then
elseif (globalState ~= "nettest" and love.keyboard.isDown(p2control.down)) or AI_SPEED > 0 or lastSentKeyClient == p2control.down then
select = math.random(1, 5) select = math.random(1, 5)
if select == 1 then if select == 1 then
ball[i].dy = 1 ball[i].dy = 1
@@ -448,20 +456,20 @@ end
function powerAvailability() function powerAvailability()
if (player1nukescore >= 20 and player1nukescore < 140) then if (player1nukescore >= 20 and player1nukescore < 140) then
potentialstrike1 = 1 potentialstrike1 = 1
if ((confirmation == "up1" and love.keyboard.isDown(p1control.super)) or (confirmation == "up2" and lastSentKeyP1 == p1control.super)) then
if (((globalState ~= "clienttest" and love.keyboard.isDown(p1control.super)) or (confirmation == "confirmed" and lastSentKeyP1 == p1control.super)) ) then
player1striken = 1 player1striken = 1
player1reverbav = 0 player1reverbav = 0
end end
end end
if (player1nukescore >= 140) and timeIsSlow2 == false and timeIsSlow == false and maxBalls == 1 and ball[1].x < VIRTUAL_WIDTH / 2 and ball[1].dx < 0 then
if (player1nukescore >= 140) and timeIsSlow2 == false and timeIsSlow == false then
player1reverbav = 1 player1reverbav = 1
if ((confirmation == "up1" and love.keyboard.isDown(p1control.counter)) or (confirmation == "up2" and lastSentKeyP1 == p1control.counter)) then
if ((confirmation == "confirmed" and lastSentKeyP1 == p1control.counter) or (globalState ~= "clienttest" and love.keyboard.isDown(p1control.counter))) then
powerControl(1, "special") powerControl(1, "special")
end end
end end
if (player1nukescore >= 200) then if (player1nukescore >= 200) then
potentialnuke1 = 1 potentialnuke1 = 1
if ((confirmation == "up1" and love.keyboard.isDown(p1control.super)) or (confirmation == "up2" and lastSentKeyP1 == p1control.super)) then
if ((confirmation == "confirmed" and lastSentKeyP1 == p1control.super)or (globalState ~= "clienttest" and love.keyboard.isDown(p1control.super))) then
sounds["nuke"]:play() sounds["nuke"]:play()
if areanuclear == 1 then if areanuclear == 1 then
maxspeed = maxspeed + 50 maxspeed = maxspeed + 50
@@ -490,15 +498,15 @@ function powerAvailability()
if (player2nukescore >= 20 and player2nukescore <= 140) then if (player2nukescore >= 20 and player2nukescore <= 140) then
potentialstrike2 = 1 potentialstrike2 = 1
if (AGAINST_AI == 0) then if (AGAINST_AI == 0) then
if ((confirmation == "up2" and love.keyboard.isDown(p2control.super)) or lastSentKeyP2 == p2control.super) then
if ((globalState ~= "nettest" and love.keyboard.isDown(p2control.super)) or lastSentKeyClient == p2control.super ) then
player2striken = 1 player2striken = 1
player2reverbav = 0 player2reverbav = 0
end end
end end
end end
if (player2nukescore >= 140) and timeIsSlow == false and timeIsSlow2 == false and maxBalls == 1 and ball[1].x > VIRTUAL_WIDTH / 2 and ball[1].dx > 0 then
if (player2nukescore >= 140) and timeIsSlow == false and timeIsSlow2 == false then
player2reverbav = 1 player2reverbav = 1
if (confirmation == "up2" and love.keyboard.isDown(p2control.counter)) or lastSentKeyP2 == p2control.counter then
if (globalState ~= "nettest" and love.keyboard.isDown(p2control.counter)) or lastSentKeyClient == p2control.counter then
sounds["time"]:play() sounds["time"]:play()
player2reverbav = false player2reverbav = false
timeIsSlow2 = true timeIsSlow2 = true
@@ -511,7 +519,7 @@ function powerAvailability()
end end
if (player2nukescore >= 200) then if (player2nukescore >= 200) then
potentialnuke2 = 1 potentialnuke2 = 1
if (((confirmation == "up2" and love.keyboard.isDown(p2control.super)) or lastSentKeyP2 == p2control.super) and AGAINST_AI == 0) then
if (((globalState ~= "nettest" and love.keyboard.isDown(p2control.super)) or lastSentKeyClient == p2control.super)) and AGAINST_AI == 0 then
sounds["nuke"]:play() sounds["nuke"]:play()
if areanuclear == 1 then if areanuclear == 1 then
maxspeed = maxspeed + 50 maxspeed = maxspeed + 50
@@ -557,7 +565,9 @@ end


function nuclearDraw() function nuclearDraw()
love.graphics.setColor(1, 1, 1, 1) love.graphics.setColor(1, 1, 1, 1)
love.graphics.circle("fill", ball[1].x, ball[1].y, explosionRange * 100, 100)
for i = 1, maxBalls do
love.graphics.circle("fill", ball[i].x, ball[i].y, explosionRange * 100, 100)
end
player1.RED, player1.GREEN, player1.BLUE, player2.RED, player2.GREEN, player2.BLUE = player1.RED, player1.GREEN, player1.BLUE, player2.RED, player2.GREEN, player2.BLUE =
nuclearanimation / 3, nuclearanimation / 3,
nuclearanimation / 3, nuclearanimation / 3,
@@ -770,7 +780,7 @@ function displayPoints()
else else
love.graphics.print(tostring("READY"), VIRTUAL_WIDTH / 2 - 500, VIRTUAL_HEIGHT / 60) love.graphics.print(tostring("READY"), VIRTUAL_WIDTH / 2 - 500, VIRTUAL_HEIGHT / 60)
end end
elseif (player1reverbav == 1 and potentialnuke1 == 0 and maxBalls == 1) then
elseif (player1reverbav == 1 and potentialnuke1 == 0 ) then
love.graphics.print( love.graphics.print(
tostring( tostring(
math.floor(player1nukescore) .. "[" .. p1control.super .. "]" .. " [" .. p1control.counter .. "]" math.floor(player1nukescore) .. "[" .. p1control.super .. "]" .. " [" .. p1control.counter .. "]"
@@ -778,7 +788,7 @@ function displayPoints()
VIRTUAL_WIDTH / 2 - 500, VIRTUAL_WIDTH / 2 - 500,
VIRTUAL_HEIGHT / 60 VIRTUAL_HEIGHT / 60
) )
elseif (potentialnuke1 == 1 and maxBalls == 1) then
elseif (potentialnuke1 == 1) then
love.graphics.setColor(255, 0, 0, 255) love.graphics.setColor(255, 0, 0, 255)
love.graphics.print( love.graphics.print(
tostring( tostring(
@@ -811,7 +821,7 @@ function displayPoints()
else else
love.graphics.print(tostring("READY"), VIRTUAL_WIDTH / 2 + 430, VIRTUAL_HEIGHT / 60) love.graphics.print(tostring("READY"), VIRTUAL_WIDTH / 2 + 430, VIRTUAL_HEIGHT / 60)
end end
elseif (potentialnuke2 == 1 and maxBalls == 1) then
elseif (potentialnuke2 == 1) then
love.graphics.setColor(255, 0, 0, 255) love.graphics.setColor(255, 0, 0, 255)
love.graphics.print( love.graphics.print(
tostring(math.floor(player2nukescore) .. "[" .. p2control.super .. "] [" .. p2control.counter .. "]"), tostring(math.floor(player2nukescore) .. "[" .. p2control.super .. "] [" .. p2control.counter .. "]"),
@@ -827,7 +837,7 @@ function displayPoints()
VIRTUAL_HEIGHT / 60 VIRTUAL_HEIGHT / 60
) )
love.graphics.setColor(255, 255, 255, 255) love.graphics.setColor(255, 255, 255, 255)
elseif (player2reverbav == 1 and potentialnuke2 == 0 and maxBalls == 1) then
elseif (player2reverbav == 1 and potentialnuke2 == 0 ) then
love.graphics.print( love.graphics.print(
tostring(math.floor(player2nukescore) .. "[" .. p2control.super .. "] [" .. p2control.counter .. "]"), tostring(math.floor(player2nukescore) .. "[" .. p2control.super .. "] [" .. p2control.counter .. "]"),
VIRTUAL_WIDTH / 2 + 400, VIRTUAL_WIDTH / 2 + 400,
@@ -949,7 +959,13 @@ function rules(query, i)
end end
end end
end end
function clientsBaseGame(dt)
function clientsBaseGame(dt)
if confirmation == "confirmed" then
player2.RED = 0
print("KEYS ARE: " .. confirmation .. " " .. lastSentKeyP1)
else
TEXT = "DISCONNECTED"
end
if gameMode == "reverse" then if gameMode == "reverse" then
reversegame(dt) reversegame(dt)
end end
@@ -965,12 +981,23 @@ function clientsBaseGame(dt)
if t < shakeDuration then if t < shakeDuration then
t = t + dt t = t + dt
end end
if (lastSentKeyClient == p1control.up) then
player1.dy = (paddle_SPEED + p1bonus) * -1
elseif (lastSentKeyClient == p1control.down) then
player1.dy = paddle_SPEED + p1bonus
if (lastSentKeyP1 == p1control.up) then
player1.dy = (paddle_SPEED + p2bonus) * -1
print("moving player1 up")
elseif (lastSentKeyP1 == p1control.down) then
player1.dy = paddle_SPEED + p2bonus
print("moving player1 down")
else else
player1.dy = 0 player1.dy = 0
print("stopping player")
end
if ((love.keyboard.isDown(p2control.up))) then
player2.dy = (paddle_SPEED + p2bonus) * -1
elseif ((love.keyboard.isDown(p2control.down))) then
player2.dy = paddle_SPEED + p2bonus
else
player2.dy = 0
end end
--print("T = " .. tostring(t)) --print("T = " .. tostring(t))
serveBot() serveBot()
@@ -985,6 +1012,7 @@ function clientsBaseGame(dt)
if (areanuclear == 0 and striken == 1 and (player1score > ptw-2 or player2score > ptw-2)) then if (areanuclear == 0 and striken == 1 and (player1score > ptw-2 or player2score > ptw-2)) then
--print("Calling animation") --print("Calling animation")
superanimator("tensehit", 1) superanimator("tensehit", 1)
print("AREA NUCLEAR?" .. areanuclear)
end end
if gameMode == "practice" then if gameMode == "practice" then
player1score = player1score + 1 player1score = player1score + 1
@@ -1015,7 +1043,9 @@ function clientsBaseGame(dt)
sounds["nuclearhit"]:setPitch(1) sounds["nuclearhit"]:setPitch(1)
sounds["nuclearhit"]:play() sounds["nuclearhit"]:play()
end end
if areanuclear == 0 then
superanimator("tensehit", 1) superanimator("tensehit", 1)
end
else else
if areanuclear == 0 then if areanuclear == 0 then
sounds["beep"]:setPitch(ballSpeed / 250) sounds["beep"]:setPitch(ballSpeed / 250)
@@ -1053,6 +1083,7 @@ function clientsBaseGame(dt)
(areanuclear == 0 and (areanuclear == 0 and
(striken == 1 and (player1score > ptw-2 or player2score > ptw-2))) (striken == 1 and (player1score > ptw-2 or player2score > ptw-2)))
then then
print("AREA NUCLEAR?" .. areanuclear)
superanimator("tensehit", 2) superanimator("tensehit", 2)
end end
if (ballSpeed > 200) then if (ballSpeed > 200) then
@@ -1072,7 +1103,10 @@ function clientsBaseGame(dt)
potentialnuke2 = 0 potentialnuke2 = 0
player2nukescore = 0 player2nukescore = 0
potentialstrike2 = 0 potentialstrike2 = 0
print("AREA NUCLEAR?" .. areanuclear)
if areanuclear == 0 then
superanimator("tensehit", 2) superanimator("tensehit", 2)
end
if areanuclear == 0 then if areanuclear == 0 then
sounds["striking"]:setPitch(ballSpeed / 250) sounds["striking"]:setPitch(ballSpeed / 250)
sounds["striking"]:play() sounds["striking"]:play()


Loading…
Cancel
Save