Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

1944 righe
55 KiB

  1. --CALLING OTHER LUA FILES
  2. require "src/dependencies"
  3. io.stdout:setvbuf("no")
  4. --CANCELLED ATTEMPETED SHADING (NOT WORKING)
  5. local shader_code =
  6. [[
  7. vec4 effect(vec4 color, Image image, vec2 uvs, vec2 screen_coords) {
  8. vec4 pixel = Texel(image,uvs);
  9. return pixel * color;
  10. }
  11. ]]
  12. debug = true
  13. --GLOBAL VARIABLES
  14. frameratecap = 1/60
  15. realtimer = 0
  16. myip = "unknown"
  17. status = "offline"
  18. gameMode = "normal"
  19. ts = 0
  20. globalState = "menu"
  21. timeIsSlow = false
  22. timeIsSlow2 = false
  23. originalSpeed = 200
  24. explosionRange = 0
  25. blockinput = false
  26. wall1width = 30
  27. nuclearanimation = 3
  28. easternum = 0
  29. ball_DIR = 0
  30. updaterate = 0.015
  31. RED = 255
  32. hitNum = {}
  33. hitNum[1] = 0
  34. hitNum[2] = 0
  35. hitNum[3] = 0
  36. confirmation = "N"
  37. hitNum[4] = 0
  38. p1bonus = 0
  39. p2bonus = 0
  40. hitNum[5] = 0
  41. hitNum[6] = 0
  42. GREEN = 255
  43. IP = '45.76.95.31'
  44. IPnew = '45.76.95.31'
  45. BLUE = 255
  46. updateTEXT = "Chalkboard Update"
  47. maxBalls = 1
  48. playerCount = 1
  49. player1reverbav = 0
  50. playertext = "1v1"
  51. player2reverbav = 0
  52. elapsed = 0
  53. rotation = 0
  54. TEXT = "Nuclear Pong"
  55. currentKey = " "
  56. ptw = 10
  57. checkrate = 0.5
  58. --CHECKING IF CONTROLS ARE TAKEN
  59. danger = "none"
  60. danger2 = "none"
  61. nuckemodactive = 0
  62. maxspeed = 700
  63. DIFFERENCE_X = 1
  64. DIFFERENCE_Y = 1
  65. paddle_SPEED = 200
  66. textamount = 15
  67. AI_STRIKEMOD = 1000
  68. resolutionWin = 0
  69. AGAINST_AI = 0
  70. RESOLUTION_SET = 0
  71. AI_NUKEMOD = 1000
  72. animstart = true
  73. AI_SPEED = 300
  74. craz = 0
  75. AI_LEVEL = 500
  76. isFullscreen = 0
  77. prtext = "Easy"
  78. lastSentKey = "c"
  79. MAP_TYPE = 0
  80. lastSentKeyClient = "c"
  81. difficultyl = 300
  82. req = "pp"
  83. ballSet = 200
  84. p1control = {up = "a", down = "z", super = "s", counter = "x"}
  85. p2control = {up = ";", down = ".", super = "l", counter = ","}
  86. synctext = "Independent"
  87. synctype = 0
  88. function newButton(text, fn)
  89. return {
  90. text = text,
  91. fn = fn,
  92. now = false,
  93. last = false
  94. }
  95. end
  96. function love.keyboard.mouseWasReleased()
  97. return love.keyboard.mouseisReleased
  98. end
  99. function autoSave(dt)
  100. autoTimer = autoTimer + dt
  101. end
  102. function balancer()
  103. if (player2score == 9 or player1score == 9) then
  104. shakeDuration = 5
  105. if debug then
  106. --print("Shaking set to match almost over")
  107. end
  108. end
  109. if (player1score < player2score) then
  110. p1bonus = (player2score - player1score) * 5
  111. else
  112. p1bonus = 0
  113. end
  114. if (player2score < player1score) then
  115. p2bonus = (player1score - player2score) * 5
  116. else
  117. p2bonus = 0
  118. end
  119. end
  120. function newWall(wallx, wally, wallwidth, wallheight)
  121. return {
  122. wallx = wallx,
  123. wally = wally,
  124. walwidth = wallwidth,
  125. wallheight = wallheight
  126. }
  127. end
  128. speedParameters = {}
  129. buttons = {}
  130. IPselect = {}
  131. difbuttons = {}
  132. settings = {}
  133. walls = {}
  134. editorpicks = {}
  135. controlSettings = {}
  136. modeSelectorButtons = {}
  137. pracdiff = {}
  138. playerCountButtons = {}
  139. function controlChanger()
  140. if (gameState == "assign") then
  141. love.graphics.clear(50 / 255, 50 / 255, 50 / 255, 255)
  142. love.graphics.printf("SELECT BUTTON", 0, VIRTUAL_HEIGHT / 2, VIRTUAL_WIDTH, "center")
  143. end
  144. end
  145. function love.load()
  146. love.keyboard.setKeyRepeat(true)
  147. simpleScale.setWindow(VIRTUAL_WIDTH, VIRTUAL_HEIGHT, WINDOW_WIDTH, WINDOW_HEIGHT)
  148. configfile = io.open("config.lua", "r")
  149. configsave = io.open("config.lua", "w")
  150. shader = love.graphics.newShader(shader_code)
  151. time_1 = 0
  152. --print("Debug active")
  153. --load
  154. testwalls = love.filesystem.load("save.lua")()
  155. if testwalls ~= nil then
  156. walls = love.filesystem.load("save.lua")()
  157. end
  158. light = 0
  159. image = love.graphics.newImage("Madi.png")
  160. table.insert(
  161. editorpicks,
  162. newButton(
  163. "C",
  164. function()
  165. for k in pairs(walls) do
  166. walls[k] = nil
  167. end
  168. end
  169. )
  170. )
  171. table.insert(
  172. editorpicks,
  173. newButton(
  174. "S",
  175. function()
  176. love.filesystem.write("save.lua", serialize(walls))
  177. end
  178. )
  179. )
  180. table.insert(
  181. editorpicks,
  182. newButton(
  183. "L",
  184. function()
  185. walls = love.filesystem.load("save.lua")()
  186. end
  187. )
  188. )
  189. table.insert(
  190. buttons,
  191. newButton(
  192. "Singleplayer",
  193. function()
  194. gameState = "gameMode"
  195. end
  196. )
  197. )
  198. table.insert(
  199. buttons,
  200. newButton(
  201. "Online",
  202. function()
  203. MAP_TYPE = 0
  204. gameState = "chooseIP"
  205. end
  206. )
  207. )
  208. table.insert(
  209. IPselect,
  210. newButton(
  211. "Host",
  212. function()
  213. globalState = "nettest"
  214. AGAINST_AI = 0
  215. gameState = "1serve"
  216. ball[1]:reset(1, 1)
  217. end
  218. )
  219. )
  220. table.insert(
  221. IPselect,
  222. newButton(
  223. "Guest",
  224. function()
  225. globalState = "clienttest"
  226. AGAINST_AI = 0
  227. gameState = "1serve"
  228. ball[1]:reset(1, 1)
  229. end
  230. )
  231. )
  232. table.insert(
  233. buttons,
  234. newButton(
  235. "Multiplayer",
  236. function()
  237. gameState = "multiMode"
  238. end
  239. )
  240. )
  241. table.insert(
  242. buttons,
  243. newButton(
  244. "Settings",
  245. function()
  246. AGAINST_AI = 0
  247. gameState = "windowsettings"
  248. end
  249. )
  250. )
  251. table.insert(
  252. buttons,
  253. newButton(
  254. "Exit",
  255. function()
  256. love.event.quit(0)
  257. end
  258. )
  259. )
  260. table.insert(
  261. difbuttons,
  262. newButton(
  263. "Easy",
  264. function()
  265. hardmanager("easy")
  266. end
  267. )
  268. )
  269. table.insert(
  270. difbuttons,
  271. newButton(
  272. "Normal",
  273. function()
  274. hardmanager("normal")
  275. end
  276. )
  277. )
  278. table.insert(
  279. difbuttons,
  280. newButton(
  281. "Hard",
  282. function()
  283. hardmanager("hard")
  284. end
  285. )
  286. )
  287. table.insert(
  288. difbuttons,
  289. newButton(
  290. "Smart",
  291. function()
  292. hardmanager("smart")
  293. end
  294. )
  295. )
  296. --table.insert(
  297. -- settings,
  298. -- newButton(
  299. -- "Change Map",
  300. -- function()
  301. -- MAP_TYPE = MAP_TYPE + 1
  302. -- end
  303. -- )
  304. --)
  305. table.insert(
  306. settings,
  307. newButton(
  308. "Toggle Fullscreen",
  309. function()
  310. myscreen:toggle(VIRTUAL_HEIGHT, VIRTUAL_WIDTH)
  311. DIFFERENCE_X = myscreen.c
  312. DIFFERENCE_Y = myscreen.d
  313. end
  314. )
  315. )
  316. table.insert(
  317. settings,
  318. newButton(
  319. "Editor",
  320. function()
  321. gameState = "editor"
  322. end
  323. )
  324. )
  325. table.insert(
  326. settings,
  327. newButton(
  328. "Speed Settings",
  329. function()
  330. gameState = "speedSettings"
  331. end
  332. )
  333. )
  334. table.insert(
  335. settings,
  336. newButton(
  337. "Control Settings",
  338. function()
  339. gameState = "controlSettings"
  340. end
  341. )
  342. )
  343. table.insert(
  344. settings,
  345. newButton(
  346. "Back to Menu",
  347. function()
  348. gameState = "menu"
  349. end
  350. )
  351. )
  352. table.insert(
  353. speedParameters,
  354. newButton(
  355. "Back to Menu",
  356. function()
  357. gameState = "windowsettings"
  358. end
  359. )
  360. )
  361. --table.insert(speedParameters, newButton("Ball Speed: ", function() speedSetter('ball') end))
  362. table.insert(
  363. playerCountButtons,
  364. newButton(
  365. "Ball Speed: ",
  366. function()
  367. speedSetter("ball")
  368. end
  369. )
  370. )
  371. --table.insert(speedParameters, newButton("snc", function() speedSetter('snc') end))
  372. table.insert(
  373. playerCountButtons,
  374. newButton(
  375. "snc",
  376. function()
  377. speedSetter("snc")
  378. end
  379. )
  380. )
  381. table.insert(
  382. speedParameters,
  383. newButton(
  384. "NUCLEAR MODE",
  385. function()
  386. speedSetter("nuclearmod")
  387. end
  388. )
  389. )
  390. table.insert(
  391. controlSettings,
  392. newButton(
  393. "1up",
  394. function()
  395. gameState = "assign"
  396. req = "p1up"
  397. end
  398. )
  399. )
  400. table.insert(
  401. controlSettings,
  402. newButton(
  403. "1down",
  404. function()
  405. gameState = "assign"
  406. req = "p1down"
  407. end
  408. )
  409. )
  410. table.insert(
  411. controlSettings,
  412. newButton(
  413. "1special",
  414. function()
  415. gameState = "assign"
  416. req = "p1super"
  417. end
  418. )
  419. )
  420. table.insert(
  421. controlSettings,
  422. newButton(
  423. "1ct",
  424. function()
  425. gameState = "assign"
  426. req = "p1ct"
  427. end
  428. )
  429. )
  430. table.insert(
  431. controlSettings,
  432. newButton(
  433. "2up",
  434. function()
  435. gameState = "assign"
  436. req = "p2up"
  437. end
  438. )
  439. )
  440. table.insert(
  441. controlSettings,
  442. newButton(
  443. "2down",
  444. function()
  445. gameState = "assign"
  446. req = "p2down"
  447. end
  448. )
  449. )
  450. table.insert(
  451. controlSettings,
  452. newButton(
  453. "2special",
  454. function()
  455. gameState = "assign"
  456. req = "p2super"
  457. end
  458. )
  459. )
  460. table.insert(
  461. controlSettings,
  462. newButton(
  463. "2ct",
  464. function()
  465. gameState = "assign"
  466. req = "p2ct"
  467. end
  468. )
  469. )
  470. table.insert(
  471. controlSettings,
  472. newButton(
  473. "Default",
  474. function()
  475. p1control = {up = "a", down = "z", super = "s", counter = "x"}
  476. p2control = {up = ";", down = ".", super = "l", counter = ","}
  477. end
  478. )
  479. )
  480. table.insert(
  481. controlSettings,
  482. newButton(
  483. "Return",
  484. function()
  485. gameState = "windowsettings"
  486. end
  487. )
  488. )
  489. table.insert(
  490. modeSelectorButtons,
  491. newButton(
  492. "Nuclear Pong",
  493. function()
  494. gameState = "difficulty"
  495. end
  496. )
  497. )
  498. table.insert(
  499. modeSelectorButtons,
  500. newButton(
  501. "Main Menu",
  502. function()
  503. gameState = "menu"
  504. end
  505. )
  506. )
  507. table.insert(
  508. pracdiff,
  509. newButton(
  510. "Silverblade",
  511. function()
  512. speedSetter("practice")
  513. end
  514. )
  515. )
  516. table.insert(
  517. pracdiff,
  518. newButton(
  519. "Return",
  520. function()
  521. speedSetter("reset")
  522. gameState = "gameMode"
  523. end
  524. )
  525. )
  526. table.insert(
  527. pracdiff,
  528. newButton(
  529. "Go!",
  530. function()
  531. gameMode = "practice"
  532. hardmanager("practice")
  533. end
  534. )
  535. )
  536. --table.insert(playerCountButtons, newButton("1v1", function() speedSetter('pc') end))
  537. table.insert(
  538. playerCountButtons,
  539. newButton(
  540. "ballCount",
  541. function()
  542. speedSetter("ballz")
  543. end
  544. )
  545. )
  546. table.insert(
  547. difbuttons,
  548. newButton(
  549. "ballCount",
  550. function()
  551. speedSetter("ballz")
  552. end
  553. )
  554. )
  555. table.insert(
  556. playerCountButtons,
  557. newButton(
  558. "Return",
  559. function()
  560. speedSetter("reset")
  561. gameState = "menu"
  562. end
  563. )
  564. )
  565. table.insert(
  566. playerCountButtons,
  567. newButton(
  568. "ptw",
  569. function()
  570. speedSetter("ptw")
  571. end
  572. )
  573. )
  574. table.insert(
  575. playerCountButtons,
  576. newButton(
  577. "Play",
  578. function()
  579. AGAINST_AI = 0
  580. gameState = "1serve"
  581. globalState = "base"
  582. end
  583. )
  584. )
  585. table.insert(
  586. playerCountButtons,
  587. newButton(
  588. "Reverse Play",
  589. function()
  590. gameState = "1serve"
  591. gameMode = "reversegame"
  592. globalState = "base"
  593. end
  594. )
  595. )
  596. --table.insert(speedParameters, newButton("Ball Speed: ", function() speedSetter() end))
  597. love.window.setTitle("NUCLEAR PONG")
  598. textphrases = {
  599. "Amazing",
  600. "Superb",
  601. "Absolutely beautiful!",
  602. "Awesome",
  603. "Look at That!",
  604. "Great",
  605. "Nice",
  606. "Boom!",
  607. "Dangerous!",
  608. "Astonishing!",
  609. "u/ebernerd saved me",
  610. "Absolutely Wonderful!",
  611. "Exsquisite",
  612. "Delicate",
  613. "Pow!",
  614. "Great Hit",
  615. "all hail nazarbayev"
  616. }
  617. sounds = {
  618. ["updateMusic"] = love.audio.newSource("audio/theme1.mp3", "static"),
  619. ["gayTheme"] = love.audio.newSource("audio/theme2.mp3", "static"),
  620. ["gayTheme2"] = love.audio.newSource("audio/theme3.mp3", "static"),
  621. ["gayTheme3"] = love.audio.newSource("audio/theme4.mp3", "static"),
  622. ["beep"] = love.audio.newSource("audio/hit1.mp3", "static"),
  623. ["wallhit"] = love.audio.newSource("audio/hit2.wav", "static"),
  624. ["win"] = love.audio.newSource("win.wav", "static"),
  625. ["score"] = love.audio.newSource("audio/score.wav", "static"),
  626. ["nuke"] = love.audio.newSource("audio/bomb.wav", "static"),
  627. ["striking"] = love.audio.newSource("audio/superhit.wav", "static"),
  628. ["nuclearhit"] = love.audio.newSource("audio/hit1.mp3", "static"),
  629. ["time"] = love.audio.newSource("audio/time.wav", "static")
  630. }
  631. love.graphics.setDefaultFilter("nearest", "nearest")
  632. --comic sans lmao
  633. math.randomseed(os.time())
  634. smallfont = love.graphics.newFont("font.ttf", 25)
  635. scorefont = love.graphics.newFont("font.ttf", 60)
  636. love.graphics.setFont(smallfont)
  637. --push:setupScreen(VIRTUAL_WIDTH, VIRTUAL_HEIGHT, WINDOW_WIDTH, WINDOW_HEIGHT, {
  638. -- fullscreen = isFullscreen,
  639. -- resizable = true,
  640. -- vsync = true,
  641. --})
  642. player1score = 0
  643. player2score = 0
  644. areanuclear = 0
  645. player1nukescore = 0
  646. player2nukescore = 0
  647. striken = 0
  648. soundtype = 1
  649. soundturn = 1
  650. potentialstrike1 = 0
  651. potentialstrike2 = 0
  652. potentialnuke1 = 0
  653. potentialnuke2 = 0
  654. player1striken = 0
  655. player2striken = 0
  656. randomtext = 0
  657. selecting = 0
  658. number = 0
  659. elec = 1
  660. INDIC = {
  661. "",
  662. "",
  663. "",
  664. ""
  665. }
  666. --playe1nuke
  667. player1 = paddle(0, 30, 10, 100, 1)
  668. player2 = paddle(VIRTUAL_WIDTH * 0.99, VIRTUAL_HEIGHT * 0.88, 10, 100, 2)
  669. player3 = paddle(5000, 5000, 10, 100)
  670. player4 = paddle(5000, 5000, 10, 100)
  671. ball = {}
  672. ball[1] = eball(VIRTUAL_WIDTH / 2, VIRTUAL_HEIGHT / 2 - 2, 16, 16)
  673. ball[2] = eball(VIRTUAL_WIDTH / 1.9, VIRTUAL_HEIGHT / 2 - 2, 16, 16)
  674. ball[3] = eball(VIRTUAL_WIDTH / 1.8, VIRTUAL_HEIGHT / 2 - 2, 16, 16)
  675. ball[4] = eball(VIRTUAL_WIDTH / 2.2, VIRTUAL_HEIGHT / 2 - 2, 16, 16)
  676. ball[5] = eball(VIRTUAL_WIDTH / 2.1, VIRTUAL_HEIGHT / 2 - 2, 16, 16)
  677. myscreen = fullScreener(RESOLUTION_SET, isFullscreen, DIFFERENCE_X, DIFFERENCE_Y)
  678. mymenu = mainMenu()
  679. ballSpeed = 200
  680. ballDX = math.random(2) == 1 and 100 or -100
  681. ballDY = math.random(-50, 50)
  682. gameState = "animation"
  683. end
  684. t = 0
  685. shakeDuration = 0
  686. shakeMagnitude = 1
  687. function startShake(duration, magnitude)
  688. t, shakeDuration, shakeMagnitude = 0, duration or 1, magnitude or 5
  689. end
  690. function displayFPS()
  691. --love.window.setTitle(love.timer.getFPS())
  692. love.window.setTitle(globalState .. " " .. gameState .. " " .. paddle_SPEED .. " " .. p1bonus .. " " .. player1.dy)
  693. if love.keyboard.isDown("space") then
  694. player1nukescore = 200
  695. player1score = player1score + 0.2
  696. player2nukescore = 200
  697. end
  698. end
  699. function speedControl()
  700. if (ballSpeed > maxspeed and gameState == "play") then
  701. ballSpeed = maxspeed
  702. end
  703. end
  704. function love.update(dt)
  705. --print("IMPORTANT!!!!!" .. globalState .. gameState)
  706. staticanimatorcounter(dt)
  707. musicController('norm', 1)
  708. if gameState == "chooseIP" then
  709. checkCurrentServer(dt)
  710. end
  711. if debug then
  712. displayFPS()
  713. end
  714. if globalState == "base" then
  715. basegame(dt)
  716. end
  717. if globalState == "menu" then
  718. debugCheck(dt)
  719. end
  720. if globalState == "nettest" then
  721. --print("Confcode: " .. confirmation)
  722. if confirmation == "N" then
  723. basegame(dt)
  724. end
  725. nettest(dt)
  726. end
  727. if globalState == "selfhost" then
  728. --print("Confcode: " .. confirmation)
  729. if confirmation == "N" then
  730. globalState = "nettest"
  731. basegame(dt)
  732. end
  733. globalState = "selfhost"
  734. selfHost(dt)
  735. IP = "127.0.0.1"
  736. end
  737. if globalState == "clienttest" then
  738. ts = ts + dt
  739. if confirmation == "N" then
  740. lastSentKeyP1 = lastSentKeyClient
  741. clientsBaseGame(dt)
  742. end
  743. clienttest(dt)
  744. end
  745. end
  746. serverinit = false
  747. dserverinit = false
  748. datawaspassedtimer = 0
  749. clientinit = false
  750. function love.textinput(t)
  751. if gameState == "chooseIP" then
  752. IPnew = IPnew .. t
  753. end
  754. end
  755. function nettest(dt)
  756. print("nettest running")
  757. if serverinit == false then
  758. local socket = require "socket"
  759. local address, port = IP, 12345
  760. print(address)
  761. udp = socket.udp()
  762. udp:setpeername(address, port)
  763. udp:settimeout(0)
  764. serverinit = true
  765. end
  766. for i = 1, maxBalls do
  767. ts = ts + dt
  768. if ts > updaterate then
  769. udp:send(tostring(lastSentKey) ..
  770. '|' .. tostring(ball[1].dy) ..
  771. '|' .. tostring(player2.y) ..
  772. '|' .. tostring(player1.y) ..
  773. '|' .. tostring(player1score) ..
  774. '|' .. tostring(player2score) ..
  775. '|' .. tostring(player1nukescore) ..
  776. '|' .. tostring(player2nukescore) ..
  777. '|' .. tostring(ball[1].x) ..
  778. '|' .. tostring(ball[1].y) ..
  779. '|' .. gameState ..
  780. '|' .. tostring(ball[1].dx) ..
  781. '|' .. tostring(ballSpeed) ..
  782. '|' .. tostring(paddle_SPEED) ..
  783. "|HOST")
  784. ts = 0
  785. end
  786. end
  787. local data
  788. local datanumtest = 0
  789. local datawaspassed = false
  790. repeat
  791. datanumtest = datanumtest + 1
  792. print("LATENCY: " .. tostring(datanumtest))
  793. data = udp:receive()
  794. if data then
  795. datawaspassed = true
  796. print("ReceivedINFO: " .. data)
  797. confirmation = "N"
  798. local p = split(data, '|')
  799. if p[15] then
  800. if tonumber(p[16]) > 90 then
  801. confirmation = "L"
  802. end
  803. if p[15] ~= "CLIENT" then
  804. confirmation = "U"
  805. end
  806. elseif p[1] == "RESPONSE" then
  807. if p[2] == "1" then
  808. elseif p[2] == "2" then
  809. elseif p[2] == "3" then
  810. end
  811. else
  812. confirmation = "U"
  813. end
  814. if p[15] then
  815. if ball[1].disabled and ball[1].x > 20 and ball[1].x < VIRTUAL_WIDTH - 20 then
  816. ball[1].disabled = false
  817. print("illegal disabling")
  818. end
  819. if gameState ~= "1serve" then
  820. if (ball[1].x > VIRTUAL_WIDTH/2) then
  821. if tonumber(p[9]) > VIRTUAL_WIDTH/2 then
  822. die = tonumber(p[2])
  823. lastSentKeyClient,
  824. ball[1].dy,
  825. player2.y,
  826. player1score,
  827. player2score,
  828. player1nukescore,
  829. player2nukescore,
  830. ball[1].x,
  831. ball[1].y,
  832. gameState,
  833. ball[1].dx,
  834. ballSpeed,
  835. 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])
  836. print("ACCEPTED")
  837. else
  838. print("DECLINED")
  839. end
  840. else
  841. if tonumber(p[9]) > VIRTUAL_WIDTH/2 then
  842. die = tonumber(p[2])
  843. lastSentKeyClient,
  844. ball[1].dy,
  845. player2.y,
  846. player1score,
  847. player2score,
  848. player1nukescore,
  849. player2nukescore,
  850. ball[1].x,
  851. ball[1].y,
  852. gameState,
  853. ball[1].dx,
  854. ballSpeed,
  855. 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])
  856. print("ACCEPTED")
  857. else
  858. print("ENFORCED" .. ball[1].x .. " " .. ball[1].dx)
  859. lastSentKeyClient = p[1]
  860. player2.y = tonumber(p[4])
  861. end
  862. end
  863. end
  864. end
  865. end
  866. until not data
  867. if not datawaspassed then
  868. datawaspassedtimer = datawaspassedtimer + 1
  869. if datawaspassedtimer > 5 then
  870. confirmation = "D"
  871. datawaspassedtimer = 0
  872. end
  873. else
  874. datawaspassedtimer = 0
  875. end
  876. end
  877. function clienttest(dt)
  878. if clientinit == false then
  879. local socket = require "socket"
  880. local address, port = IP, 12345
  881. udp = socket.udp()
  882. udp:setpeername(address, port)
  883. udp:settimeout(0)
  884. clientinit = true
  885. end
  886. ts = ts + dt
  887. if ts > updaterate then
  888. udp:send(tostring(lastSentKey) ..
  889. '|' .. tostring(ball[1].dy) ..
  890. '|' .. tostring(player1.y) ..
  891. '|' .. tostring(player2.y) ..
  892. '|' .. tostring(player1score) ..
  893. '|' .. tostring(player2score) ..
  894. '|' .. tostring(player1nukescore) ..
  895. '|' .. tostring(player2nukescore) ..
  896. '|' .. tostring(ball[1].x) ..
  897. '|' .. tostring(ball[1].y) ..
  898. '|' .. gameState ..
  899. '|' .. tostring(ball[1].dx) ..
  900. '|' .. tostring(ballSpeed) ..
  901. '|' .. tostring(paddle_SPEED) ..
  902. "|CLIENT")
  903. ts = 0
  904. end
  905. local data
  906. local datanumtest = 0
  907. local datawaspassed = false
  908. repeat
  909. datanumtest = datanumtest + 1
  910. print("LATENCY: " .. tostring(datanumtest))
  911. data = udp:receive()
  912. if data then
  913. print("RECEIVED DATA: " .. data)
  914. datawaspassed = true
  915. print("SENT TO SERVER:" .. lastSentKey)
  916. confirmation = "N"
  917. local p = split(data, '|')
  918. if p[15] then
  919. if p[15] ~= "HOST" then
  920. confirmation = "U"
  921. end
  922. if tonumber(p[16]) > 90 then
  923. confirmation = "L"
  924. end
  925. for i = 1, maxBalls do
  926. local die = tonumber(p[2])
  927. if (ball[i].x <= VIRTUAL_WIDTH/2) then
  928. if tonumber(p[9]) <= VIRTUAL_WIDTH/2 then
  929. 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])
  930. print("ACCEPTED")
  931. else
  932. print("DECLINED")
  933. end
  934. else
  935. if tonumber(p[9]) <= VIRTUAL_WIDTH/2 then
  936. 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])
  937. print("REROUTED")
  938. else lastSentKeyClient = p[1]
  939. player1.y = tonumber(p[4])
  940. print("ENFORCED")
  941. end
  942. end
  943. end
  944. else
  945. confirmation = "U"
  946. end
  947. end
  948. print("GOT: " .. lastSentKeyClient)
  949. until not data
  950. if not datawaspassed then
  951. datawaspassedtimer = datawaspassedtimer + 1
  952. if datawaspassedtimer > 5 then
  953. confirmation = "D"
  954. datawaspassedtimer = 0
  955. end
  956. else
  957. datawaspassedtimer = 0
  958. end
  959. end
  960. function wallbreaker(x, y)
  961. if (gameState == "editor") then
  962. for i, wall in ipairs(walls) do
  963. if math.abs(wall.wallx - x) < 10 and math.abs(wall.wally - y) < 10 then
  964. table.remove(walls, i)
  965. end
  966. end
  967. end
  968. end
  969. function hardmanager(diff)
  970. selecting = 1
  971. if (diff == "easy") then
  972. INDIC[1] = ">"
  973. AGAINST_AI = 1
  974. AI_SPEED = ballSet
  975. AI_STRIKEMOD = 100
  976. AI_NUKEMOD = 1000
  977. AI_LEVEL = 350
  978. difficultyl = 200
  979. selecting = 0
  980. gameState = "1serve"
  981. globalState = "base"
  982. end
  983. if (diff == "normal") then
  984. INDIC[2] = ">"
  985. AI_SPEED = ballSet
  986. AI_LEVEL = 500
  987. AI_NUKEMOD = 250
  988. AI_STRIKEMOD = 60
  989. AGAINST_AI = 1
  990. difficultyl = 300
  991. selecting = 0
  992. gameState = "1serve"
  993. globalState = "base"
  994. end
  995. if (diff == "hard") then
  996. INDIC[3] = ">"
  997. AI_SPEED = ballSpeed * 1.1 + 50
  998. AI_LEVEL = 700
  999. AI_NUKEMOD = 200
  1000. AI_STRIKEMOD = 20
  1001. selecting = 0
  1002. difficultyl = 350
  1003. AGAINST_AI = 1
  1004. gameState = "1serve"
  1005. globalState = "base"
  1006. end
  1007. if (diff == "smart") then
  1008. INDIC[3] = ">"
  1009. AI_SPEED = ballSpeed * 1.1 + 50
  1010. AI_LEVEL = 1500
  1011. AI_NUKEMOD = 200
  1012. AI_STRIKEMOD = 20
  1013. selecting = 0
  1014. difficultyl = 350
  1015. AGAINST_AI = 1
  1016. gameState = "1serve"
  1017. globalState = "base"
  1018. end
  1019. if (diff == "practice") then
  1020. INDIC[3] = ">"
  1021. AI_SPEED = ballSpeed * 500 + 50
  1022. AI_LEVEL = 700
  1023. AI_NUKEMOD = 9000000000
  1024. AI_STRIKEMOD = 90000000
  1025. selecting = 0
  1026. difficultyl = 350
  1027. AGAINST_AI = 1
  1028. gameState = "base"
  1029. end
  1030. end
  1031. function dangerChecker() --CHECK IF CONTROLS ARE DUPLICATING
  1032. if (p1control.up == p1control.down) then
  1033. danger = "1up"
  1034. danger2 = "1down"
  1035. elseif (p1control.up == p1control.super) then
  1036. danger = "1up"
  1037. danger2 = "1special"
  1038. elseif (p1control.up == p1control.counter) then
  1039. danger = "1up"
  1040. danger2 = "1ct"
  1041. elseif (p1control.down == p1control.super) then
  1042. danger = "1down"
  1043. danger2 = "1special"
  1044. elseif (p1control.down == p1control.counter) then
  1045. danger = "1ct"
  1046. danger2 = "1down"
  1047. elseif (p1control.super == p1control.counter) then
  1048. danger = "1special"
  1049. danger2 = "1ct"
  1050. elseif (p2control.down == p2control.up) then
  1051. danger = "2down"
  1052. danger2 = "2up"
  1053. elseif (p2control.down == p2control.super) then
  1054. danger = "2down"
  1055. danger2 = "2special"
  1056. elseif (p2control.down == p2control.counter) then
  1057. danger = "2down"
  1058. danger2 = "2ct"
  1059. elseif (p2control.up == p2control.super) then
  1060. danger = "2up"
  1061. danger2 = "2special"
  1062. elseif (p2control.up == p2control.counter) then
  1063. danger = "2ct"
  1064. danger2 = "2up"
  1065. elseif (p2control.super == p2control.counter) then
  1066. danger = "2special"
  1067. danger2 = "2ct"
  1068. else
  1069. danger = "none"
  1070. danger2 = "none"
  1071. end
  1072. end
  1073. function love.keypressed(key)
  1074. lastSentKey = key
  1075. if gameState == "chooseIP" then
  1076. if key == "backspace" then
  1077. -- get the byte offset to the last UTF-8 character in the string.
  1078. local byteoffset = utf8.offset(IPnew, -1)
  1079. if byteoffset then
  1080. -- remove the last UTF-8 character.
  1081. -- string.sub operates on bytes rather than UTF-8 characters, so we couldn't do string.sub(text, 1, -2).
  1082. IPnew = string.sub(IPnew, 1, byteoffset - 1)
  1083. end
  1084. end
  1085. end
  1086. if gameState == "assign" then
  1087. if (req == "p1up") then
  1088. p1control.up = key
  1089. currentKey = key
  1090. --love.window.setTitle(key)
  1091. gameState = "controlSettings"
  1092. end
  1093. if (req == "p2up") then
  1094. p2control.up = key
  1095. currentKey = key
  1096. --love.window.setTitle(key)
  1097. gameState = "controlSettings"
  1098. end
  1099. if (req == "p1down") then
  1100. p1control.down = key
  1101. currentKey = key
  1102. --love.window.setTitle(key)
  1103. gameState = "controlSettings"
  1104. end
  1105. if (req == "p2down") then
  1106. p2control.down = key
  1107. currentKey = key
  1108. -- love.window.setTitle(key)
  1109. gameState = "controlSettings"
  1110. end
  1111. if (req == "p1super") then
  1112. p1control.super = key
  1113. currentKey = key
  1114. -- love.window.setTitle(key)
  1115. gameState = "controlSettings"
  1116. end
  1117. if (req == "p2super") then
  1118. p2control.super = key
  1119. currentKey = key
  1120. -- love.window.setTitle(key)
  1121. gameState = "controlSettings"
  1122. end
  1123. if (req == "p1ct") then
  1124. p1control.counter = key
  1125. currentKey = key
  1126. -- love.window.setTitle(key)
  1127. gameState = "controlSettings"
  1128. end
  1129. if (req == "p2ct") then
  1130. p2control.counter = key
  1131. currentKey = key
  1132. --love.window.setTitle(key)
  1133. gameState = "controlSettings"
  1134. end
  1135. end
  1136. if key == "escape" then
  1137. TEXT = "Escape Key"
  1138. love.event.quit()
  1139. elseif key == "enter" or key == "return" then
  1140. if gameState == "start" then
  1141. resettinggenius()
  1142. gameState = "menu"
  1143. globalState = "menu"
  1144. hardmanager()
  1145. elseif (gameState == "done") then
  1146. if (player1score > player2score) then
  1147. gameState = "2serve"
  1148. potentialnuke1 = 0
  1149. potentialnuke2 = 0
  1150. striken = 0
  1151. if (nuckemodactive == 0) then
  1152. areanuclear = 0
  1153. nuclearanimation = 3
  1154. end
  1155. potentialstrike1 = 0
  1156. potentialstrike2 = 0
  1157. player1nukescore = 0
  1158. player2nukescore = 0
  1159. else
  1160. gameState = "1serve"
  1161. resettinggenius()
  1162. for i = 1, maxBalls do
  1163. ball[i]:reset(i, 1)
  1164. end
  1165. end
  1166. else
  1167. gameState = "menu"
  1168. globalState = "menu"
  1169. if (love.math.random(0, 10) == 1) then
  1170. TEXT = "Nuclear Ching Chong"
  1171. else
  1172. TEXT = "Nuclear Pong"
  1173. end
  1174. resettinggenius()
  1175. for i = 1, maxBalls do
  1176. ball[i]:reset(i)
  1177. end
  1178. end
  1179. end
  1180. end
  1181. function love.keyreleased(key)
  1182. currentKey = " "
  1183. if lastSentKey == key then
  1184. lastSentKey = "g"
  1185. end
  1186. end
  1187. function speedSetter(requesttype)
  1188. if (requesttype == "ball") then
  1189. if (ballSet > 550) then
  1190. ballSet = 0
  1191. paddle_SPEED = 0
  1192. else
  1193. ballSet = ballSet + 50
  1194. paddle_SPEED = paddle_SPEED + 5
  1195. end
  1196. ballSpeed = ballSet
  1197. end
  1198. if (requesttype == "snc") then
  1199. synctype = synctype + 1
  1200. if (synctype > 1) then
  1201. synctype = 0
  1202. end
  1203. if synctype == 0 then
  1204. synctext = "Independent"
  1205. end
  1206. if synctype == 1 then
  1207. synctext = "Synchronised"
  1208. end
  1209. end
  1210. if (requesttype == "nuclearmod") then
  1211. nuckemodactive = nuckemodactive + 1
  1212. if (nuckemodactive > 1) then
  1213. nuckemodactive = 0
  1214. end
  1215. if (nuckemodactive == 0) then
  1216. areanuclear = 0
  1217. nuclearanimation = 3
  1218. ballSet = 200
  1219. TEXT = "Nuclear Pong"
  1220. synctype = 0
  1221. maxspeed = 700
  1222. synctext = "Independent"
  1223. paddle_SPEED = ballSet
  1224. AI_SPEED = ballSet
  1225. end
  1226. if (nuckemodactive == 1) then
  1227. areanuclear = 1
  1228. ballSet = 2000
  1229. maxspeed = 2000
  1230. paddle_SPEED = ballSet
  1231. AI_SPEED = ballSet
  1232. synctext = "death is imminent"
  1233. end
  1234. ballSpeed = ballSet
  1235. end
  1236. if (requesttype == "practice") then
  1237. if (ballSpeed > 999) then
  1238. ballSpeed = 200
  1239. ballSet = 200
  1240. end
  1241. if (ballSpeed > 799) then
  1242. prtext = "Insane"
  1243. maxBalls = 5
  1244. elseif ballSpeed > 599 then
  1245. prtext = "Hard"
  1246. maxBalls = 4
  1247. elseif ballSpeed > 399 then
  1248. prtext = "Normal"
  1249. maxBalls = 3
  1250. elseif ballSpeed > 199 then
  1251. prtext = "Easy"
  1252. maxBalls = 3
  1253. end
  1254. ballSpeed = ballSpeed + 200
  1255. ballSet = ballSet + 200
  1256. end
  1257. if (requesttype == "reset") then
  1258. ballSpeed = 200
  1259. ballSet = 200
  1260. synctype = 0
  1261. prtext = "Easy"
  1262. maxBalls = 1
  1263. end
  1264. if (requesttype == "pc") then
  1265. if (playerCount == 2) then
  1266. playerCount = 1
  1267. playertext = "1v1"
  1268. elseif (playerCount == 1) then
  1269. playerCount = playerCount + 1
  1270. player3.x = player1.x + VIRTUAL_WIDTH / 2
  1271. player3.y = player3.y
  1272. playertext = "2v2"
  1273. end
  1274. end
  1275. if (requesttype == "ballz") then
  1276. if (maxBalls > 1) then
  1277. --love.window.setTitle("more than 4")
  1278. maxBalls = 1
  1279. else
  1280. maxBalls = maxBalls + 1
  1281. end
  1282. end
  1283. if requesttype == "ptw" then
  1284. if ptw == 10 then
  1285. ptw = 1
  1286. else
  1287. ptw = ptw + 1
  1288. end
  1289. end
  1290. end
  1291. function gameModeChanger()
  1292. if (gameState == "gameMode") then
  1293. local button_width = VIRTUAL_WIDTH * (1 / 3)
  1294. local BUTTON_HEIGHT = 50
  1295. local margin = 20
  1296. local hot = false
  1297. local cursor_y = 0
  1298. local total_height = (BUTTON_HEIGHT + margin) * #buttons
  1299. for i, button in ipairs(modeSelectorButtons) do
  1300. button.last = button.now
  1301. local bx = (VIRTUAL_WIDTH * 0.5) - (button_width * 0.5)
  1302. local by = (VIRTUAL_HEIGHT * 0.5) - (total_height * 0.5) + cursor_y
  1303. local color = {255, 255, 255, 255}
  1304. local mx, my = love.mouse.getPosition()
  1305. mx = mx * DIFFERENCE_X
  1306. my = my * DIFFERENCE_Y
  1307. hot = (mx > bx and mx < bx + button_width and my > by and my < by + BUTTON_HEIGHT) and i
  1308. if (hot == i) then
  1309. color = {10, 10, 0, 255}
  1310. end
  1311. button.now = love.mouse.isDown(1)
  1312. if button.now and not button.last and hot == i then
  1313. love.graphics.setColor(0, 0, 0, 1)
  1314. love.graphics.rectangle("fill", 0, 0, VIRTUAL_WIDTH, VIRTUAL_HEIGHT)
  1315. sounds["wallhit"]:play()
  1316. button.fn()
  1317. end
  1318. love.graphics.setColor(unpack(color))
  1319. love.graphics.rectangle("fill", bx, by, button_width, BUTTON_HEIGHT)
  1320. love.graphics.setColor(0, 0, 0, 255)
  1321. local textW = smallfont:getWidth(button.text)
  1322. local textH = smallfont:getHeight(button.text)
  1323. love.graphics.print(button.text, smallfont, VIRTUAL_WIDTH * 0.5 - textW * 0.5, by + textH * 0.5)
  1324. love.graphics.setColor(255, 255, 255, 255)
  1325. cursor_y = cursor_y + (BUTTON_HEIGHT + margin)
  1326. end
  1327. end
  1328. if (gameState == "multiMode") then
  1329. local button_width = VIRTUAL_WIDTH * (1 / 3)
  1330. local BUTTON_HEIGHT = 50
  1331. local margin = 20
  1332. local hot = false
  1333. local cursor_y = 0
  1334. local total_height = (BUTTON_HEIGHT + margin) * #buttons
  1335. for i, button in ipairs(playerCountButtons) do
  1336. button.last = button.now
  1337. local bx = (VIRTUAL_WIDTH * 0.5) - (button_width * 0.5)
  1338. local by = (VIRTUAL_HEIGHT * 0.3) - (total_height * 0.5) + cursor_y
  1339. if (button.text == "Play") then
  1340. by = by + by / 1.8
  1341. end
  1342. local color = {255, 255, 255, 255}
  1343. local mx, my = love.mouse.getPosition()
  1344. mx = mx * DIFFERENCE_X
  1345. my = my * DIFFERENCE_Y
  1346. hot = (mx > bx and mx < bx + button_width and my > by and my < by + BUTTON_HEIGHT) and i
  1347. if (hot == i) then
  1348. if (button.text == "Play") then
  1349. color = {0 / 255, 255 / 255, 0 / 255, 255}
  1350. else
  1351. color = {10, 10, 0, 255}
  1352. end
  1353. end
  1354. button.now = love.mouse.isDown(1)
  1355. if button.now and not button.last and hot == i then
  1356. love.graphics.setColor(0, 0, 0, 1)
  1357. love.graphics.rectangle("fill", 0, 0, VIRTUAL_WIDTH, VIRTUAL_HEIGHT)
  1358. sounds["wallhit"]:play()
  1359. if button.text == "Ball Speed: " and nuckemodactive == 1 then
  1360. else
  1361. button.fn()
  1362. end
  1363. end
  1364. love.graphics.setColor(unpack(color))
  1365. love.graphics.rectangle("fill", bx, by, button_width, BUTTON_HEIGHT)
  1366. love.graphics.setColor(0, 0, 0, 255)
  1367. local textW = smallfont:getWidth(button.text)
  1368. local textH = smallfont:getHeight(button.text)
  1369. if (button.text == "1v1") then
  1370. love.graphics.print(playertext, smallfont, VIRTUAL_WIDTH * 0.5 - textW * 0.5, by + textH * 0.5)
  1371. elseif button.text == "snc" then
  1372. if (nuckemodactive == 1) then
  1373. love.graphics.setColor(1, 0, 0, 1)
  1374. love.graphics.print(synctext, smallfont, VIRTUAL_WIDTH * 0.5 - textW * 0.5, by + textH * 0.5)
  1375. love.graphics.setColor(1, 1, 1, 1)
  1376. love.graphics.print(synctext, smallfont, VIRTUAL_WIDTH * 0.5 - textW * 0.5, by + textH * 0.5)
  1377. love.graphics.setColor(0, 0, 0, 1)
  1378. else
  1379. --
  1380. love.graphics.print(synctext, smallfont, VIRTUAL_WIDTH * 0.45 - textW * 0.5, by + textH * 0.5)
  1381. end
  1382. elseif (button.text == "ballCount") then
  1383. love.graphics.print(
  1384. "Ball Count: " .. maxBalls,
  1385. smallfont,
  1386. VIRTUAL_WIDTH * 0.5 - textW * 0.5,
  1387. by + textH * 0.5
  1388. )
  1389. elseif (button.text == "Ball Speed: ") then
  1390. if (nuckemodactive == 1) then
  1391. love.graphics.setColor(1, 0, 0, 1)
  1392. love.graphics.print(
  1393. "shaitan machina",
  1394. smallfont,
  1395. VIRTUAL_WIDTH * 0.5 - textW * 0.5,
  1396. by + textH * 0.5
  1397. )
  1398. love.graphics.setColor(1, 1, 1, 1)
  1399. love.graphics.print(
  1400. "shaitan machina",
  1401. smallfont,
  1402. VIRTUAL_WIDTH * 0.5 - textW * 0.5,
  1403. by + textH * 0.5
  1404. )
  1405. love.graphics.setColor(0, 0, 0, 1)
  1406. else
  1407. love.graphics.print(
  1408. button.text .. ballSet,
  1409. smallfont,
  1410. VIRTUAL_WIDTH * 0.5 - textW * 0.5,
  1411. by + textH * 0.5
  1412. )
  1413. end
  1414. elseif button.text == "ptw" then
  1415. love.graphics.print(
  1416. "Points to Win: " .. ptw,
  1417. smallfont,
  1418. VIRTUAL_WIDTH * 0.5 - textW * 1.5,
  1419. by + textH * 0.5
  1420. )
  1421. else
  1422. love.graphics.print(button.text, smallfont, VIRTUAL_WIDTH * 0.5 - textW * 0.5, by + textH * 0.5)
  1423. end
  1424. love.graphics.setColor(255, 255, 255, 255)
  1425. cursor_y = cursor_y + (BUTTON_HEIGHT + margin)
  1426. end
  1427. end
  1428. end
  1429. function love.draw(dt)
  1430. simpleScale.set()
  1431. if globalState == "selfhost" then
  1432. globalState = "nettest"
  1433. baseDraw()
  1434. globalState = "selfhost"
  1435. else
  1436. baseDraw()
  1437. end
  1438. if (globalState == "nettest" or globalState == "clienttest" or globalState == "selfhost") and confirmation == "D" then
  1439. love.graphics.clear(50 / 255, 50 / 255, 50 / 255, 255)
  1440. love.graphics.printf("WAIT FOR OPPONENT", 0, VIRTUAL_HEIGHT / 2, VIRTUAL_WIDTH, "center")
  1441. end
  1442. if (globalState == "nettest" or globalState == "clienttest" or globalState == "selfhost") and confirmation == "U" then
  1443. love.graphics.clear(50 / 255, 50 / 255, 50 / 255, 255)
  1444. love.graphics.printf("LOBBY FULL OR WRONG MODE CHOSEN", 0, VIRTUAL_HEIGHT / 2, VIRTUAL_WIDTH, "center")
  1445. end
  1446. if (globalState == "nettest" or globalState == "clienttest" or globalState == "selfhost") and confirmation == "L" then
  1447. love.graphics.clear(50 / 255, 50 / 255, 50 / 255, 255)
  1448. love.graphics.printf("POOR CONNECTION TO SERVER", 0, VIRTUAL_HEIGHT / 2, VIRTUAL_WIDTH, "center")
  1449. end
  1450. if (globalState == "nettest" or globalState == "clienttest" or globalState == "selfhost") and confirmation == "S" then
  1451. love.graphics.clear(50 / 255, 50 / 255, 50 / 255, 255)
  1452. love.graphics.printf("INTERNAL SERVER WAITING", 0, VIRTUAL_HEIGHT / 2, VIRTUAL_WIDTH, "center")
  1453. love.graphics.printf(myip, 0, VIRTUAL_HEIGHT / 2 + 120, VIRTUAL_WIDTH, "center")
  1454. end
  1455. simpleScale.unSet()
  1456. end
  1457. --Check if controls are duplicating
  1458. function controllerSer()
  1459. for i = 1, maxBalls do
  1460. if (ball[i].dy == 0) then
  1461. hitNum[i] = hitNum[i] + 1
  1462. if hitNum[i] >= 10 then
  1463. ball[i].dy = 1
  1464. hitNum[i] = 0
  1465. end
  1466. else
  1467. hitNum[i] = 0
  1468. end
  1469. end
  1470. end
  1471. function palleteController() --!!!!LEGACY CODE, MIGRATED TO Paddle.lua!!!!
  1472. if (areanuclear == 0) then
  1473. player1.RED = 1
  1474. player1.GREEN = 1
  1475. player1.BLUE = 1
  1476. end
  1477. if (areanuclear == 0) then
  1478. player2.RED = 1
  1479. player2.GREEN = 1
  1480. player2.BLUE = 1
  1481. end
  1482. if (areanuclear == 1) then
  1483. player1.RED = 0
  1484. player1.GREEN = 0
  1485. player1.BLUE = 0
  1486. end
  1487. if (areanuclear == 1) then
  1488. player2.RED = 0
  1489. player2.GREEN = 0
  1490. player2.BLUE = 0
  1491. end
  1492. end
  1493. function love.wheelmoved(x, y)
  1494. if (y < 0 and wall1width > 0) then
  1495. wall1width = wall1width - 5
  1496. elseif y > 0 and wall1width < 900 then
  1497. wall1width = wall1width + 5
  1498. end
  1499. end
  1500. function serveBot() --THIS IS USED TO CHANGE TEXT/BALL DIRECTION ON DIFFERENT SERVES
  1501. --print("servebot called")
  1502. if (gameState == "1serve") then
  1503. updateTEXT = ""
  1504. if (gameMode ~= "practice") then
  1505. TEXT = "PLAYER 1, serve!(q)"
  1506. end
  1507. if ((globalState ~= "clienttest" and love.keyboard.isDown("q")) or (globalState == "clienttest" and lastSentKeyP1 == "q")) then
  1508. TEXT = "Lets Begin!"
  1509. ball_DIR = 1
  1510. if maxBalls == 1 then
  1511. ball[1]:reset(1, 1)
  1512. else
  1513. for i = 1, maxBalls do
  1514. ball[i]:reset(i)
  1515. end
  1516. end
  1517. gameState = "play"
  1518. end
  1519. end
  1520. if (gameState == "2serve") then
  1521. TEXT = "PLAYER 2, serve!(p)"
  1522. if (AGAINST_AI == 1) then
  1523. TEXT = ""
  1524. ball_DIR = -1
  1525. if maxBalls == 1 then
  1526. ball[2]:reset(i, 2)
  1527. else
  1528. for i = 1, maxBalls do
  1529. ball[i]:reset(i)
  1530. end
  1531. end
  1532. gameState = "play"
  1533. end
  1534. if (((globalState == "nettest" and lastSentKeyClient == "p") or ((globalState ~= "nettest") and love.keyboard.isDown("p")))and AGAINST_AI == 0) then
  1535. TEXT = "Lets Begin"
  1536. ball_DIR = -1
  1537. if maxBalls == 1 then
  1538. ball[1]:reset(1, 2)
  1539. else
  1540. for i = 1, maxBalls do
  1541. ball[i]:reset(i)
  1542. end
  1543. end
  1544. --love.window.setTitle("An atttttttt")
  1545. gameState = "play"
  1546. end
  1547. end
  1548. end
  1549. function mapChanger()
  1550. if (gameState == "editor") then
  1551. MAP_TYPE = 2
  1552. end
  1553. if (MAP_TYPE > 2) then
  1554. MAP_TYPE = 0
  1555. end
  1556. end
  1557. function resolutionChanger()
  1558. if (RESOLUTION_SET > 1) then
  1559. RESOLUTION_SET = 0
  1560. end
  1561. if (RESOLUTION_SET == 0) then
  1562. if (isFullscreen == 1) then
  1563. DIFFERENCE_X = 1
  1564. DIFFERENCE_Y = 1
  1565. simpleScale.updateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, {fullscreen = false})
  1566. isFullscreen = 0
  1567. end
  1568. end
  1569. if (RESOLUTION_SET == 1) then
  1570. if (isFullscreen == 0) then
  1571. simpleScale.updateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, {fullscreen = true})
  1572. local newWidth = love.graphics.getWidth()
  1573. local newHeight = love.graphics.getHeight()
  1574. DIFFERENCE_X = VIRTUAL_WIDTH / newWidth
  1575. DIFFERENCE_Y = VIRTUAL_HEIGHT / newHeight
  1576. isFullscreen = 1
  1577. end
  1578. end
  1579. end
  1580. function resettinggenius()
  1581. maxBalls = 1
  1582. for i = 1, maxBalls do
  1583. ball[i]:reset(i)
  1584. end
  1585. paddle_SPEED = 200
  1586. nuclearanimation = 3
  1587. timeIsSlow = false
  1588. timeIsSlow2 = false
  1589. serverinit = false
  1590. ts = 0
  1591. originalSpeed = 200
  1592. gameState = "menu"
  1593. globalState = "menu"
  1594. gameMode = "normal"
  1595. player1.height = 100
  1596. player2.height = 100
  1597. ballSet = 200
  1598. ballSpeed = ballSet
  1599. player2.GREEN = 255
  1600. player2.BLUE = 255
  1601. player1.GREEN = 255
  1602. player1.BLUE = 255
  1603. player1score = 0
  1604. player2score = 0
  1605. potentialnuke1 = 0
  1606. potentialnuke2 = 0
  1607. striken = 0
  1608. areanuclear = 0
  1609. potentialstrike1 = 0
  1610. potentialstrike2 = 0
  1611. player1nukescore = 0
  1612. player2nukescore = 0
  1613. player1reverbav = 0
  1614. player2reverbav = 0
  1615. selecting = 0
  1616. AGAINST_AI = 0
  1617. end
  1618. function love.mousereleased(x, y, button)
  1619. love.keyboard.mouseisReleased = true
  1620. if (gameState == "editor") then
  1621. if (#walls < 1000 and button == 1 and blockinput ~= true) then
  1622. table.insert(walls, newWall(x * DIFFERENCE_X, y * DIFFERENCE_Y, 10, wall1width))
  1623. end
  1624. end
  1625. end
  1626. function ballsAlive()
  1627. for i = 1, maxBalls do
  1628. if ball[i].disabled == false then
  1629. print("Ball " .. i .. " is not disabled")
  1630. return true
  1631. end
  1632. end
  1633. return false
  1634. end
  1635. function split(s, delimiter)
  1636. result = {}
  1637. for match in (s..delimiter):gmatch("(.-)"..delimiter) do
  1638. table.insert(result, match)
  1639. end
  1640. return result
  1641. end
  1642. address, port = IP, 12345
  1643. function checkCurrentServer(dt)
  1644. if GetIPType(IP) ~= 1 then
  1645. status = "offline"
  1646. end
  1647. if GetIPType(IP) == 1 then
  1648. if dserverinit == false then
  1649. print("Switching IP")
  1650. socket = require "socket"
  1651. address, port = IP, 12345
  1652. print(address)
  1653. udp = socket.udp()
  1654. udp:setpeername(address, port)
  1655. udp:settimeout(0)
  1656. dserverinit = true
  1657. end
  1658. if IP ~= address then dserverinit = false print(IP .. " doesnt equal " .. address)
  1659. else
  1660. ts = ts + dt
  1661. --print(ts)
  1662. if ts > checkrate then
  1663. status = "offline"
  1664. print("sent ping")
  1665. udp:send("HELLO")
  1666. local data
  1667. data = udp:receive()
  1668. if data then
  1669. print("got answer!")
  1670. local p = split(data, '|')
  1671. status = p[1]
  1672. print("answer is " .. status)
  1673. else
  1674. print("no response!")
  1675. end
  1676. ts = 0
  1677. end
  1678. end
  1679. end
  1680. end
  1681. local gts = 0
  1682. hostinit = false
  1683. player1ip = "127.0.0.1"
  1684. player1port = "12345"
  1685. player2ip = "none"
  1686. player2port = nil
  1687. local p1ping = 0
  1688. local p2ping = 0
  1689. local requesterip
  1690. local requresterport
  1691. function selfHost(dt)
  1692. print("Server running")
  1693. if not hostinit then
  1694. local socket = require('socket')
  1695. udp = socket.udp()
  1696. udp:setsockname('*', 12345)
  1697. udp:settimeout(0)
  1698. local s = socket.udp()
  1699. s:setpeername("74.125.115.104",80)
  1700. myip, _ = s:getsockname()
  1701. hostinit = true
  1702. else
  1703. gts = gts + dt
  1704. if gts > 0.015 then
  1705. local data, msg_or_ip, port_or_nil
  1706. local p1data, p2data
  1707. repeat
  1708. data, msg_or_ip, port_or_nil = udp:receivefrom()
  1709. if data then
  1710. if data == "HELLO" then
  1711. requesterip = msg_or_ip
  1712. requesterport = port_or_nil
  1713. else
  1714. print(string.sub(data,1,1) .. "Playerlist: " .. player1ip .. " " .. player2ip)
  1715. if player2ip == msg_or_ip then
  1716. p2data = data .. '|' .. p2ping
  1717. p2ping = 0
  1718. else
  1719. if player2ip == "none" and msg_or_ip ~= player1ip then
  1720. player2ip = msg_or_ip
  1721. p2data = data .. '|' .. p2ping
  1722. p2ping = 0
  1723. player2port = port_or_nil
  1724. print("CONNECTED: PLAYER 2 FROM: " .. player2ip)
  1725. elseif (player1ip ~= msg_or_ip and player2ip ~= msg_or_ip) then
  1726. print("Lobby Full!" .. player1ip .. player2ip)
  1727. end
  1728. end
  1729. end
  1730. end
  1731. until not data
  1732. if player1ip ~= "none" then
  1733. p1ping = p1ping + 1
  1734. end
  1735. if player2ip == "none" then
  1736. confirmation = "S"
  1737. else
  1738. print("Player2: " .. player2ip)
  1739. p2ping = p2ping + 1
  1740. if p2ping > 100 then
  1741. for i = 1, maxBalls do
  1742. ts = ts + dt
  1743. if ts > updaterate then
  1744. udp:sendto(tostring(lastSentKey) ..
  1745. '|' .. tostring(ball[1].dy) ..
  1746. '|' .. tostring(player2.y) ..
  1747. '|' .. tostring(player1.y) ..
  1748. '|' .. tostring(player1score) ..
  1749. '|' .. tostring(player2score) ..
  1750. '|' .. tostring(player1nukescore) ..
  1751. '|' .. tostring(player2nukescore) ..
  1752. '|' .. tostring(ball[1].x) ..
  1753. '|' .. tostring(ball[1].y) ..
  1754. '|' .. gameState ..
  1755. '|' .. tostring(ball[1].dx) ..
  1756. '|' .. tostring(ballSpeed) ..
  1757. '|' .. tostring(paddle_SPEED) ..
  1758. "|HOST|".. p2ping, player2ip, player2port)
  1759. ts = 0
  1760. end
  1761. end
  1762. print("PLAYER 2 DISCONNECTED")
  1763. p2data = nil
  1764. player2ip = "none"
  1765. player2port = nil
  1766. end
  1767. end
  1768. if player2port then
  1769. for i = 1, maxBalls do
  1770. ts = ts + dt
  1771. if ts > updaterate then
  1772. udp:sendto(tostring(lastSentKey) ..
  1773. '|' .. tostring(ball[1].dy) ..
  1774. '|' .. tostring(player2.y) ..
  1775. '|' .. tostring(player1.y) ..
  1776. '|' .. tostring(player1score) ..
  1777. '|' .. tostring(player2score) ..
  1778. '|' .. tostring(player1nukescore) ..
  1779. '|' .. tostring(player2nukescore) ..
  1780. '|' .. tostring(ball[1].x) ..
  1781. '|' .. tostring(ball[1].y) ..
  1782. '|' .. gameState ..
  1783. '|' .. tostring(ball[1].dx) ..
  1784. '|' .. tostring(ballSpeed) ..
  1785. '|' .. tostring(paddle_SPEED) ..
  1786. "|HOST|".. p2ping, player2ip, player2port)
  1787. ts = 0
  1788. end
  1789. end
  1790. print("SENT TO " .. player2ip .. ":" .. player2port .. " : " ..lastSentKey)
  1791. end
  1792. local datanumtest = 0
  1793. local datawaspassed = false
  1794. if p2data and player1port then
  1795. datawaspassed = true
  1796. print("ReceivedINFO: " .. p2data)
  1797. confirmation = "N"
  1798. local p = split(p2data, '|')
  1799. if p[15] then
  1800. if tonumber(p[16]) > 90 then
  1801. confirmation = "L"
  1802. end
  1803. if p[15] ~= "CLIENT" then
  1804. confirmation = "U"
  1805. end
  1806. elseif p[1] == "RESPONSE" then
  1807. if p[2] == "1" then
  1808. elseif p[2] == "2" then
  1809. elseif p[2] == "3" then
  1810. end
  1811. else
  1812. confirmation = "U"
  1813. end
  1814. if p[15] then
  1815. if ball[1].disabled and ball[1].x > 20 and ball[1].x < VIRTUAL_WIDTH - 20 then
  1816. ball[1].disabled = false
  1817. print("illegal disabling")
  1818. end
  1819. if gameState ~= "1serve" then
  1820. if (ball[1].x > VIRTUAL_WIDTH/2) then
  1821. if tonumber(p[9]) > VIRTUAL_WIDTH/2 then
  1822. die = tonumber(p[2])
  1823. lastSentKeyClient,
  1824. ball[1].dy,
  1825. player2.y,
  1826. player1score,
  1827. player2score,
  1828. player1nukescore,
  1829. player2nukescore,
  1830. ball[1].x,
  1831. ball[1].y,
  1832. gameState,
  1833. ball[1].dx,
  1834. ballSpeed,
  1835. 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])
  1836. print("ACCEPTED")
  1837. else
  1838. print("DECLINED")
  1839. end
  1840. else
  1841. if tonumber(p[9]) > VIRTUAL_WIDTH/2 then
  1842. die = tonumber(p[2])
  1843. lastSentKeyClient,
  1844. ball[1].dy,
  1845. player2.y,
  1846. player1score,
  1847. player2score,
  1848. player1nukescore,
  1849. player2nukescore,
  1850. ball[1].x,
  1851. ball[1].y,
  1852. gameState,
  1853. ball[1].dx,
  1854. ballSpeed,
  1855. 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])
  1856. print("ACCEPTED")
  1857. else
  1858. print("ENFORCED" .. ball[1].x .. " " .. ball[1].dx)
  1859. lastSentKeyClient = p[1]
  1860. player2.y = tonumber(p[4])
  1861. end
  1862. end
  1863. end
  1864. end
  1865. print("SENT TO " .. player1ip .. ":" .. player1port .. " : " .. string.sub(p2data,1,1))
  1866. --print("1::" .. p1data)
  1867. --print("2::" .. p2data)
  1868. --print("SENT1: " .. player2ip .. " " .. player2port .. " " .. p1data)
  1869. --print("SENT2: " .. player1ip .. " " .. player1port .. " " .. p2data)
  1870. end
  1871. if requesterip then
  1872. print("getting pnged!")
  1873. if player2ip == "none" then
  1874. udp:sendto("clienttest", requesterip, requesterport)
  1875. print("clienttest av to: " .. requesterip)
  1876. else
  1877. udp:sendto("full", requesterip, requesterport)
  1878. print("full to: " .. msg_or_ip)
  1879. end
  1880. requesterip, requesterport = nil
  1881. end
  1882. gts = 0
  1883. end
  1884. end
  1885. end