A pong clone, but with a twist!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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