|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920 |
- --CALLING OTHER LUA FILES
- require "src/dependencies"
- io.stdout:setvbuf("no")
- --CANCELLED ATTEMPETED SHADING (NOT WORKING)
- local shader_code =
- [[
- vec4 effect(vec4 color, Image image, vec2 uvs, vec2 screen_coords) {
- vec4 pixel = Texel(image,uvs);
- return pixel * color;
- }
- ]]
-
- debug = true
- --GLOBAL VARIABLES
- frameratecap = 1/60
- realtimer = 0
- status = "offline"
- gameMode = "normal"
- ts = 0
- globalState = "menu"
- timeIsSlow = false
- timeIsSlow2 = false
- originalSpeed = 200
- explosionRange = 0
- blockinput = false
- wall1width = 30
- nuclearanimation = 3
- easternum = 0
- ball_DIR = 0
- updaterate = 0.015
- RED = 255
- hitNum = {}
- hitNum[1] = 0
- hitNum[2] = 0
- hitNum[3] = 0
- confirmation = "N"
- hitNum[4] = 0
- p1bonus = 0
- p2bonus = 0
- hitNum[5] = 0
- hitNum[6] = 0
- GREEN = 255
- IP = '45.76.95.31'
- BLUE = 255
- updateTEXT = "Chalkboard Update"
- maxBalls = 1
- playerCount = 1
- player1reverbav = 0
- playertext = "1v1"
- player2reverbav = 0
- elapsed = 0
- rotation = 0
- TEXT = "Nuclear Pong"
- currentKey = " "
- ptw = 10
- checkrate = 0.5
- --CHECKING IF CONTROLS ARE TAKEN
- danger = "none"
- danger2 = "none"
-
- nuckemodactive = 0
- maxspeed = 700
- DIFFERENCE_X = 1
- DIFFERENCE_Y = 1
- paddle_SPEED = 200
- textamount = 15
- AI_STRIKEMOD = 1000
- resolutionWin = 0
- AGAINST_AI = 0
- RESOLUTION_SET = 0
- AI_NUKEMOD = 1000
- animstart = true
- AI_SPEED = 300
- craz = 0
- AI_LEVEL = 500
- isFullscreen = 0
- prtext = "Easy"
- lastSentKey = "c"
- MAP_TYPE = 0
- lastSentKeyClient = "c"
- difficultyl = 300
- req = "pp"
- ballSet = 200
- p1control = {up = "a", down = "z", super = "s", counter = "x"}
- p2control = {up = ";", down = ".", super = "l", counter = ","}
- synctext = "Independent"
- synctype = 0
- function newButton(text, fn)
- return {
- text = text,
- fn = fn,
- now = false,
- last = false
- }
- end
- function love.keyboard.mouseWasReleased()
- return love.keyboard.mouseisReleased
- end
- function autoSave(dt)
- autoTimer = autoTimer + dt
- end
-
- function balancer()
- if (player2score == 9 or player1score == 9) then
- shakeDuration = 5
- if debug then
- --print("Shaking set to match almost over")
- end
- end
- if (player1score < player2score) then
- p1bonus = (player2score - player1score) * 5
- else
- p1bonus = 0
- end
- if (player2score < player1score) then
- p2bonus = (player1score - player2score) * 5
- else
- p2bonus = 0
- end
- end
-
- function newWall(wallx, wally, wallwidth, wallheight)
- return {
- wallx = wallx,
- wally = wally,
- walwidth = wallwidth,
- wallheight = wallheight
- }
- end
- speedParameters = {}
- buttons = {}
- IPselect = {}
- difbuttons = {}
- settings = {}
- walls = {}
- editorpicks = {}
- controlSettings = {}
- modeSelectorButtons = {}
- pracdiff = {}
- playerCountButtons = {}
- function controlChanger()
- if (gameState == "assign") then
- love.graphics.clear(50 / 255, 50 / 255, 50 / 255, 255)
- love.graphics.printf("SELECT BUTTON", 0, VIRTUAL_HEIGHT / 2, VIRTUAL_WIDTH, "center")
- end
- end
- function love.load()
- love.keyboard.setKeyRepeat(true)
- simpleScale.setWindow(VIRTUAL_WIDTH, VIRTUAL_HEIGHT, WINDOW_WIDTH, WINDOW_HEIGHT)
- configfile = io.open("config.lua", "r")
- configsave = io.open("config.lua", "w")
- shader = love.graphics.newShader(shader_code)
- time_1 = 0
- --print("Debug active")
- --load
-
- testwalls = love.filesystem.load("save.lua")()
- if testwalls ~= nil then
- walls = love.filesystem.load("save.lua")()
- end
-
- light = 0
- image = love.graphics.newImage("Madi.png")
- table.insert(
- editorpicks,
- newButton(
- "C",
- function()
- for k in pairs(walls) do
- walls[k] = nil
- end
- end
- )
- )
- table.insert(
- editorpicks,
- newButton(
- "S",
- function()
- love.filesystem.write("save.lua", serialize(walls))
- end
- )
- )
- table.insert(
- editorpicks,
- newButton(
- "L",
- function()
- walls = love.filesystem.load("save.lua")()
- end
- )
- )
- table.insert(
- buttons,
- newButton(
- "Singleplayer",
- function()
- gameState = "gameMode"
- end
- )
- )
- table.insert(
- buttons,
- newButton(
- "Online",
- function()
- MAP_TYPE = 0
- gameState = "chooseIP"
- end
- )
- )
- table.insert(
- IPselect,
- newButton(
- "Host",
- function()
- globalState = "nettest"
- AGAINST_AI = 0
- gameState = "1serve"
- ball[1]:reset(1, 1)
- end
- )
- )
- table.insert(
- IPselect,
- newButton(
- "Guest",
- function()
- globalState = "clienttest"
- AGAINST_AI = 0
- gameState = "1serve"
- ball[1]:reset(1, 1)
- end
- )
- )
- table.insert(
- buttons,
- newButton(
- "Multiplayer",
- function()
- gameState = "multiMode"
- end
- )
- )
- table.insert(
- buttons,
- newButton(
- "Settings",
- function()
- AGAINST_AI = 0
- gameState = "windowsettings"
- end
- )
- )
- table.insert(
- buttons,
- newButton(
- "Exit",
- function()
- love.event.quit(0)
- end
- )
- )
- table.insert(
- difbuttons,
- newButton(
- "Easy",
- function()
- hardmanager("easy")
- end
- )
- )
- table.insert(
- difbuttons,
- newButton(
- "Normal",
- function()
- hardmanager("normal")
- end
- )
- )
- table.insert(
- difbuttons,
- newButton(
- "Hard",
- function()
- hardmanager("hard")
- end
- )
- )
- table.insert(
- difbuttons,
- newButton(
- "Smart",
- function()
- hardmanager("smart")
- end
- )
- )
- --table.insert(
- -- settings,
- -- newButton(
- -- "Change Map",
- -- function()
- -- MAP_TYPE = MAP_TYPE + 1
- -- end
- -- )
- --)
- table.insert(
- settings,
- newButton(
- "Toggle Fullscreen",
- function()
- myscreen:toggle(VIRTUAL_HEIGHT, VIRTUAL_WIDTH)
- DIFFERENCE_X = myscreen.c
- DIFFERENCE_Y = myscreen.d
- end
- )
- )
- table.insert(
- settings,
- newButton(
- "Editor",
- function()
- gameState = "editor"
- end
- )
- )
- table.insert(
- settings,
- newButton(
- "Speed Settings",
- function()
- gameState = "speedSettings"
- end
- )
- )
- table.insert(
- settings,
- newButton(
- "Control Settings",
- function()
- gameState = "controlSettings"
- end
- )
- )
- table.insert(
- settings,
- newButton(
- "Back to Menu",
- function()
- gameState = "menu"
- end
- )
- )
- table.insert(
- speedParameters,
- newButton(
- "Back to Menu",
- function()
- gameState = "windowsettings"
- end
- )
- )
- --table.insert(speedParameters, newButton("Ball Speed: ", function() speedSetter('ball') end))
- table.insert(
- playerCountButtons,
- newButton(
- "Ball Speed: ",
- function()
- speedSetter("ball")
- end
- )
- )
- --table.insert(speedParameters, newButton("snc", function() speedSetter('snc') end))
- table.insert(
- playerCountButtons,
- newButton(
- "snc",
- function()
- speedSetter("snc")
- end
- )
- )
- table.insert(
- speedParameters,
- newButton(
- "NUCLEAR MODE",
- function()
- speedSetter("nuclearmod")
- end
- )
- )
- table.insert(
- controlSettings,
- newButton(
- "1up",
- function()
- gameState = "assign"
- req = "p1up"
- end
- )
- )
- table.insert(
- controlSettings,
- newButton(
- "1down",
- function()
- gameState = "assign"
- req = "p1down"
- end
- )
- )
- table.insert(
- controlSettings,
- newButton(
- "1special",
- function()
- gameState = "assign"
- req = "p1super"
- end
- )
- )
- table.insert(
- controlSettings,
- newButton(
- "1ct",
- function()
- gameState = "assign"
- req = "p1ct"
- end
- )
- )
- table.insert(
- controlSettings,
- newButton(
- "2up",
- function()
- gameState = "assign"
- req = "p2up"
- end
- )
- )
- table.insert(
- controlSettings,
- newButton(
- "2down",
- function()
- gameState = "assign"
- req = "p2down"
- end
- )
- )
- table.insert(
- controlSettings,
- newButton(
- "2special",
- function()
- gameState = "assign"
- req = "p2super"
- end
- )
- )
- table.insert(
- controlSettings,
- newButton(
- "2ct",
- function()
- gameState = "assign"
- req = "p2ct"
- end
- )
- )
- table.insert(
- controlSettings,
- newButton(
- "Default",
- function()
- p1control = {up = "a", down = "z", super = "s", counter = "x"}
- p2control = {up = ";", down = ".", super = "l", counter = ","}
- end
- )
- )
- table.insert(
- controlSettings,
- newButton(
- "Return",
- function()
- gameState = "windowsettings"
- end
- )
- )
- table.insert(
- modeSelectorButtons,
- newButton(
- "Nuclear Pong",
- function()
- gameState = "difficulty"
- end
- )
- )
- table.insert(
- modeSelectorButtons,
- newButton(
- "Main Menu",
- function()
- gameState = "menu"
- end
- )
- )
- table.insert(
- pracdiff,
- newButton(
- "Silverblade",
- function()
- speedSetter("practice")
- end
- )
- )
- table.insert(
- pracdiff,
- newButton(
- "Return",
- function()
- speedSetter("reset")
- gameState = "gameMode"
- end
- )
- )
- table.insert(
- pracdiff,
- newButton(
- "Go!",
- function()
- gameMode = "practice"
- hardmanager("practice")
- end
- )
- )
- --table.insert(playerCountButtons, newButton("1v1", function() speedSetter('pc') end))
- table.insert(
- playerCountButtons,
- newButton(
- "ballCount",
- function()
- speedSetter("ballz")
- end
- )
- )
- table.insert(
- difbuttons,
- newButton(
- "ballCount",
- function()
- speedSetter("ballz")
- end
- )
- )
- table.insert(
- playerCountButtons,
- newButton(
- "Return",
- function()
- speedSetter("reset")
- gameState = "menu"
-
- end
- )
- )
- table.insert(
- playerCountButtons,
- newButton(
- "ptw",
- function()
- speedSetter("ptw")
- end
- )
- )
- table.insert(
- playerCountButtons,
- newButton(
- "Play",
- function()
- AGAINST_AI = 0
- gameState = "1serve"
- globalState = "base"
- end
- )
- )
- table.insert(
- playerCountButtons,
- newButton(
- "Reverse Play",
- function()
- gameState = "1serve"
- gameMode = "reversegame"
- globalState = "base"
- end
- )
- )
-
- --table.insert(speedParameters, newButton("Ball Speed: ", function() speedSetter() end))
-
- love.window.setTitle("NUCLEAR PONG")
- textphrases = {
- "Amazing",
- "Superb",
- "Absolutely beautiful!",
- "Awesome",
- "Look at That!",
- "Great",
- "Nice",
- "Boom!",
- "Dangerous!",
- "Astonishing!",
- "u/ebernerd saved me",
- "Absolutely Wonderful!",
- "Exsquisite",
- "Delicate",
- "Pow!",
- "Great Hit",
- "all hail nazarbayev"
- }
- sounds = {
- ["updateMusic"] = love.audio.newSource("audio/theme1.mp3", "static"),
- ["gayTheme"] = love.audio.newSource("audio/theme2.mp3", "static"),
- ["gayTheme2"] = love.audio.newSource("audio/theme3.mp3", "static"),
- ["gayTheme3"] = love.audio.newSource("audio/theme4.mp3", "static"),
- ["beep"] = love.audio.newSource("audio/hit1.mp3", "static"),
- ["wallhit"] = love.audio.newSource("audio/hit2.wav", "static"),
- ["win"] = love.audio.newSource("win.wav", "static"),
- ["score"] = love.audio.newSource("audio/score.wav", "static"),
- ["nuke"] = love.audio.newSource("audio/bomb.wav", "static"),
- ["striking"] = love.audio.newSource("audio/superhit.wav", "static"),
- ["nuclearhit"] = love.audio.newSource("audio/hit1.mp3", "static"),
- ["time"] = love.audio.newSource("audio/time.wav", "static")
- }
- love.graphics.setDefaultFilter("nearest", "nearest")
- --comic sans lmao
- math.randomseed(os.time())
- smallfont = love.graphics.newFont("font.ttf", 25)
- scorefont = love.graphics.newFont("font.ttf", 60)
- love.graphics.setFont(smallfont)
-
- --push:setupScreen(VIRTUAL_WIDTH, VIRTUAL_HEIGHT, WINDOW_WIDTH, WINDOW_HEIGHT, {
- -- fullscreen = isFullscreen,
- -- resizable = true,
- -- vsync = true,
- --})
- player1score = 0
- player2score = 0
- areanuclear = 0
- player1nukescore = 0
- player2nukescore = 0
- striken = 0
- soundtype = 1
- soundturn = 1
- potentialstrike1 = 0
- potentialstrike2 = 0
- potentialnuke1 = 0
- potentialnuke2 = 0
- player1striken = 0
- player2striken = 0
- randomtext = 0
- selecting = 0
- number = 0
- elec = 1
- INDIC = {
- "",
- "",
- "",
- ""
- }
- --playe1nuke
- player1 = paddle(0, 30, 10, 100, 1)
- player2 = paddle(VIRTUAL_WIDTH * 0.99, VIRTUAL_HEIGHT * 0.88, 10, 100, 2)
- player3 = paddle(5000, 5000, 10, 100)
- player4 = paddle(5000, 5000, 10, 100)
- ball = {}
- ball[1] = eball(VIRTUAL_WIDTH / 2, VIRTUAL_HEIGHT / 2 - 2, 16, 16)
- ball[2] = eball(VIRTUAL_WIDTH / 1.9, VIRTUAL_HEIGHT / 2 - 2, 16, 16)
- ball[3] = eball(VIRTUAL_WIDTH / 1.8, VIRTUAL_HEIGHT / 2 - 2, 16, 16)
- ball[4] = eball(VIRTUAL_WIDTH / 2.2, VIRTUAL_HEIGHT / 2 - 2, 16, 16)
- ball[5] = eball(VIRTUAL_WIDTH / 2.1, VIRTUAL_HEIGHT / 2 - 2, 16, 16)
- myscreen = fullScreener(RESOLUTION_SET, isFullscreen, DIFFERENCE_X, DIFFERENCE_Y)
- mymenu = mainMenu()
-
- ballSpeed = 200
-
- ballDX = math.random(2) == 1 and 100 or -100
- ballDY = math.random(-50, 50)
-
- gameState = "animation"
- end
- t = 0
- shakeDuration = 0
- shakeMagnitude = 1
- function startShake(duration, magnitude)
- t, shakeDuration, shakeMagnitude = 0, duration or 1, magnitude or 5
- end
- function displayFPS()
- --love.window.setTitle(love.timer.getFPS())
- love.window.setTitle(globalState .. " " .. gameState .. " " .. paddle_SPEED .. " " .. p1bonus .. " " .. player1.dy)
- if love.keyboard.isDown("space") then
- player1nukescore = 200
- player1score = player1score + 0.2
- player2nukescore = 200
- end
-
- end
-
- function speedControl()
- if (ballSpeed > maxspeed and gameState == "play") then
- ballSpeed = maxspeed
- end
- end
-
- function love.update(dt)
- --print("IMPORTANT!!!!!" .. globalState .. gameState)
-
- staticanimatorcounter(dt)
- if gameState == "chooseIP" then
- checkCurrentServer(dt)
- end
- musicController('norm', 1)
-
- if debug then
- displayFPS()
- end
- if globalState == "base" then
- basegame(dt)
- end
- if globalState == "menu" then
- debugCheck(dt)
- end
-
- if globalState == "nettest" then
- --print("Confcode: " .. confirmation)
- if confirmation == "N" then
- basegame(dt)
- end
- nettest(dt)
-
- end
- if globalState == "selfhost" then
- --print("Confcode: " .. confirmation)
- if confirmation == "N" then
- globalState = "nettest"
- basegame(dt)
- end
- globalState = "selfhost"
- selfHost(dt)
-
- end
- if globalState == "clienttest" then
- ts = ts + dt
- if confirmation == "N" then
- lastSentKeyP1 = lastSentKeyClient
- clientsBaseGame(dt)
- end
- clienttest(dt)
- end
-
-
- end
- serverinit = false
- dserverinit = false
- datawaspassedtimer = 0
- clientinit = false
- function love.textinput(t)
- if gameState == "chooseIP" then
- IP = IP .. t
- end
- end
- function nettest(dt)
- if serverinit == false then
- local socket = require "socket"
- local address, port = IP, 12345
- print(address)
- udp = socket.udp()
- udp:setpeername(address, port)
- udp:settimeout(0)
- serverinit = true
- end
- for i = 1, maxBalls do
- ts = ts + dt
- if ts > updaterate then
- udp:send(tostring(lastSentKey) ..
- '|' .. tostring(ball[1].dy) ..
- '|' .. tostring(player2.y) ..
- '|' .. tostring(player1.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) ..
- "|HOST")
- ts = 0
- end
- end
-
- local data
- local datanumtest = 0
- local datawaspassed = false
- repeat
- datanumtest = datanumtest + 1
- print("LATENCY: " .. tostring(datanumtest))
- data = udp:receive()
- if data then
- datawaspassed = true
- print("ReceivedINFO: " .. data)
- confirmation = "N"
- local p = split(data, '|')
- if p[15] then
- if tonumber(p[16]) > 90 then
- confirmation = "L"
- end
- if p[15] ~= "CLIENT" then
- confirmation = "U"
- end
- elseif p[1] == "RESPONSE" then
- if p[2] == "1" then
-
- elseif p[2] == "2" then
-
- elseif p[2] == "3" then
- end
- else
- confirmation = "U"
- end
-
-
- if ball[1].disabled and ball[1].x > 20 and ball[1].x < VIRTUAL_WIDTH - 20 then
- ball[1].disabled = false
- print("illegal disabling")
- end
- if (ball[1].x > VIRTUAL_WIDTH/2) then
- if tonumber(p[9]) > VIRTUAL_WIDTH/2 then
- die = tonumber(p[2])
- lastSentKeyClient,
- ball[1].dy,
- player2.y,
- player1score,
- player2score,
- player1nukescore,
- player2nukescore,
- ball[1].x,
- ball[1].y,
- gameState,
- ball[1].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])
- print("ACCEPTED")
- else
- print("DECLINED")
- end
- else
- if tonumber(p[9]) > VIRTUAL_WIDTH/2 then
- die = tonumber(p[2])
- lastSentKeyClient,
- ball[1].dy,
- player2.y,
- player1score,
- player2score,
- player1nukescore,
- player2nukescore,
- ball[1].x,
- ball[1].y,
- gameState,
- ball[1].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])
- print("ACCEPTED")
- else
- print("ENFORCED" .. ball[1].x .. " " .. ball[1].dx)
- lastSentKeyClient = p[1]
- player2.y = tonumber(p[4])
- end
- end
-
- end
- until not data
- if not datawaspassed then
- datawaspassedtimer = datawaspassedtimer + 1
- if datawaspassedtimer > 5 then
- confirmation = "D"
- datawaspassedtimer = 0
- end
- else
- datawaspassedtimer = 0
- end
- end
- function clienttest(dt)
- if clientinit == false then
- local socket = require "socket"
- local address, port = IP, 12345
-
- udp = socket.udp()
- udp:setpeername(address, port)
- udp:settimeout(0)
- clientinit = true
- end
- ts = ts + dt
- if ts > updaterate 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")
- ts = 0
- end
- local data
- local datanumtest = 0
- local datawaspassed = false
- repeat
- datanumtest = datanumtest + 1
- print("LATENCY: " .. tostring(datanumtest))
- data = udp:receive()
-
- if data then
- print("RECEIVED DATA: " .. data)
- datawaspassed = true
- print("SENT TO SERVER:" .. lastSentKey)
- confirmation = "N"
- local p = split(data, '|')
- if p[15] then
- if p[15] ~= "HOST" then
- confirmation = "U"
- end
- if tonumber(p[16]) > 90 then
- confirmation = "L"
- end
- for i = 1, maxBalls do
- local die = tonumber(p[2])
- if (ball[i].x <= VIRTUAL_WIDTH/2) then
- if tonumber(p[9]) <= VIRTUAL_WIDTH/2 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])
- print("ACCEPTED")
- else
- print("DECLINED")
- end
- else
- if tonumber(p[9]) <= VIRTUAL_WIDTH/2 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])
- print("REROUTED")
- else lastSentKeyClient = p[1]
- player1.y = tonumber(p[4])
- print("ENFORCED")
- end
- end
- end
- else
- confirmation = "U"
- end
- end
- print("GOT: " .. lastSentKeyClient)
- until not data
- if not datawaspassed then
- datawaspassedtimer = datawaspassedtimer + 1
- if datawaspassedtimer > 5 then
- confirmation = "D"
- datawaspassedtimer = 0
- end
- else
- datawaspassedtimer = 0
- end
- end
- function wallbreaker(x, y)
- if (gameState == "editor") then
- for i, wall in ipairs(walls) do
- if math.abs(wall.wallx - x) < 10 and math.abs(wall.wally - y) < 10 then
- table.remove(walls, i)
- end
- end
- end
- end
-
- function hardmanager(diff)
- selecting = 1
- if (diff == "easy") then
- INDIC[1] = ">"
- AGAINST_AI = 1
- AI_SPEED = ballSet
- AI_STRIKEMOD = 100
- AI_NUKEMOD = 1000
- AI_LEVEL = 350
- difficultyl = 200
- selecting = 0
- gameState = "1serve"
- globalState = "base"
- end
- if (diff == "normal") then
- INDIC[2] = ">"
- AI_SPEED = ballSet
- AI_LEVEL = 500
- AI_NUKEMOD = 250
- AI_STRIKEMOD = 60
- AGAINST_AI = 1
- difficultyl = 300
- selecting = 0
- gameState = "1serve"
- globalState = "base"
- end
- if (diff == "hard") then
- INDIC[3] = ">"
- AI_SPEED = ballSpeed * 1.1 + 50
- AI_LEVEL = 700
- AI_NUKEMOD = 200
- AI_STRIKEMOD = 20
- selecting = 0
- difficultyl = 350
- AGAINST_AI = 1
- gameState = "1serve"
- globalState = "base"
- end
- if (diff == "smart") then
- INDIC[3] = ">"
- AI_SPEED = ballSpeed * 1.1 + 50
- AI_LEVEL = 1500
- AI_NUKEMOD = 200
- AI_STRIKEMOD = 20
- selecting = 0
- difficultyl = 350
- AGAINST_AI = 1
- gameState = "1serve"
- globalState = "base"
- end
- if (diff == "practice") then
- INDIC[3] = ">"
- AI_SPEED = ballSpeed * 500 + 50
- AI_LEVEL = 700
- AI_NUKEMOD = 9000000000
- AI_STRIKEMOD = 90000000
- selecting = 0
- difficultyl = 350
- AGAINST_AI = 1
- gameState = "base"
- end
- end
-
- function dangerChecker() --CHECK IF CONTROLS ARE DUPLICATING
- if (p1control.up == p1control.down) then
- danger = "1up"
- danger2 = "1down"
- elseif (p1control.up == p1control.super) then
- danger = "1up"
- danger2 = "1special"
- elseif (p1control.up == p1control.counter) then
- danger = "1up"
- danger2 = "1ct"
- elseif (p1control.down == p1control.super) then
- danger = "1down"
- danger2 = "1special"
- elseif (p1control.down == p1control.counter) then
- danger = "1ct"
- danger2 = "1down"
- elseif (p1control.super == p1control.counter) then
- danger = "1special"
- danger2 = "1ct"
- elseif (p2control.down == p2control.up) then
- danger = "2down"
- danger2 = "2up"
- elseif (p2control.down == p2control.super) then
- danger = "2down"
- danger2 = "2special"
- elseif (p2control.down == p2control.counter) then
- danger = "2down"
- danger2 = "2ct"
- elseif (p2control.up == p2control.super) then
- danger = "2up"
- danger2 = "2special"
- elseif (p2control.up == p2control.counter) then
- danger = "2ct"
- danger2 = "2up"
- elseif (p2control.super == p2control.counter) then
- danger = "2special"
- danger2 = "2ct"
- else
- danger = "none"
- danger2 = "none"
- end
- end
- function love.keypressed(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 (req == "p1up") then
- p1control.up = key
- currentKey = key
- --love.window.setTitle(key)
- gameState = "controlSettings"
- end
- if (req == "p2up") then
- p2control.up = key
- currentKey = key
- --love.window.setTitle(key)
- gameState = "controlSettings"
- end
- if (req == "p1down") then
- p1control.down = key
- currentKey = key
- --love.window.setTitle(key)
- gameState = "controlSettings"
- end
- if (req == "p2down") then
- p2control.down = key
- currentKey = key
- -- love.window.setTitle(key)
- gameState = "controlSettings"
- end
- if (req == "p1super") then
- p1control.super = key
- currentKey = key
- -- love.window.setTitle(key)
- gameState = "controlSettings"
- end
- if (req == "p2super") then
- p2control.super = key
- currentKey = key
- -- love.window.setTitle(key)
- gameState = "controlSettings"
- end
- if (req == "p1ct") then
- p1control.counter = key
- currentKey = key
- -- love.window.setTitle(key)
- gameState = "controlSettings"
- end
- if (req == "p2ct") then
- p2control.counter = key
- currentKey = key
- --love.window.setTitle(key)
- gameState = "controlSettings"
- end
- end
- if key == "escape" then
- TEXT = "Escape Key"
- love.event.quit()
- elseif key == "enter" or key == "return" then
- if gameState == "start" then
- resettinggenius()
- gameState = "menu"
- globalState = "menu"
- hardmanager()
- elseif (gameState == "done") then
- if (player1score > player2score) then
- gameState = "2serve"
- potentialnuke1 = 0
- potentialnuke2 = 0
- striken = 0
- if (nuckemodactive == 0) then
- areanuclear = 0
- nuclearanimation = 3
- end
- potentialstrike1 = 0
- potentialstrike2 = 0
- player1nukescore = 0
- player2nukescore = 0
- else
- gameState = "1serve"
- resettinggenius()
- for i = 1, maxBalls do
- ball[i]:reset(i, 1)
- end
- end
- else
- gameState = "menu"
- globalState = "menu"
- if (love.math.random(0, 10) == 1) then
- TEXT = "Nuclear Ching Chong"
- else
- TEXT = "Nuclear Pong"
- end
- resettinggenius()
- for i = 1, maxBalls do
- ball[i]:reset(i)
- end
- end
- end
- end
-
- function love.keyreleased(key)
- currentKey = " "
- if lastSentKey == key then
- lastSentKey = "g"
- end
- end
- function speedSetter(requesttype)
- if (requesttype == "ball") then
- if (ballSet > 550) then
- ballSet = 0
- paddle_SPEED = 0
- else
- ballSet = ballSet + 50
- paddle_SPEED = paddle_SPEED + 5
- end
- ballSpeed = ballSet
- end
- if (requesttype == "snc") then
- synctype = synctype + 1
- if (synctype > 1) then
- synctype = 0
- end
-
- if synctype == 0 then
- synctext = "Independent"
- end
- if synctype == 1 then
- synctext = "Synchronised"
- end
- end
- if (requesttype == "nuclearmod") then
- nuckemodactive = nuckemodactive + 1
- if (nuckemodactive > 1) then
- nuckemodactive = 0
- end
- if (nuckemodactive == 0) then
- areanuclear = 0
- nuclearanimation = 3
- ballSet = 200
- TEXT = "Nuclear Pong"
-
- synctype = 0
- maxspeed = 700
- synctext = "Independent"
- paddle_SPEED = ballSet
- AI_SPEED = ballSet
- end
- if (nuckemodactive == 1) then
- areanuclear = 1
- ballSet = 2000
- maxspeed = 2000
- paddle_SPEED = ballSet
- AI_SPEED = ballSet
- synctext = "death is imminent"
- end
- ballSpeed = ballSet
- end
- if (requesttype == "practice") then
- if (ballSpeed > 999) then
- ballSpeed = 200
- ballSet = 200
- end
- if (ballSpeed > 799) then
- prtext = "Insane"
- maxBalls = 5
- elseif ballSpeed > 599 then
- prtext = "Hard"
- maxBalls = 4
- elseif ballSpeed > 399 then
- prtext = "Normal"
- maxBalls = 3
- elseif ballSpeed > 199 then
- prtext = "Easy"
- maxBalls = 3
- end
- ballSpeed = ballSpeed + 200
- ballSet = ballSet + 200
- end
- if (requesttype == "reset") then
- ballSpeed = 200
- ballSet = 200
- synctype = 0
- prtext = "Easy"
- maxBalls = 1
- end
- if (requesttype == "pc") then
- if (playerCount == 2) then
- playerCount = 1
- playertext = "1v1"
- elseif (playerCount == 1) then
- playerCount = playerCount + 1
- player3.x = player1.x + VIRTUAL_WIDTH / 2
- player3.y = player3.y
- playertext = "2v2"
- end
- end
- if (requesttype == "ballz") then
- if (maxBalls > 1) then
- --love.window.setTitle("more than 4")
- maxBalls = 1
- else
- maxBalls = maxBalls + 1
- end
- end
- if requesttype == "ptw" then
- if ptw == 10 then
- ptw = 1
- else
- ptw = ptw + 1
- end
- end
- end
-
- function gameModeChanger()
- if (gameState == "gameMode") then
- local button_width = VIRTUAL_WIDTH * (1 / 3)
- local BUTTON_HEIGHT = 50
- local margin = 20
- local hot = false
- local cursor_y = 0
- local total_height = (BUTTON_HEIGHT + margin) * #buttons
- for i, button in ipairs(modeSelectorButtons) do
- button.last = button.now
- local bx = (VIRTUAL_WIDTH * 0.5) - (button_width * 0.5)
- local by = (VIRTUAL_HEIGHT * 0.5) - (total_height * 0.5) + cursor_y
- local color = {255, 255, 255, 255}
- local mx, my = love.mouse.getPosition()
- mx = mx * DIFFERENCE_X
- my = my * DIFFERENCE_Y
- hot = (mx > bx and mx < bx + button_width and my > by and my < by + BUTTON_HEIGHT) and i
- if (hot == i) then
- color = {10, 10, 0, 255}
- end
- button.now = love.mouse.isDown(1)
- if button.now and not button.last and hot == i then
- love.graphics.setColor(0, 0, 0, 1)
- love.graphics.rectangle("fill", 0, 0, VIRTUAL_WIDTH, VIRTUAL_HEIGHT)
- sounds["wallhit"]:play()
- button.fn()
- end
- love.graphics.setColor(unpack(color))
- love.graphics.rectangle("fill", bx, by, button_width, BUTTON_HEIGHT)
- love.graphics.setColor(0, 0, 0, 255)
- local textW = smallfont:getWidth(button.text)
- local textH = smallfont:getHeight(button.text)
- love.graphics.print(button.text, smallfont, VIRTUAL_WIDTH * 0.5 - textW * 0.5, by + textH * 0.5)
- love.graphics.setColor(255, 255, 255, 255)
- cursor_y = cursor_y + (BUTTON_HEIGHT + margin)
- end
- end
- if (gameState == "multiMode") then
- local button_width = VIRTUAL_WIDTH * (1 / 3)
- local BUTTON_HEIGHT = 50
- local margin = 20
- local hot = false
- local cursor_y = 0
- local total_height = (BUTTON_HEIGHT + margin) * #buttons
- for i, button in ipairs(playerCountButtons) do
- button.last = button.now
-
- local bx = (VIRTUAL_WIDTH * 0.5) - (button_width * 0.5)
-
- local by = (VIRTUAL_HEIGHT * 0.3) - (total_height * 0.5) + cursor_y
- if (button.text == "Play") then
- by = by + by / 1.8
- end
- local color = {255, 255, 255, 255}
- local mx, my = love.mouse.getPosition()
- mx = mx * DIFFERENCE_X
- my = my * DIFFERENCE_Y
- hot = (mx > bx and mx < bx + button_width and my > by and my < by + BUTTON_HEIGHT) and i
- if (hot == i) then
- if (button.text == "Play") then
- color = {0 / 255, 255 / 255, 0 / 255, 255}
- else
- color = {10, 10, 0, 255}
- end
- end
- button.now = love.mouse.isDown(1)
- if button.now and not button.last and hot == i then
- love.graphics.setColor(0, 0, 0, 1)
- love.graphics.rectangle("fill", 0, 0, VIRTUAL_WIDTH, VIRTUAL_HEIGHT)
- sounds["wallhit"]:play()
- if button.text == "Ball Speed: " and nuckemodactive == 1 then
- else
- button.fn()
- end
- end
- love.graphics.setColor(unpack(color))
- love.graphics.rectangle("fill", bx, by, button_width, BUTTON_HEIGHT)
- love.graphics.setColor(0, 0, 0, 255)
- local textW = smallfont:getWidth(button.text)
- local textH = smallfont:getHeight(button.text)
- if (button.text == "1v1") then
- love.graphics.print(playertext, smallfont, VIRTUAL_WIDTH * 0.5 - textW * 0.5, by + textH * 0.5)
- elseif button.text == "snc" then
- if (nuckemodactive == 1) then
- love.graphics.setColor(1, 0, 0, 1)
- love.graphics.print(synctext, smallfont, VIRTUAL_WIDTH * 0.5 - textW * 0.5, by + textH * 0.5)
- love.graphics.setColor(1, 1, 1, 1)
- love.graphics.print(synctext, smallfont, VIRTUAL_WIDTH * 0.5 - textW * 0.5, by + textH * 0.5)
- love.graphics.setColor(0, 0, 0, 1)
- else
- --
- love.graphics.print(synctext, smallfont, VIRTUAL_WIDTH * 0.45 - textW * 0.5, by + textH * 0.5)
- end
- elseif (button.text == "ballCount") then
- love.graphics.print(
- "Ball Count: " .. maxBalls,
- smallfont,
- VIRTUAL_WIDTH * 0.5 - textW * 0.5,
- by + textH * 0.5
- )
- elseif (button.text == "Ball Speed: ") then
- if (nuckemodactive == 1) then
- love.graphics.setColor(1, 0, 0, 1)
- love.graphics.print(
- "shaitan machina",
- smallfont,
- VIRTUAL_WIDTH * 0.5 - textW * 0.5,
- by + textH * 0.5
- )
- love.graphics.setColor(1, 1, 1, 1)
- love.graphics.print(
- "shaitan machina",
- smallfont,
- VIRTUAL_WIDTH * 0.5 - textW * 0.5,
- by + textH * 0.5
- )
- love.graphics.setColor(0, 0, 0, 1)
- else
- love.graphics.print(
- button.text .. ballSet,
- smallfont,
- VIRTUAL_WIDTH * 0.5 - textW * 0.5,
- by + textH * 0.5
- )
- end
- elseif button.text == "ptw" then
- love.graphics.print(
- "Points to Win: " .. ptw,
- smallfont,
- VIRTUAL_WIDTH * 0.5 - textW * 1.5,
- by + textH * 0.5
- )
- else
- love.graphics.print(button.text, smallfont, VIRTUAL_WIDTH * 0.5 - textW * 0.5, by + textH * 0.5)
- end
- love.graphics.setColor(255, 255, 255, 255)
- cursor_y = cursor_y + (BUTTON_HEIGHT + margin)
- end
- end
- end
-
- function love.draw(dt)
- simpleScale.set()
-
-
- baseDraw()
- if (globalState == "nettest" or globalState == "clienttest" or globalState == "selfhost") and confirmation == "D" then
- love.graphics.clear(50 / 255, 50 / 255, 50 / 255, 255)
- love.graphics.printf("WAIT FOR OPPONENT", 0, VIRTUAL_HEIGHT / 2, VIRTUAL_WIDTH, "center")
- end
- if (globalState == "nettest" or globalState == "clienttest" or globalState == "selfhost") 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" or globalState == "selfhost") 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
- if (globalState == "nettest" or globalState == "clienttest" or globalState == "selfhost") and confirmation == "S" then
- love.graphics.clear(50 / 255, 50 / 255, 50 / 255, 255)
- love.graphics.printf("INTERNAL SERVER WAITING", 0, VIRTUAL_HEIGHT / 2, VIRTUAL_WIDTH, "center")
- end
-
- simpleScale.unSet()
- end
-
- --Check if controls are duplicating
- function controllerSer()
- for i = 1, maxBalls do
- if (ball[i].dy == 0) then
- hitNum[i] = hitNum[i] + 1
- if hitNum[i] >= 10 then
- ball[i].dy = 1
- hitNum[i] = 0
- end
- else
- hitNum[i] = 0
- end
- end
- end
-
- function palleteController() --!!!!LEGACY CODE, MIGRATED TO Paddle.lua!!!!
- if (areanuclear == 0) then
- player1.RED = 1
- player1.GREEN = 1
- player1.BLUE = 1
- end
- if (areanuclear == 0) then
- player2.RED = 1
- player2.GREEN = 1
- player2.BLUE = 1
- end
- if (areanuclear == 1) then
- player1.RED = 0
- player1.GREEN = 0
- player1.BLUE = 0
- end
- if (areanuclear == 1) then
- player2.RED = 0
- player2.GREEN = 0
- player2.BLUE = 0
- end
- end
-
- function love.wheelmoved(x, y)
- if (y < 0 and wall1width > 0) then
- wall1width = wall1width - 5
- elseif y > 0 and wall1width < 900 then
- wall1width = wall1width + 5
- end
- end
-
- function serveBot() --THIS IS USED TO CHANGE TEXT/BALL DIRECTION ON DIFFERENT SERVES
- --print("servebot called")
- if (gameState == "1serve") then
- updateTEXT = ""
- if (gameMode ~= "practice") then
- TEXT = "PLAYER 1, serve!(q)"
- end
- if ((globalState ~= "clienttest" and love.keyboard.isDown("q")) or (globalState == "clienttest" and lastSentKeyP1 == "q")) then
- TEXT = "Lets Begin!"
- ball_DIR = 1
- if maxBalls == 1 then
- ball[1]:reset(1, 1)
- else
- for i = 1, maxBalls do
- ball[i]:reset(i)
- end
- end
- gameState = "play"
-
- end
- end
- if (gameState == "2serve") then
- TEXT = "PLAYER 2, serve!(p)"
- if (AGAINST_AI == 1) then
- TEXT = ""
- ball_DIR = -1
- if maxBalls == 1 then
- ball[2]:reset(i, 2)
- else
- for i = 1, maxBalls do
- ball[i]:reset(i)
- end
- end
-
- gameState = "play"
-
- end
- if (((globalState == "nettest" and lastSentKeyClient == "p") or ((globalState ~= "nettest") and love.keyboard.isDown("p")))and AGAINST_AI == 0) then
- TEXT = "Lets Begin"
- ball_DIR = -1
- if maxBalls == 1 then
- ball[1]:reset(1, 2)
- else
- for i = 1, maxBalls do
- ball[i]:reset(i)
- end
- end
- --love.window.setTitle("An atttttttt")
- gameState = "play"
-
- end
- end
- end
- function mapChanger()
- if (gameState == "editor") then
- MAP_TYPE = 2
- end
- if (MAP_TYPE > 2) then
- MAP_TYPE = 0
- end
-
- end
- function resolutionChanger()
- if (RESOLUTION_SET > 1) then
- RESOLUTION_SET = 0
- end
- if (RESOLUTION_SET == 0) then
- if (isFullscreen == 1) then
- DIFFERENCE_X = 1
- DIFFERENCE_Y = 1
- simpleScale.updateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, {fullscreen = false})
- isFullscreen = 0
- end
- end
- if (RESOLUTION_SET == 1) then
- if (isFullscreen == 0) then
- simpleScale.updateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, {fullscreen = true})
- local newWidth = love.graphics.getWidth()
- local newHeight = love.graphics.getHeight()
- DIFFERENCE_X = VIRTUAL_WIDTH / newWidth
- DIFFERENCE_Y = VIRTUAL_HEIGHT / newHeight
- isFullscreen = 1
- end
- end
- end
- function resettinggenius()
- maxBalls = 1
- for i = 1, maxBalls do
- ball[i]:reset(i)
- end
- paddle_SPEED = 200
- nuclearanimation = 3
- timeIsSlow = false
- timeIsSlow2 = false
- originalSpeed = 200
- gameState = "menu"
- globalState = "menu"
- gameMode = "normal"
- player1.height = 100
- player2.height = 100
- ballSet = 200
- ballSpeed = ballSet
- player2.GREEN = 255
- player2.BLUE = 255
- player1.GREEN = 255
- player1.BLUE = 255
- player1score = 0
- player2score = 0
- potentialnuke1 = 0
- potentialnuke2 = 0
- striken = 0
- areanuclear = 0
- potentialstrike1 = 0
- potentialstrike2 = 0
- player1nukescore = 0
- player2nukescore = 0
- player1reverbav = 0
- player2reverbav = 0
- selecting = 0
- AGAINST_AI = 0
- end
-
- function love.mousereleased(x, y, button)
- love.keyboard.mouseisReleased = true
- if (gameState == "editor") then
- if (#walls < 1000 and button == 1 and blockinput ~= true) then
- table.insert(walls, newWall(x * DIFFERENCE_X, y * DIFFERENCE_Y, 10, wall1width))
- end
- end
- end
-
- function ballsAlive()
- for i = 1, maxBalls do
- if ball[i].disabled == false then
- print("Ball " .. i .. " is not disabled")
- return true
- end
- end
- return false
- end
- function split(s, delimiter)
- result = {}
- for match in (s..delimiter):gmatch("(.-)"..delimiter) do
- table.insert(result, match)
- end
- return result
- end
- address, port = IP, 12345
- function checkCurrentServer(dt)
-
- if dserverinit == false then
- local socket = require "socket"
- local address, port = IP, 12345
- print(address)
- udp = socket.udp()
- udp:setpeername(address, port)
- udp:settimeout(0)
- dserverinit = true
- end
- if IP ~= address then dserverinit = false print(IP .. " " .. address)
- end
- ts = ts + dt
- --print(ts)
- if ts > checkrate then
- status = "offline"
- print("sent ping")
- udp:send("HELLO")
- local data
- data = udp:receive()
- if data then
- print("got answer!")
- local p = split(data, '|')
- status = p[1]
- print("answer is " .. status)
- else
- print("no response!")
- end
- ts = 0
- end
-
-
- end
- actualP2DATA = nil
- actualP1DATA = nil
- running = false
- local p1ping = 0
- local p2ping = 0
- local requesterip
- local requresterport
- local player1ip, player2ip, player1port, player2port = "127.0.0.1", "none", nil, nil
- local gts = 0
- function selfHost(dt)
- ts = ts + dt
- gts = gts + dt
- if serverinit == false then
- local socket = require('socket')
- udp = socket.udp()
- udp:setsockname('*', 12345)
- udp:settimeout(0)
- serverinit = true
- end
- if gts > 0.015 then
- gts = 0
- data, msg_or_ip, port_or_nil = udp:receivefrom()
- if not running then
- print("launching server")
- running = true
- local socket = require 'socket'
- local udp = socket.udp()
-
- udp:settimeout(0)
- udp:setsockname('*', 12345)
-
- end
- print("Acting as server")
- actualP2DATA = nil
- local data, msg_or_ip, port_or_nil
- local p1data, p2data
- repeat
-
- data, msg_or_ip, port_or_nil = udp:receivefrom()
- if data then
-
- if data == "HELLO" then
- requesterip = msg_or_ip
- requesterport = port_or_nil
- else
- print(string.sub(data,1,1) .. "Playerlist: " .. player1ip .. " " .. player2ip)
- if player2ip == msg_or_ip then
- p2data = data
- p2ping = 0
- else
- if 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
- print("Lobby Full!" .. player1ip .. player2ip)
- end
- end
-
- end
- end
- until not data
- if player2ip ~= "none" then
- p2ping = p2ping + 1
- if p2ping > 100 then
- if p1data then
- udp:sendto(p1data .. '|' .. p2ping, player2ip, player2port)
- end
- print("PLAYER 2 DISCONNECTED")
- p2data = nil
- player2ip = "none"
- player2port = nil
- end
- 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
- actualP2DATA = p2data
- --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
- if requesterip then
- print("getting pnged!")
- if player2ip == "none" then
- udp:sendto("clienttest", requesterip, requesterport)
- print("clienttest av to: " .. requesterip)
- else
- udp:sendto("full", requesterip, requesterport)
- print("full to: " .. msg_or_ip)
- end
- requesterip, requesterport = nil
- end
- end
- print("Integrating nettest")
-
- for i = 1, maxBalls do
-
- if ts > updaterate then
- ts = 0
- actualP1DATA = tostring(lastSentKey) ..
- '|' .. tostring(ball[1].dy) ..
- '|' .. tostring(player2.y) ..
- '|' .. tostring(player1.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) ..
- "|HOST"
- end
- end
-
- local data
- local datanumtest = 0
- local datawaspassed = false
- if actualP2DATA then
- datawaspassed = true
- print("ReceivedINFO: " .. actualP2data)
- confirmation = "N"
- local p = split(actualP2data, '|')
- if p[15] then
- if tonumber(p[16]) > 90 then
- confirmation = "L"
- end
- if p[15] ~= "CLIENT" then
- confirmation = "U"
- end
- elseif p[1] == "RESPONSE" then
- else
- confirmation = "U"
- end
-
-
- if ball[1].disabled and ball[1].x > 20 and ball[1].x < VIRTUAL_WIDTH - 20 then
- ball[1].disabled = false
- print("illegal disabling")
- end
- if (ball[1].x > VIRTUAL_WIDTH/2) then
- if tonumber(p[9]) > VIRTUAL_WIDTH/2 then
- die = tonumber(p[2])
- lastSentKeyClient,
- ball[1].dy,
- player2.y,
- player1score,
- player2score,
- player1nukescore,
- player2nukescore,
- ball[1].x,
- ball[1].y,
- gameState,
- ball[1].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])
- print("ACCEPTED")
- else
- print("DECLINED")
- end
- else
- if tonumber(p[9]) > VIRTUAL_WIDTH/2 then
- die = tonumber(p[2])
- lastSentKeyClient,
- ball[1].dy,
- player2.y,
- player1score,
- player2score,
- player1nukescore,
- player2nukescore,
- ball[1].x,
- ball[1].y,
- gameState,
- ball[1].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])
- print("ACCEPTED")
- else
- print("ENFORCED" .. ball[1].x .. " " .. ball[1].dx)
- lastSentKeyClient = p[1]
- player2.y = tonumber(p[4])
- end
- end
-
- if not datawaspassed then
- datawaspassedtimer = datawaspassedtimer + 1
- if datawaspassedtimer > 5 then
- confirmation = "D"
- datawaspassedtimer = 0
- end
- else
- datawaspassedtimer = 0
- end
- else
- confirmation = "S"
- end
- end
|