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.

2568 lines
73 KiB

  1. --CALLING OTHER LUA FILES
  2. require "src/dependencies"
  3. --local content = love.filesystem.read("src/libdiscord-rpc.so")
  4. --print(content)
  5. --love.filesystem.write("libdiscord-rpc.so", content)
  6. if not isAndroid then
  7. discordRPC = require("src/discordRPC")
  8. end
  9. local appId = require("applicationId")
  10. --CANCELLED ATTEMPETED SHADING (NOT WORKING)
  11. local shader_code =
  12. [[
  13. vec4 effect(vec4 color, Image image, vec2 uvs, vec2 screen_coords) {
  14. vec4 pixel = Texel(image,uvs);
  15. return pixel * color;
  16. }
  17. ]]
  18. --ANDROID EXLUSIVE VARIABLES
  19. touches = {}
  20. doubleclick1 = false
  21. doubleclick2 = false
  22. hold1 = false
  23. hold2 = false
  24. debug = true
  25. paused = false
  26. androidButtons = {}
  27. pauseButtons = {}
  28. doneButtons = {}
  29. showTouchControls = false
  30. --GLOBAL VARIABLES
  31. --0.9 VARIABLES
  32. freePlay = false
  33. startTime = os.time(os.date("*t"))
  34. globalMessage = "none"
  35. globalAnimation = "none"
  36. globalMessageTime = 0
  37. isButtonAnimated = false
  38. lowcpu = false
  39. wallsLoadError = false
  40. background = love.graphics.newImage('img/background.jpg')
  41. backgroundScroll = 0
  42. background_scroll_speed = 10
  43. background_looping_point = 810
  44. --END HERE
  45. frameratecap = 1/60
  46. realtimer = 0
  47. myip = "unknown"
  48. status = "offline"
  49. gameMode = "normal"
  50. ts = 0
  51. globalState = "menu"
  52. timeIsSlow = false
  53. timeIsSlow2 = false
  54. originalSpeed = 200
  55. explosionRange = 0
  56. blockinput = false
  57. wall1width = 30
  58. nuclearanimation = 3
  59. easternum = 0
  60. qq = 0
  61. ball_DIR = 0
  62. updaterate = 0.015
  63. RED = 255
  64. hitNum = {}
  65. hitNum[1] = 0
  66. hitNum[2] = 0
  67. hitNum[3] = 0
  68. confirmation = "N"
  69. hitNum[4] = 0
  70. p1bonus = 0
  71. p2bonus = 0
  72. hitNum[5] = 0
  73. hitNum[6] = 0
  74. GREEN = 255
  75. IP = '45.76.95.31'
  76. IPnew = '45.76.95.31'
  77. BLUE = 255
  78. updateTEXT = "Galaxy Update"
  79. maxBalls = 1
  80. playerCount = 1
  81. player1reverbav = 0
  82. playertext = "1v1"
  83. player2reverbav = 0
  84. elapsed = 0
  85. rotation = 0
  86. TEXT = "Nuclear Pong"
  87. currentKey = " "
  88. ptw = 10
  89. checkrate = 0.5
  90. --CHECKING IF CONTROLS ARE TAKEN
  91. danger = "none"
  92. danger2 = "none"
  93. nuckemodactive = 0
  94. maxspeed = 700
  95. DIFFERENCE_X = 1
  96. DIFFERENCE_Y = 1
  97. OFFSET_X = 0
  98. OFFSET_Y = 0
  99. paddle_SPEED = 200
  100. textamount = 15
  101. AI_STRIKEMOD = 1000
  102. resolutionWin = 0
  103. AGAINST_AI = 0
  104. RESOLUTION_SET = 0
  105. AI_NUKEMOD = 1000
  106. animstart = true
  107. AI_SPEED = 300
  108. craz = 0
  109. AI_LEVEL = 500
  110. isFullscreen = 0
  111. prtext = "Easy"
  112. lastSentKey = "c"
  113. MAP_TYPE = 0
  114. lastSentKeyClient = "c"
  115. difficultyl = 300
  116. req = "pp"
  117. ballSet = 200
  118. p1control = {up = "a", down = "z", super = "s", counter = "x"}
  119. p2control = {up = ";", down = ".", super = "l", counter = ","}
  120. synctext = "Independent"
  121. synctype = 0
  122. function newTouch(id, x, y)
  123. return {
  124. id = id,
  125. x = x,
  126. y = y,
  127. originalX = x,
  128. originalY = y
  129. }
  130. end
  131. function newButton(text, fn, sp, qp)
  132. if qp ~= nil then
  133. return {
  134. x = (VIRTUAL_WIDTH * 0.5) - VIRTUAL_WIDTH * (1/3)*0.5,
  135. text = text,
  136. fn = fn,
  137. skipAnim = true,
  138. now = false,
  139. last = false
  140. }
  141. else
  142. return {
  143. x = 1300,
  144. text = text,
  145. fn = fn,
  146. skipAnim = sp,
  147. now = false,
  148. last = false
  149. }
  150. end
  151. end
  152. function love.keyboard.mouseWasReleased()
  153. return love.keyboard.mouseisReleased
  154. end
  155. function autoSave(dt)
  156. autoTimer = autoTimer + dt
  157. end
  158. function balancer()
  159. if (player2score == 9 or player1score == 9) then
  160. shakeDuration = 5
  161. if debug then
  162. --print("Shaking set to match almost over")
  163. end
  164. end
  165. if (player1score < player2score) then
  166. p1bonus = (player2score - player1score) * 5
  167. else
  168. p1bonus = 0
  169. end
  170. if (player2score < player1score) then
  171. p2bonus = (player1score - player2score) * 5
  172. else
  173. p2bonus = 0
  174. end
  175. end
  176. function newWall(wallx, wally, wallwidth, wallheight)
  177. return {
  178. wallx = wallx,
  179. wally = wally,
  180. walwidth = wallwidth,
  181. wallheight = wallheight
  182. }
  183. end
  184. speedParameters = {}
  185. buttons = {}
  186. IPselect = {}
  187. difbuttons = {}
  188. settings = {}
  189. walls = {}
  190. editorpicks = {}
  191. controlSettings = {}
  192. modeSelectorButtons = {}
  193. pracdiff = {}
  194. playerCountButtons = {}
  195. function controlChanger()
  196. if (gameState == "assign") then
  197. love.graphics.clear(50 / 255, 50 / 255, 50 / 255, 255)
  198. love.graphics.printf("SELECT BUTTON", 0, VIRTUAL_HEIGHT / 2, VIRTUAL_WIDTH, "center")
  199. end
  200. end
  201. function love.load()
  202. walls = {}
  203. print (love.filesystem.getSaveDirectory())
  204. print (love.filesystem.getIdentity( ))
  205. love.graphics.setDefaultFilter('nearest', 'nearest')
  206. love.keyboard.setKeyRepeat(true)
  207. tick.framerate = 60
  208. simpleScale.setWindow(VIRTUAL_WIDTH, VIRTUAL_HEIGHT, WINDOW_WIDTH, WINDOW_HEIGHT)
  209. configfile = io.open("config.lua", "r")
  210. configsave = io.open("config.lua", "w")
  211. shader = love.graphics.newShader(shader_code)
  212. time_1 = 0
  213. --print("Debug active")
  214. --load
  215. testwalls = love.filesystem.load("save")
  216. if testwalls ~= nil then
  217. walls = love.filesystem.load("save")
  218. print("Save file found")
  219. else
  220. print("No save file found!")
  221. end
  222. light = 0
  223. image = love.graphics.newImage("Madi.png")
  224. table.insert(
  225. androidButtons,
  226. newButton(
  227. "H",
  228. function()
  229. if globalState == "base" and gameState ~= "done" then
  230. paused = true
  231. else
  232. resetButtonX(buttons)
  233. TEXT = "Nuclear Pong"
  234. resettinggenius()
  235. paused = false
  236. gameState = "menu"
  237. ball[1].dx = 1
  238. ball_DIR = 1
  239. ball[1].dy = 1
  240. globalState = "menu"
  241. hardmanager()
  242. end
  243. end,
  244. false
  245. )
  246. )
  247. table.insert(
  248. editorpicks,
  249. newButton(
  250. "C",
  251. function()
  252. for k in pairs(walls) do
  253. walls[k] = nil
  254. end
  255. end,
  256. false
  257. )
  258. )
  259. table.insert(
  260. pauseButtons,
  261. newButton(
  262. "Resume",
  263. function()
  264. paused = false
  265. TEXT = "Let's Continue"
  266. end,
  267. false
  268. )
  269. )
  270. table.insert(
  271. doneButtons,
  272. newButton(
  273. "Freeplay",
  274. function()
  275. if player1score > player2score then
  276. gameState = "2serve"
  277. else
  278. gameState = "1serve"
  279. end
  280. freePlay = true
  281. potentialnuke1 = 0
  282. potentialnuke2 = 0
  283. striken = 0
  284. if (nuckemodactive == 0) then
  285. areanuclear = 0
  286. nuclearanimation = 3
  287. end
  288. potentialstrike1 = 0
  289. potentialstrike2 = 0
  290. player1nukescore = 0
  291. player2nukescore = 0
  292. end,
  293. false
  294. )
  295. )
  296. table.insert(
  297. doneButtons,
  298. newButton(
  299. "Menu",
  300. function()
  301. resettinggenius()
  302. TEXT = "Nuclear Pong"
  303. paused = false
  304. gameState = "menu"
  305. ball[1].dx = 1
  306. ball_DIR = 1
  307. ball[1].dy = 1
  308. globalState = "menu"
  309. hardmanager()
  310. end,
  311. false
  312. )
  313. )
  314. if not isAndroid then
  315. table.insert(
  316. pauseButtons,
  317. newButton(
  318. "Toggle Fullscreen",
  319. function()
  320. myscreen:toggle(VIRTUAL_HEIGHT, VIRTUAL_WIDTH)
  321. DIFFERENCE_X = myscreen.c
  322. DIFFERENCE_Y = myscreen.d
  323. OFFSET_X = myscreen.e
  324. OFFSET_Y = myscreen.f
  325. end,
  326. true
  327. )
  328. )
  329. end
  330. table.insert(
  331. pauseButtons,
  332. newButton(
  333. "Toggle Music",
  334. function()
  335. if mute then
  336. musicController("mute", 0)
  337. else
  338. musicController("mute", 1)
  339. end
  340. end,
  341. true
  342. )
  343. )
  344. table.insert(
  345. pauseButtons,
  346. newButton(
  347. "Menu",
  348. function()
  349. resettinggenius()
  350. paused = false
  351. TEXT = "Nuclear Pong"
  352. gameState = "menu"
  353. ball[1].dx = 1
  354. ball_DIR = 1
  355. ball[1].dy = 1
  356. globalState = "menu"
  357. hardmanager()
  358. end,
  359. false
  360. )
  361. )
  362. table.insert(
  363. editorpicks,
  364. newButton(
  365. "S",
  366. function()
  367. print(love.filesystem.write("save.lua", serialize(walls)))
  368. end,
  369. true
  370. )
  371. )
  372. table.insert(
  373. editorpicks,
  374. newButton(
  375. "L",
  376. function()
  377. walls = love.filesystem.load("save.lua")()
  378. if walls == nil then
  379. walls = {}
  380. wallsLoadError = true
  381. end
  382. end,
  383. true
  384. )
  385. )
  386. table.insert(
  387. buttons,
  388. newButton(
  389. "Singleplayer",
  390. function()
  391. ptw = 10
  392. gameState = "gameMode"
  393. end,
  394. false
  395. )
  396. )
  397. table.insert(
  398. buttons,
  399. newButton(
  400. "Online",
  401. function()
  402. MAP_TYPE = 0
  403. if isAndroid then
  404. love.keyboard.setTextInput( true, 0, VIRTUAL_HEIGHT, VIRTUAL_WIDTH, VIRTUAL_HEIGHT/3)
  405. end
  406. gameState = "chooseIP"
  407. end,
  408. false
  409. )
  410. )
  411. table.insert(
  412. IPselect,
  413. newButton(
  414. "Host",
  415. function()
  416. globalState = "nettest"
  417. AGAINST_AI = 0
  418. gameState = "1serve"
  419. ball[1]:reset(1, 1)
  420. end,
  421. true
  422. )
  423. )
  424. table.insert(
  425. IPselect,
  426. newButton(
  427. "Guest",
  428. function()
  429. globalState = "clienttest"
  430. AGAINST_AI = 0
  431. gameState = "1serve"
  432. ball[1]:reset(1, 1)
  433. end,
  434. true
  435. )
  436. )
  437. table.insert(
  438. buttons,
  439. newButton(
  440. "Multiplayer",
  441. function()
  442. gameState = "multiMode"
  443. end,
  444. false
  445. )
  446. )
  447. if not isAndroid then
  448. table.insert(
  449. buttons,
  450. newButton(
  451. "Settings",
  452. function()
  453. AGAINST_AI = 0
  454. gameState = "windowsettings"
  455. end,
  456. false
  457. )
  458. )
  459. else
  460. table.insert(
  461. buttons,
  462. newButton(
  463. "Show Controls",
  464. function()
  465. if showTouchControls then
  466. showTouchControls = false
  467. else
  468. showTouchControls = true
  469. end
  470. gameState = "touchcontrols"
  471. end,
  472. true
  473. )
  474. )
  475. end
  476. table.insert(
  477. buttons,
  478. newButton(
  479. "Exit",
  480. function()
  481. love.event.quit(0)
  482. end,
  483. false
  484. )
  485. )
  486. table.insert(
  487. difbuttons,
  488. newButton(
  489. "Easy",
  490. function()
  491. hardmanager("easy")
  492. end,
  493. false
  494. )
  495. )
  496. table.insert(
  497. difbuttons,
  498. newButton(
  499. "Normal",
  500. function()
  501. hardmanager("normal")
  502. end,
  503. false
  504. )
  505. )
  506. table.insert(
  507. difbuttons,
  508. newButton(
  509. "Hard",
  510. function()
  511. hardmanager("hard")
  512. end,
  513. false
  514. )
  515. )
  516. table.insert(
  517. difbuttons,
  518. newButton(
  519. "Smart",
  520. function()
  521. hardmanager("smart")
  522. end,
  523. false
  524. )
  525. )
  526. --table.insert(
  527. -- settings,
  528. -- newButton(
  529. -- "Change Map",
  530. -- function()
  531. -- MAP_TYPE = MAP_TYPE + 1
  532. -- end
  533. -- )
  534. --)
  535. table.insert(
  536. settings,
  537. newButton(
  538. "Toggle Fullscreen",
  539. function()
  540. myscreen:toggle(VIRTUAL_HEIGHT, VIRTUAL_WIDTH)
  541. DIFFERENCE_X = myscreen.c
  542. DIFFERENCE_Y = myscreen.d
  543. OFFSET_X = myscreen.e
  544. OFFSET_Y = myscreen.f
  545. end,
  546. true
  547. )
  548. )
  549. if isAndroid then
  550. table.insert(
  551. buttons,
  552. newButton(
  553. "Toggle Music",
  554. function()
  555. if mute then
  556. musicController("mute", 0)
  557. else
  558. musicController("mute", 1)
  559. end
  560. end,
  561. true
  562. )
  563. )
  564. end
  565. table.insert(
  566. settings,
  567. newButton(
  568. "Toggle Music",
  569. function()
  570. if mute then
  571. musicController("mute", 0)
  572. else
  573. musicController("mute", 1)
  574. end
  575. end,
  576. true
  577. )
  578. )
  579. table.insert(
  580. settings,
  581. newButton(
  582. "Editor",
  583. function()
  584. gameState = "editor"
  585. end,
  586. true
  587. )
  588. )
  589. table.insert(
  590. settings,
  591. newButton(
  592. "Speed Settings",
  593. function()
  594. gameState = "speedSettings"
  595. end,
  596. true
  597. )
  598. )
  599. table.insert(
  600. settings,
  601. newButton(
  602. "Control Settings",
  603. function()
  604. gameState = "controlSettings"
  605. end,
  606. false
  607. )
  608. )
  609. table.insert(
  610. settings,
  611. newButton(
  612. "Back to Menu",
  613. function()
  614. gameState = "menu"
  615. end,
  616. false
  617. )
  618. )
  619. table.insert(
  620. speedParameters,
  621. newButton(
  622. "Back to Menu",
  623. function()
  624. gameState = "windowsettings"
  625. end,
  626. false
  627. )
  628. )
  629. --table.insert(speedParameters, newButton("Ball Speed: ", function() speedSetter('ball') end))
  630. table.insert(
  631. playerCountButtons,
  632. newButton(
  633. "Ball Speed: ",
  634. function()
  635. speedSetter("ball")
  636. end,
  637. true
  638. )
  639. )
  640. --table.insert(speedParameters, newButton("snc", function() speedSetter('snc') end))
  641. table.insert(
  642. playerCountButtons,
  643. newButton(
  644. "snc",
  645. function()
  646. speedSetter("snc")
  647. end,
  648. true
  649. )
  650. )
  651. table.insert(
  652. speedParameters,
  653. newButton(
  654. "NUCLEAR MODE",
  655. function()
  656. speedSetter("nuclearmod")
  657. end,
  658. true
  659. )
  660. )
  661. table.insert(
  662. controlSettings,
  663. newButton(
  664. "1up",
  665. function()
  666. gameState = "assign"
  667. req = "p1up"
  668. end,
  669. true
  670. )
  671. )
  672. table.insert(
  673. controlSettings,
  674. newButton(
  675. "1down",
  676. function()
  677. gameState = "assign"
  678. req = "p1down"
  679. end,
  680. true
  681. )
  682. )
  683. table.insert(
  684. controlSettings,
  685. newButton(
  686. "1special",
  687. function()
  688. gameState = "assign"
  689. req = "p1super"
  690. end,
  691. true
  692. )
  693. )
  694. table.insert(
  695. controlSettings,
  696. newButton(
  697. "1ct",
  698. function()
  699. gameState = "assign"
  700. req = "p1ct"
  701. end,
  702. true
  703. )
  704. )
  705. table.insert(
  706. controlSettings,
  707. newButton(
  708. "2up",
  709. function()
  710. gameState = "assign"
  711. req = "p2up"
  712. end,
  713. true
  714. )
  715. )
  716. table.insert(
  717. controlSettings,
  718. newButton(
  719. "2down",
  720. function()
  721. gameState = "assign"
  722. req = "p2down"
  723. end,
  724. true
  725. )
  726. )
  727. table.insert(
  728. controlSettings,
  729. newButton(
  730. "2special",
  731. function()
  732. gameState = "assign"
  733. req = "p2super"
  734. end,
  735. true
  736. )
  737. )
  738. table.insert(
  739. controlSettings,
  740. newButton(
  741. "2ct",
  742. function()
  743. gameState = "assign"
  744. req = "p2ct"
  745. end,
  746. true
  747. )
  748. )
  749. table.insert(
  750. controlSettings,
  751. newButton(
  752. "Default",
  753. function()
  754. p1control = {up = "a", down = "z", super = "s", counter = "x"}
  755. p2control = {up = ";", down = ".", super = "l", counter = ","}
  756. end,
  757. true
  758. )
  759. )
  760. table.insert(
  761. controlSettings,
  762. newButton(
  763. "Return",
  764. function()
  765. gameState = "windowsettings"
  766. end,
  767. false
  768. )
  769. )
  770. table.insert(
  771. modeSelectorButtons,
  772. newButton(
  773. "Nuclear Pong",
  774. function()
  775. gameState = "difficulty"
  776. end,
  777. false
  778. )
  779. )
  780. table.insert(
  781. modeSelectorButtons,
  782. newButton(
  783. "Main Menu",
  784. function()
  785. gameState = "menu"
  786. end,
  787. false
  788. )
  789. )
  790. table.insert(
  791. pracdiff,
  792. newButton(
  793. "Silverblade",
  794. function()
  795. speedSetter("practice")
  796. end,
  797. false
  798. )
  799. )
  800. table.insert(
  801. pracdiff,
  802. newButton(
  803. "Return",
  804. function()
  805. speedSetter("reset")
  806. gameState = "gameMode"
  807. end,
  808. false
  809. )
  810. )
  811. table.insert(
  812. pracdiff,
  813. newButton(
  814. "Go!",
  815. function()
  816. gameMode = "practice"
  817. hardmanager("practice")
  818. end,
  819. false
  820. )
  821. )
  822. --table.insert(playerCountButtons, newButton("1v1", function() speedSetter('pc') end))
  823. table.insert(
  824. playerCountButtons,
  825. newButton(
  826. "ballCount",
  827. function()
  828. speedSetter("ballz")
  829. end,
  830. true
  831. )
  832. )
  833. table.insert(
  834. difbuttons,
  835. newButton(
  836. "ballCount",
  837. function()
  838. speedSetter("ballz")
  839. end,
  840. true
  841. )
  842. )
  843. table.insert(
  844. playerCountButtons,
  845. newButton(
  846. "Return",
  847. function()
  848. speedSetter("reset")
  849. gameState = "menu"
  850. end,
  851. false
  852. )
  853. )
  854. table.insert(
  855. playerCountButtons,
  856. newButton(
  857. "ptw",
  858. function()
  859. speedSetter("ptw")
  860. end,
  861. true
  862. )
  863. )
  864. table.insert(
  865. playerCountButtons,
  866. newButton(
  867. "Play",
  868. function()
  869. AGAINST_AI = 0
  870. gameState = "1serve"
  871. globalState = "base"
  872. end,
  873. false
  874. )
  875. )
  876. table.insert(
  877. playerCountButtons,
  878. newButton(
  879. "Reverse Play",
  880. function()
  881. gameState = "1serve"
  882. gameMode = "reversegame"
  883. globalState = "base"
  884. end,
  885. false
  886. )
  887. )
  888. --table.insert(speedParameters, newButton("Ball Speed: ", function() speedSetter() end))
  889. love.window.setTitle("NUCLEAR PONG")
  890. textphrases = {
  891. "Amazing",
  892. "Superb",
  893. "Absolutely beautiful!",
  894. "Awesome",
  895. "Look at That!",
  896. "Great",
  897. "Nice",
  898. "Boom!",
  899. "Dangerous!",
  900. "Astonishing!",
  901. "u/ebernerd saved me",
  902. "Absolutely Wonderful!",
  903. "Exsquisite",
  904. "Delicate",
  905. "Pow!",
  906. "Great Hit",
  907. "all hail nazarbayev"
  908. }
  909. sounds = {
  910. ["updateMusic"] = love.audio.newSource("audio/theme1.mp3", "static"),
  911. ["gayTheme"] = love.audio.newSource("audio/theme2.mp3", "static"),
  912. ["gayTheme2"] = love.audio.newSource("audio/theme3.mp3", "static"),
  913. ["gayTheme3"] = love.audio.newSource("audio/theme4.mp3", "static"),
  914. ["gayTheme4"] = love.audio.newSource("audio/theme5.mp3", "static"),
  915. ["beep"] = love.audio.newSource("audio/hit1.mp3", "static"),
  916. ["wallhit"] = love.audio.newSource("audio/hit2.wav", "static"),
  917. ["win"] = love.audio.newSource("win.wav", "static"),
  918. ["score"] = love.audio.newSource("audio/score.wav", "static"),
  919. ["nuke"] = love.audio.newSource("audio/bomb.wav", "static"),
  920. ["striking"] = love.audio.newSource("audio/superhit.wav", "static"),
  921. ["nuclearhit"] = love.audio.newSource("audio/hit1.mp3", "static"),
  922. ["time"] = love.audio.newSource("audio/time.wav", "static")
  923. }
  924. love.graphics.setDefaultFilter("nearest", "nearest")
  925. --comic sans lmao
  926. math.randomseed(os.time())
  927. smallfont = love.graphics.newFont("font.ttf", 25)
  928. scorefont = love.graphics.newFont("font.ttf", 60)
  929. love.graphics.setFont(smallfont)
  930. if not isAndroid then
  931. discordRPC.initialize(appId, true)
  932. local now = os.time(os.date("*t"))
  933. presence = {
  934. state = "Enjoying Pong",
  935. details = "Main Menu",
  936. largeImageKey = "pongnew",
  937. largeImageText = "Nuclear Pong",
  938. }
  939. end
  940. nextPresenceUpdate = 0
  941. --push:setupScreen(VIRTUAL_WIDTH, VIRTUAL_HEIGHT, WINDOW_WIDTH, WINDOW_HEIGHT, {
  942. -- fullscreen = isFullscreen,
  943. -- resizable = true,
  944. -- vsync = true,
  945. --})
  946. love.window.setVSync( 0 )
  947. player1score = 0
  948. player2score = 0
  949. areanuclear = 0
  950. player1nukescore = 0
  951. player2nukescore = 0
  952. striken = 0
  953. soundtype = 1
  954. soundturn = 1
  955. potentialstrike1 = 0
  956. potentialstrike2 = 0
  957. potentialnuke1 = 0
  958. potentialnuke2 = 0
  959. player1striken = 0
  960. player2striken = 0
  961. randomtext = 0
  962. selecting = 0
  963. number = 0
  964. elec = 1
  965. INDIC = {
  966. "",
  967. "",
  968. "",
  969. ""
  970. }
  971. --playe1nuke
  972. player1 = paddle(0, 30, 10, 100, 1)
  973. player2 = paddle(VIRTUAL_WIDTH * 0.99, VIRTUAL_HEIGHT * 0.88, 10, 100, 2)
  974. player3 = paddle(5000, 5000, 10, 100)
  975. player4 = paddle(5000, 5000, 10, 100)
  976. ball = {}
  977. explosions = {}
  978. ball[1] = eball(VIRTUAL_WIDTH / 2, VIRTUAL_HEIGHT / 2 - 2, 16, 16)
  979. ball[2] = eball(VIRTUAL_WIDTH / 1.9, VIRTUAL_HEIGHT / 2 - 2, 16, 16)
  980. ball[3] = eball(VIRTUAL_WIDTH / 1.8, VIRTUAL_HEIGHT / 2 - 2, 16, 16)
  981. ball[4] = eball(VIRTUAL_WIDTH / 2.2, VIRTUAL_HEIGHT / 2 - 2, 16, 16)
  982. ball[5] = eball(VIRTUAL_WIDTH / 2.1, VIRTUAL_HEIGHT / 2 - 2, 16, 16)
  983. myscreen = fullScreener(RESOLUTION_SET, isFullscreen, DIFFERENCE_X, DIFFERENCE_Y, OFFSET_X, OFFSET_Y)
  984. if isAndroid then
  985. myscreen:toggle(VIRTUAL_HEIGHT, VIRTUAL_WIDTH)
  986. DIFFERENCE_X = myscreen.c
  987. DIFFERENCE_Y = myscreen.d
  988. OFFSET_X = myscreen.e
  989. OFFSET_Y = myscreen.f
  990. end
  991. mymenu = mainMenu()
  992. ballSpeed = 200
  993. background_scroll_speed = ballSpeed / 20
  994. background_scroll_speed = ballSpeed / 20
  995. ballDX = math.random(2) == 1 and 100 or -100
  996. ballDY = math.random(-50, 50)
  997. gameState = "animation"
  998. end
  999. t = 0
  1000. shakeDuration = 0
  1001. shakeMagnitude = 1
  1002. function startShake(duration, magnitude)
  1003. t, shakeDuration, shakeMagnitude = 0, duration or 1, magnitude or 5
  1004. end
  1005. function displayFPS()
  1006. love.window.setTitle("Nuclear Pong")
  1007. --love.window.setTitle(globalState .. " " .. gameState .. " " .. paddle_SPEED .. " " .. p1bonus .. " " .. player1.dy)
  1008. if love.keyboard.isDown("space") then
  1009. player1nukescore = 200
  1010. player1score = player1score + 0.2
  1011. player2nukescore = 200
  1012. end
  1013. end
  1014. function speedControl()
  1015. if (ballSpeed > maxspeed and gameState == "play") then
  1016. ballSpeed = maxspeed
  1017. background_scroll_speed = ballSpeed / 20
  1018. end
  1019. end
  1020. checking = 0
  1021. local countinglowcpu = 0
  1022. function love.update(dt)
  1023. --checking = checking + 1
  1024. --print(checking)
  1025. --print("IMPORTANT!!!!!" .. globalState .. gameState)
  1026. if globalMessage ~= "none" then
  1027. globalMessageTime = globalMessageTime + dt
  1028. if globalMessageTime > 10 then
  1029. globalMessage = "none"
  1030. end
  1031. end
  1032. if not isAndroid then
  1033. if nextPresenceUpdate < love.timer.getTime() then
  1034. discordRPC.updatePresence(presence)
  1035. nextPresenceUpdate = love.timer.getTime() + 2.0
  1036. end
  1037. discordRPC.runCallbacks()
  1038. end
  1039. if not lowcpu then
  1040. if (love.timer.getFPS() < 50 and gameState ~= "animation") then
  1041. countinglowcpu = countinglowcpu + 1
  1042. if countinglowcpu > 30 then
  1043. lowcpu = true
  1044. globalMessage = "[color=#00ff00][bounce]Low-end mode enabled[/bounce][/color]"
  1045. end
  1046. end
  1047. end
  1048. for i, explosion in ipairs(explosions) do
  1049. explosion:update(dt)
  1050. end
  1051. staticanimatorcounter(dt)
  1052. player1.goal = -1
  1053. player2.goal = -1
  1054. if gameState == "chooseIP" then
  1055. checkCurrentServer(dt)
  1056. end
  1057. if debug then
  1058. displayFPS()
  1059. --print(player2.y .. " " .. player2.goal .. " " .. player2.dy .. " " .. AI_SPEED .. " " .. paddle_SPEED .. " " .. lastSentKeyClient)
  1060. end
  1061. if globalState == "base" and not paused then
  1062. basegame(dt)
  1063. end
  1064. if globalState == "menu" then
  1065. debugCheck(dt)
  1066. if gameState ~= "animation" then
  1067. menuDemo(dt)
  1068. end
  1069. end
  1070. if gameState ~= "animation" then
  1071. musicController('norm', 1)
  1072. end
  1073. if globalState == "nettest" then
  1074. --print("Confcode: " .. confirmation)
  1075. if confirmation == "N" then
  1076. basegame(dt)
  1077. end
  1078. nettest(dt)
  1079. end
  1080. if globalState == "selfhost" then
  1081. --print("Confcode: " .. confirmation)
  1082. if confirmation == "N" then
  1083. globalState = "nettest"
  1084. basegame(dt)
  1085. end
  1086. globalState = "selfhost"
  1087. selfHost(dt)
  1088. IP = "127.0.0.1"
  1089. end
  1090. if globalState == "clienttest" then
  1091. ts = ts + dt
  1092. if confirmation == "N" then
  1093. lastSentKeyP1 = lastSentKeyClient
  1094. clientsBaseGame(dt)
  1095. end
  1096. clienttest(dt)
  1097. end
  1098. end
  1099. serverinit = false
  1100. dserverinit = false
  1101. datawaspassedtimer = 0
  1102. clientinit = false
  1103. function love.textinput(t)
  1104. if gameState == "chooseIP" then
  1105. IPnew = IPnew .. t
  1106. end
  1107. end
  1108. function nettest(dt)
  1109. --print("nettest running")
  1110. if serverinit == false then
  1111. local socket = require "socket"
  1112. local address, port = IP, 12345
  1113. --print(address)
  1114. udp = socket.udp()
  1115. udp:setpeername(address, port)
  1116. udp:settimeout(0)
  1117. serverinit = true
  1118. end
  1119. if isAndroid then
  1120. if table.empty(touches) then
  1121. lastSentKey = "g"
  1122. end
  1123. end
  1124. for i = 1, maxBalls do
  1125. ts = ts + dt
  1126. if ts > updaterate then
  1127. udp:send(tostring(lastSentKey) ..
  1128. '|' .. tostring(ball[1].dy) ..
  1129. '|' .. tostring(player2.y) ..
  1130. '|' .. tostring(player1.y) ..
  1131. '|' .. tostring(player1score) ..
  1132. '|' .. tostring(player2score) ..
  1133. '|' .. tostring(player1nukescore) ..
  1134. '|' .. tostring(player2nukescore) ..
  1135. '|' .. tostring(ball[1].x) ..
  1136. '|' .. tostring(ball[1].y) ..
  1137. '|' .. gameState ..
  1138. '|' .. tostring(ball[1].dx) ..
  1139. '|' .. tostring(ballSpeed) ..
  1140. '|' .. tostring(paddle_SPEED) ..
  1141. '|' .. tostring(player1striken) ..
  1142. '|' .. tostring(areanuclear) ..
  1143. "|HOST")
  1144. ts = 0
  1145. end
  1146. end
  1147. local data
  1148. local datanumtest = 0
  1149. local datawaspassed = false
  1150. repeat
  1151. datanumtest = datanumtest + 1
  1152. --print("LATENCY: " .. tostring(datanumtest))
  1153. data = udp:receive()
  1154. if data then
  1155. datawaspassed = true
  1156. --print("ReceivedINFO: " .. data)
  1157. confirmation = "N"
  1158. local p = split(data, '|')
  1159. if p[17] then
  1160. if tonumber(p[18]) > 90 then
  1161. confirmation = "L"
  1162. end
  1163. if p[17] ~= "CLIENT" then
  1164. confirmation = "U"
  1165. end
  1166. elseif p[1] == "RESPONSE" then
  1167. if p[2] == "1" then
  1168. elseif p[2] == "2" then
  1169. elseif p[2] == "3" then
  1170. end
  1171. else
  1172. confirmation = "U"
  1173. end
  1174. if p[17] then
  1175. if ball[1].disabled and ball[1].x > 20 and ball[1].x < VIRTUAL_WIDTH - 20 then
  1176. ball[1].disabled = false
  1177. --print("illegal disabling")
  1178. end
  1179. if gameState ~= "1serve" then
  1180. if (ball[1].x > VIRTUAL_WIDTH/2) then
  1181. if tonumber(p[9]) > VIRTUAL_WIDTH/2 then
  1182. die = tonumber(p[2])
  1183. lastSentKeyClient,
  1184. ball[1].dy,
  1185. player2.y,
  1186. player1score,
  1187. player2score,
  1188. player1nukescore,
  1189. player2nukescore,
  1190. ball[1].x,
  1191. ball[1].y,
  1192. gameState,
  1193. ball[1].dx,
  1194. ballSpeed,
  1195. paddle_SPEED,
  1196. player2striken,
  1197. areanuclear = 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]), tonumber(p[15]), tonumber(p[16])
  1198. --print("ACCEPTED")
  1199. else
  1200. --print("DECLINED")
  1201. end
  1202. else
  1203. if tonumber(p[9]) > VIRTUAL_WIDTH/2 then
  1204. die = tonumber(p[2])
  1205. lastSentKeyClient,
  1206. ball[1].dy,
  1207. player2.y,
  1208. player1score,
  1209. player2score,
  1210. player1nukescore,
  1211. player2nukescore,
  1212. ball[1].x,
  1213. ball[1].y,
  1214. gameState,
  1215. ball[1].dx,
  1216. ballSpeed,
  1217. paddle_SPEED, player2striken,
  1218. areanuclear = 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]), tonumber(p[15]), tonumber(p[16])
  1219. --print("ACCEPTED")
  1220. else
  1221. --print("ENFORCED" .. ball[1].x .. " " .. ball[1].dx)
  1222. lastSentKeyClient = p[1]
  1223. player2striken = tonumber(p[15])
  1224. player2.y = tonumber(p[4])
  1225. end
  1226. end
  1227. end
  1228. end
  1229. end
  1230. until not data
  1231. if not datawaspassed then
  1232. datawaspassedtimer = datawaspassedtimer + 1
  1233. if datawaspassedtimer > 15 then
  1234. confirmation = "D"
  1235. datawaspassedtimer = 0
  1236. end
  1237. else
  1238. datawaspassedtimer = 0
  1239. end
  1240. end
  1241. function clienttest(dt)
  1242. if clientinit == false then
  1243. local socket = require "socket"
  1244. local address, port = IP, 12345
  1245. udp = socket.udp()
  1246. udp:setpeername(address, port)
  1247. udp:settimeout(0)
  1248. clientinit = true
  1249. end
  1250. if isAndroid then
  1251. if table.empty(touches) then
  1252. lastSentKey = "g"
  1253. end
  1254. end
  1255. ts = ts + dt
  1256. if ts > updaterate then
  1257. udp:send(tostring(lastSentKey) ..
  1258. '|' .. tostring(ball[1].dy) ..
  1259. '|' .. tostring(player1.y) ..
  1260. '|' .. tostring(player2.y) ..
  1261. '|' .. tostring(player1score) ..
  1262. '|' .. tostring(player2score) ..
  1263. '|' .. tostring(player1nukescore) ..
  1264. '|' .. tostring(player2nukescore) ..
  1265. '|' .. tostring(ball[1].x) ..
  1266. '|' .. tostring(ball[1].y) ..
  1267. '|' .. gameState ..
  1268. '|' .. tostring(ball[1].dx) ..
  1269. '|' .. tostring(ballSpeed) ..
  1270. '|' .. tostring(paddle_SPEED) ..
  1271. '|' .. tostring(player2striken) ..
  1272. '|' .. tostring(areanuclear) ..
  1273. "|CLIENT")
  1274. ts = 0
  1275. end
  1276. local data
  1277. local datanumtest = 0
  1278. local datawaspassed = false
  1279. repeat
  1280. datanumtest = datanumtest + 1
  1281. --print("LATENCY: " .. tostring(datanumtest))
  1282. data = udp:receive()
  1283. if data then
  1284. --print("RECEIVED DATA: " .. data)
  1285. datawaspassed = true
  1286. --print("SENT TO SERVER:" .. lastSentKey)
  1287. confirmation = "N"
  1288. local p = split(data, '|')
  1289. if p[17] then
  1290. if p[17] ~= "HOST" then
  1291. confirmation = "U"
  1292. end
  1293. if tonumber(p[18]) > 90 then
  1294. confirmation = "L"
  1295. end
  1296. for i = 1, maxBalls do
  1297. local die = tonumber(p[2])
  1298. if (ball[i].x <= VIRTUAL_WIDTH/2) then
  1299. if tonumber(p[9]) <= VIRTUAL_WIDTH/2 then
  1300. lastSentKeyClient, ball[i].dy, player1.y, player1score, player2score, player1nukescore, player2nukescore, ball[i].x, ball[i].y, gameState, ball[i].dx, ballSpeed, paddle_SPEED, player1striken, areanuclear = 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]), tonumber(p[15]), tonumber(p[16])
  1301. --print("ACCEPTED")
  1302. else
  1303. --print("DECLINED")
  1304. end
  1305. else
  1306. if tonumber(p[9]) <= VIRTUAL_WIDTH/2 then
  1307. lastSentKeyClient, ball[i].dy, player1.y, player1score, player2score, player1nukescore, player2nukescore, ball[i].x, ball[i].y, gameState, ball[i].dx, ballSpeed, paddle_SPEED, player1striken, areanuclear = 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]), tonumber(p[15]), tonumber(p[16])
  1308. --print("REROUTED")
  1309. else lastSentKeyClient = p[1]
  1310. player1.y = tonumber(p[4])
  1311. player1striken = tonumber(p[15])
  1312. --print("ENFORCED")
  1313. end
  1314. end
  1315. end
  1316. else
  1317. confirmation = "U"
  1318. end
  1319. end
  1320. --print("GOT: " .. lastSentKeyClient)
  1321. until not data
  1322. if not datawaspassed then
  1323. datawaspassedtimer = datawaspassedtimer + 1
  1324. if datawaspassedtimer > 15 then
  1325. confirmation = "D"
  1326. datawaspassedtimer = 0
  1327. end
  1328. else
  1329. datawaspassedtimer = 0
  1330. end
  1331. end
  1332. function wallbreaker(x, y)
  1333. if (gameState == "editor") then
  1334. for i, wall in ipairs(walls) do
  1335. if math.abs(wall.wallx - x) < 10 and math.abs(wall.wally - y) < 10 then
  1336. table.remove(walls, i)
  1337. end
  1338. end
  1339. end
  1340. end
  1341. function hardmanager(diff)
  1342. selecting = 1
  1343. if (diff == "easy") then
  1344. INDIC[1] = ">"
  1345. AGAINST_AI = 1
  1346. AI_SPEED = ballSet
  1347. AI_STRIKEMOD = 100
  1348. AI_NUKEMOD = 1000
  1349. AI_LEVEL = 350
  1350. difficultyl = 200
  1351. selecting = 0
  1352. gameState = "1serve"
  1353. globalState = "base"
  1354. end
  1355. if (diff == "normal") then
  1356. INDIC[2] = ">"
  1357. AI_SPEED = ballSet
  1358. AI_LEVEL = 500
  1359. AI_NUKEMOD = 250
  1360. AI_STRIKEMOD = 60
  1361. AGAINST_AI = 1
  1362. difficultyl = 300
  1363. selecting = 0
  1364. gameState = "1serve"
  1365. globalState = "base"
  1366. end
  1367. if (diff == "hard") then
  1368. INDIC[3] = ">"
  1369. AI_SPEED = ballSpeed * 1.1 + 50
  1370. AI_LEVEL = 700
  1371. AI_NUKEMOD = 200
  1372. AI_STRIKEMOD = 20
  1373. selecting = 0
  1374. difficultyl = 350
  1375. AGAINST_AI = 1
  1376. gameState = "1serve"
  1377. globalState = "base"
  1378. end
  1379. if (diff == "smart") then
  1380. INDIC[3] = ">"
  1381. AI_SPEED = ballSpeed * 1.1 + 50
  1382. AI_LEVEL = 1500
  1383. AI_NUKEMOD = 200
  1384. AI_STRIKEMOD = 20
  1385. selecting = 0
  1386. difficultyl = 350
  1387. AGAINST_AI = 1
  1388. gameState = "1serve"
  1389. globalState = "base"
  1390. end
  1391. if (diff == "practice") then
  1392. INDIC[3] = ">"
  1393. AI_SPEED = ballSpeed * 500 + 50
  1394. AI_LEVEL = 700
  1395. AI_NUKEMOD = 9000000000
  1396. AI_STRIKEMOD = 90000000
  1397. selecting = 0
  1398. difficultyl = 350
  1399. AGAINST_AI = 1
  1400. gameState = "base"
  1401. end
  1402. startTime = os.time(os.date("*t"))
  1403. end
  1404. function dangerChecker() --CHECK IF CONTROLS ARE DUPLICATING
  1405. if (p1control.up == p1control.down) then
  1406. danger = "1up"
  1407. danger2 = "1down"
  1408. elseif (p1control.up == p1control.super) then
  1409. danger = "1up"
  1410. danger2 = "1special"
  1411. elseif (p1control.up == p1control.counter) then
  1412. danger = "1up"
  1413. danger2 = "1ct"
  1414. elseif (p1control.down == p1control.super) then
  1415. danger = "1down"
  1416. danger2 = "1special"
  1417. elseif (p1control.down == p1control.counter) then
  1418. danger = "1ct"
  1419. danger2 = "1down"
  1420. elseif (p1control.super == p1control.counter) then
  1421. danger = "1special"
  1422. danger2 = "1ct"
  1423. elseif (p2control.down == p2control.up) then
  1424. danger = "2down"
  1425. danger2 = "2up"
  1426. elseif (p2control.down == p2control.super) then
  1427. danger = "2down"
  1428. danger2 = "2special"
  1429. elseif (p2control.down == p2control.counter) then
  1430. danger = "2down"
  1431. danger2 = "2ct"
  1432. elseif (p2control.up == p2control.super) then
  1433. danger = "2up"
  1434. danger2 = "2special"
  1435. elseif (p2control.up == p2control.counter) then
  1436. danger = "2ct"
  1437. danger2 = "2up"
  1438. elseif (p2control.super == p2control.counter) then
  1439. danger = "2special"
  1440. danger2 = "2ct"
  1441. else
  1442. danger = "none"
  1443. danger2 = "none"
  1444. end
  1445. end
  1446. function love.keypressed(key)
  1447. if not isAndroid then
  1448. lastSentKey = key
  1449. end
  1450. if gameState == "chooseIP" then
  1451. if key == "backspace" then
  1452. -- get the byte offset to the last UTF-8 character in the string.
  1453. local byteoffset = utf8.offset(IPnew, -1)
  1454. if byteoffset then
  1455. -- remove the last UTF-8 character.
  1456. -- string.sub operates on bytes rather than UTF-8 characters, so we couldn't do string.sub(text, 1, -2).
  1457. IPnew = string.sub(IPnew, 1, byteoffset - 1)
  1458. end
  1459. end
  1460. end
  1461. if gameState == "assign" then
  1462. if (req == "p1up") then
  1463. p1control.up = key
  1464. currentKey = key
  1465. --love.window.setTitle(key)
  1466. gameState = "controlSettings"
  1467. end
  1468. if (req == "p2up") then
  1469. p2control.up = key
  1470. currentKey = key
  1471. --love.window.setTitle(key)
  1472. gameState = "controlSettings"
  1473. end
  1474. if (req == "p1down") then
  1475. p1control.down = key
  1476. currentKey = key
  1477. --love.window.setTitle(key)
  1478. gameState = "controlSettings"
  1479. end
  1480. if (req == "p2down") then
  1481. p2control.down = key
  1482. currentKey = key
  1483. -- love.window.setTitle(key)
  1484. gameState = "controlSettings"
  1485. end
  1486. if (req == "p1super") then
  1487. p1control.super = key
  1488. currentKey = key
  1489. -- love.window.setTitle(key)
  1490. gameState = "controlSettings"
  1491. end
  1492. if (req == "p2super") then
  1493. p2control.super = key
  1494. currentKey = key
  1495. -- love.window.setTitle(key)
  1496. gameState = "controlSettings"
  1497. end
  1498. if (req == "p1ct") then
  1499. p1control.counter = key
  1500. currentKey = key
  1501. -- love.window.setTitle(key)
  1502. gameState = "controlSettings"
  1503. end
  1504. if (req == "p2ct") then
  1505. p2control.counter = key
  1506. currentKey = key
  1507. --love.window.setTitle(key)
  1508. gameState = "controlSettings"
  1509. end
  1510. end
  1511. if key == "escape" then
  1512. if not isAndroid and globalState == "base" and gameState ~= "done" then
  1513. if paused then
  1514. paused = false
  1515. TEXT = "Let's Continue"
  1516. else
  1517. paused = true
  1518. TEXT = "PAUSED"
  1519. end
  1520. end
  1521. elseif key == "enter" or key == "return" then
  1522. if gameState == "start" then
  1523. resettinggenius()
  1524. gameState = "menu"
  1525. ball[1].dx = 1
  1526. ball[1].dy = 1
  1527. globalState = "menu"
  1528. hardmanager()
  1529. elseif (gameState == "done") then
  1530. if (player1score > player2score) then
  1531. gameState = "2serve"
  1532. potentialnuke1 = 0
  1533. potentialnuke2 = 0
  1534. striken = 0
  1535. if (nuckemodactive == 0) then
  1536. areanuclear = 0
  1537. nuclearanimation = 3
  1538. end
  1539. potentialstrike1 = 0
  1540. potentialstrike2 = 0
  1541. player1nukescore = 0
  1542. player2nukescore = 0
  1543. else
  1544. gameState = "1serve"
  1545. resettinggenius()
  1546. for i = 1, maxBalls do
  1547. ball[i]:reset(i, 1)
  1548. end
  1549. end
  1550. else
  1551. gameState = "menu"
  1552. ball[1].dx = 1
  1553. ball[1].dy = 1
  1554. globalState = "menu"
  1555. if (love.math.random(0, 20) == 1) then
  1556. TEXT = "Nuclear Ching Chong"
  1557. else
  1558. TEXT = "Nuclear Pong"
  1559. end
  1560. resettinggenius()
  1561. for i = 1, maxBalls do
  1562. ball[i]:reset(i)
  1563. end
  1564. end
  1565. end
  1566. end
  1567. function love.keyreleased(key)
  1568. currentKey = " "
  1569. if lastSentKey == key and not isAndroid then
  1570. lastSentKey = "g"
  1571. end
  1572. end
  1573. function speedSetter(requesttype)
  1574. if (requesttype == "ball") then
  1575. if (ballSet > 550) then
  1576. ballSet = 0
  1577. paddle_SPEED = 0
  1578. else
  1579. ballSet = ballSet + 50
  1580. paddle_SPEED = paddle_SPEED + 5
  1581. end
  1582. ballSpeed = ballSet
  1583. background_scroll_speed = ballSpeed / 20
  1584. end
  1585. if (requesttype == "snc") then
  1586. synctype = synctype + 1
  1587. if (synctype > 1) then
  1588. synctype = 0
  1589. end
  1590. if synctype == 0 then
  1591. synctext = "Independent"
  1592. end
  1593. if synctype == 1 then
  1594. synctext = "Synchronised"
  1595. end
  1596. end
  1597. if (requesttype == "nuclearmod") then
  1598. nuckemodactive = nuckemodactive + 1
  1599. if (nuckemodactive > 1) then
  1600. nuckemodactive = 0
  1601. end
  1602. if (nuckemodactive == 0) then
  1603. areanuclear = 0
  1604. nuclearanimation = 3
  1605. ballSet = 200
  1606. TEXT = "Nuclear Pong"
  1607. synctype = 0
  1608. maxspeed = 700
  1609. synctext = "Independent"
  1610. paddle_SPEED = ballSet
  1611. AI_SPEED = ballSet
  1612. end
  1613. if (nuckemodactive == 1) then
  1614. areanuclear = 1
  1615. ballSet = 2000
  1616. maxspeed = 2000
  1617. paddle_SPEED = ballSet
  1618. AI_SPEED = ballSet
  1619. synctext = "death is imminent"
  1620. end
  1621. ballSpeed = ballSet
  1622. background_scroll_speed = ballSpeed / 20
  1623. end
  1624. if (requesttype == "practice") then
  1625. if (ballSpeed > 999) then
  1626. ballSpeed = 200
  1627. background_scroll_speed = ballSpeed / 20
  1628. ballSet = 200
  1629. end
  1630. if (ballSpeed > 799) then
  1631. prtext = "Insane"
  1632. maxBalls = 5
  1633. elseif ballSpeed > 599 then
  1634. prtext = "Hard"
  1635. maxBalls = 4
  1636. elseif ballSpeed > 399 then
  1637. prtext = "Normal"
  1638. maxBalls = 3
  1639. elseif ballSpeed > 199 then
  1640. prtext = "Easy"
  1641. maxBalls = 3
  1642. end
  1643. ballSpeed = ballSpeed + 200
  1644. background_scroll_speed = ballSpeed / 20
  1645. ballSet = ballSet + 200
  1646. end
  1647. if (requesttype == "reset") then
  1648. ballSpeed = 200
  1649. background_scroll_speed = ballSpeed / 20
  1650. ballSet = 200
  1651. synctype = 0
  1652. prtext = "Easy"
  1653. maxBalls = 1
  1654. end
  1655. if (requesttype == "pc") then
  1656. if (playerCount == 2) then
  1657. playerCount = 1
  1658. playertext = "1v1"
  1659. elseif (playerCount == 1) then
  1660. playerCount = playerCount + 1
  1661. player3.x = player1.x + VIRTUAL_WIDTH / 2
  1662. player3.y = player3.y
  1663. playertext = "2v2"
  1664. end
  1665. end
  1666. if (requesttype == "ballz") then
  1667. if (maxBalls > 1) then
  1668. --love.window.setTitle("more than 4")
  1669. maxBalls = 1
  1670. else
  1671. maxBalls = maxBalls + 1
  1672. end
  1673. end
  1674. if requesttype == "ptw" then
  1675. if ptw == 10 then
  1676. ptw = 1
  1677. else
  1678. ptw = ptw + 1
  1679. end
  1680. end
  1681. end
  1682. function gameModeChanger()
  1683. if (gameState == "gameMode") then
  1684. local button_width = VIRTUAL_WIDTH * (1 / 3)
  1685. local BUTTON_HEIGHT = 50
  1686. local margin = 20
  1687. local hot = false
  1688. local cursor_y = 0
  1689. local total_height = (BUTTON_HEIGHT + margin) * #buttons
  1690. for i, button in ipairs(modeSelectorButtons) do
  1691. button.last = button.now
  1692. local bx = (VIRTUAL_WIDTH * 0.5) - (button_width * 0.5)
  1693. local by = (VIRTUAL_HEIGHT * 0.5) - (total_height * 0.5) + cursor_y
  1694. local color = {255, 255, 255, 255}
  1695. local mx, my = love.mouse.getPosition()
  1696. mx = mx
  1697. my = my
  1698. mx = mx * DIFFERENCE_X
  1699. my = my * DIFFERENCE_Y
  1700. hot = (mx > bx and mx < bx + button_width and my > by and my < by + BUTTON_HEIGHT) and i
  1701. if (hot == i) then
  1702. color = {10, 10, 0, 255}
  1703. end
  1704. button.now = love.mouse.isDown(1)
  1705. if button.now and not button.last and hot == i then
  1706. love.graphics.setColor(0, 0, 0, 1)
  1707. love.graphics.rectangle("fill", 0, 0, VIRTUAL_WIDTH, VIRTUAL_HEIGHT)
  1708. sounds["wallhit"]:play()
  1709. button.fn()
  1710. end
  1711. love.graphics.setColor(unpack(color))
  1712. love.graphics.rectangle("fill", bx, by, button_width, BUTTON_HEIGHT)
  1713. love.graphics.setColor(0, 0, 0, 255)
  1714. local textW = smallfont:getWidth(button.text)
  1715. local textH = smallfont:getHeight(button.text)
  1716. love.graphics.print(button.text, smallfont, VIRTUAL_WIDTH * 0.5 - textW * 0.5, by + textH * 0.5)
  1717. love.graphics.setColor(255, 255, 255, 255)
  1718. cursor_y = cursor_y + (BUTTON_HEIGHT + margin)
  1719. end
  1720. end
  1721. if (gameState == "multiMode") then
  1722. local button_width = VIRTUAL_WIDTH * (1 / 3)
  1723. local BUTTON_HEIGHT = 50
  1724. local margin = 20
  1725. local hot = false
  1726. local cursor_y = 0
  1727. local total_height = (BUTTON_HEIGHT + margin) * #buttons
  1728. for i, button in ipairs(playerCountButtons) do
  1729. button.last = button.now
  1730. local bx = (VIRTUAL_WIDTH * 0.5) - (button_width * 0.5)
  1731. local by = (VIRTUAL_HEIGHT * 0.3) - (total_height * 0.5) + cursor_y
  1732. if (button.text == "Play") then
  1733. by = by + by / 1.8
  1734. end
  1735. local color = {255, 255, 255, 255}
  1736. local mx, my = love.mouse.getPosition()
  1737. mx = mx
  1738. my = my
  1739. mx = mx * DIFFERENCE_X
  1740. my = my * DIFFERENCE_Y
  1741. hot = (mx > bx and mx < bx + button_width and my > by and my < by + BUTTON_HEIGHT) and i
  1742. if (hot == i) then
  1743. if (button.text == "Play") then
  1744. color = {0 / 255, 255 / 255, 0 / 255, 255}
  1745. else
  1746. color = {10, 10, 0, 255}
  1747. end
  1748. end
  1749. button.now = love.mouse.isDown(1)
  1750. if button.now and not button.last and hot == i then
  1751. love.graphics.setColor(0, 0, 0, 1)
  1752. love.graphics.rectangle("fill", 0, 0, VIRTUAL_WIDTH, VIRTUAL_HEIGHT)
  1753. sounds["wallhit"]:play()
  1754. if button.text == "Ball Speed: " and nuckemodactive == 1 then
  1755. else
  1756. button.fn()
  1757. end
  1758. end
  1759. love.graphics.setColor(unpack(color))
  1760. love.graphics.rectangle("fill", bx, by, button_width, BUTTON_HEIGHT)
  1761. love.graphics.setColor(0, 0, 0, 255)
  1762. local textW = smallfont:getWidth(button.text)
  1763. local textH = smallfont:getHeight(button.text)
  1764. if (button.text == "1v1") then
  1765. love.graphics.print(playertext, smallfont, VIRTUAL_WIDTH * 0.5 - textW * 0.5, by + textH * 0.5)
  1766. elseif button.text == "snc" then
  1767. if (nuckemodactive == 1) then
  1768. love.graphics.setColor(1, 0, 0, 1)
  1769. love.graphics.print(synctext, smallfont, VIRTUAL_WIDTH * 0.5 - textW * 0.5, by + textH * 0.5)
  1770. love.graphics.setColor(1, 1, 1, 1)
  1771. love.graphics.print(synctext, smallfont, VIRTUAL_WIDTH * 0.5 - textW * 0.5, by + textH * 0.5)
  1772. love.graphics.setColor(0, 0, 0, 1)
  1773. else
  1774. --
  1775. love.graphics.print(synctext, smallfont, VIRTUAL_WIDTH * 0.45 - textW * 0.5, by + textH * 0.5)
  1776. end
  1777. elseif (button.text == "ballCount") then
  1778. love.graphics.print(
  1779. "Ball Count: " .. maxBalls,
  1780. smallfont,
  1781. VIRTUAL_WIDTH * 0.5 - textW * 0.5,
  1782. by + textH * 0.5
  1783. )
  1784. elseif (button.text == "Ball Speed: ") then
  1785. if (nuckemodactive == 1) then
  1786. love.graphics.setColor(1, 0, 0, 1)
  1787. love.graphics.print(
  1788. "shaitan machina",
  1789. smallfont,
  1790. VIRTUAL_WIDTH * 0.5 - textW * 0.5,
  1791. by + textH * 0.5
  1792. )
  1793. love.graphics.setColor(1, 1, 1, 1)
  1794. love.graphics.print(
  1795. "shaitan machina",
  1796. smallfont,
  1797. VIRTUAL_WIDTH * 0.5 - textW * 0.5,
  1798. by + textH * 0.5
  1799. )
  1800. love.graphics.setColor(0, 0, 0, 1)
  1801. else
  1802. love.graphics.print(
  1803. button.text .. ballSet,
  1804. smallfont,
  1805. VIRTUAL_WIDTH * 0.5 - textW * 0.5,
  1806. by + textH * 0.5
  1807. )
  1808. end
  1809. elseif button.text == "ptw" then
  1810. love.graphics.print(
  1811. "Points to Win: " .. ptw,
  1812. smallfont,
  1813. VIRTUAL_WIDTH * 0.5 - textW * 1.5,
  1814. by + textH * 0.5
  1815. )
  1816. else
  1817. love.graphics.print(button.text, smallfont, VIRTUAL_WIDTH * 0.5 - textW * 0.5, by + textH * 0.5)
  1818. end
  1819. love.graphics.setColor(255, 255, 255, 255)
  1820. cursor_y = cursor_y + (BUTTON_HEIGHT + margin)
  1821. end
  1822. end
  1823. end
  1824. function love.draw(dt)
  1825. simpleScale.set()
  1826. if globalState == "selfhost" then
  1827. globalState = "nettest"
  1828. baseDraw()
  1829. globalState = "selfhost"
  1830. else
  1831. baseDraw()
  1832. end
  1833. if (globalState == "nettest" or globalState == "clienttest" or globalState == "selfhost") and confirmation == "D" then
  1834. love.graphics.clear(50 / 255, 50 / 255, 50 / 255, 255)
  1835. love.graphics.printf("WAIT FOR OPPONENT", 0, VIRTUAL_HEIGHT / 2, VIRTUAL_WIDTH, "center")
  1836. end
  1837. if (globalState == "nettest" or globalState == "clienttest" or globalState == "selfhost") and confirmation == "U" then
  1838. love.graphics.clear(50 / 255, 50 / 255, 50 / 255, 255)
  1839. love.graphics.printf("LOBBY FULL OR WRONG MODE CHOSEN", 0, VIRTUAL_HEIGHT / 2, VIRTUAL_WIDTH, "center")
  1840. end
  1841. if (globalState == "nettest" or globalState == "clienttest" or globalState == "selfhost") and confirmation == "L" then
  1842. love.graphics.clear(50 / 255, 50 / 255, 50 / 255, 255)
  1843. love.graphics.printf("POOR CONNECTION TO SERVER", 0, VIRTUAL_HEIGHT / 2, VIRTUAL_WIDTH, "center")
  1844. end
  1845. if (globalState == "nettest" or globalState == "clienttest" or globalState == "selfhost") and confirmation == "S" then
  1846. love.graphics.clear(50 / 255, 50 / 255, 50 / 255, 255)
  1847. love.graphics.printf("INTERNAL SERVER WAITING", 0, VIRTUAL_HEIGHT / 2, VIRTUAL_WIDTH, "center")
  1848. love.graphics.printf(myip, 0, VIRTUAL_HEIGHT / 2 + 120, VIRTUAL_WIDTH, "center")
  1849. end
  1850. if isAndroid then
  1851. androidDraw()
  1852. love.keyboard.mouseisReleased = false
  1853. end
  1854. if debug then
  1855. if touches then
  1856. for i, touch in ipairs(touches) do
  1857. love.graphics.printf(touch.x, 0, VIRTUAL_HEIGHT / 2, VIRTUAL_WIDTH, "center")
  1858. end
  1859. end
  1860. end
  1861. showMessage()
  1862. if wallsLoadError then
  1863. love.graphics.setColor(1,0,0,1)
  1864. love.graphics.printf("Error loading map!", 0,0,VIRTUAL_WIDTH, "left")
  1865. end
  1866. simpleScale.unSet()
  1867. end
  1868. --Check if controls are duplicating
  1869. function controllerSer()
  1870. for i = 1, maxBalls do
  1871. if (ball[i].dy == 0) then
  1872. hitNum[i] = hitNum[i] + 1
  1873. if hitNum[i] >= 10 then
  1874. ball[i].dy = 1
  1875. hitNum[i] = 0
  1876. end
  1877. else
  1878. hitNum[i] = 0
  1879. end
  1880. end
  1881. end
  1882. function palleteController() --!!!!LEGACY CODE, MIGRATED TO Paddle.lua!!!!
  1883. if (areanuclear == 0) then
  1884. player1.RED = 1
  1885. player1.GREEN = 1
  1886. player1.BLUE = 1
  1887. end
  1888. if (areanuclear == 0) then
  1889. player2.RED = 1
  1890. player2.GREEN = 1
  1891. player2.BLUE = 1
  1892. end
  1893. if (areanuclear == 1) then
  1894. player1.RED = 0
  1895. player1.GREEN = 0
  1896. player1.BLUE = 0
  1897. end
  1898. if (areanuclear == 1) then
  1899. player2.RED = 0
  1900. player2.GREEN = 0
  1901. player2.BLUE = 0
  1902. end
  1903. end
  1904. function love.wheelmoved(x, y)
  1905. if (y < 0 and wall1width > 0) then
  1906. wall1width = wall1width - 5
  1907. elseif y > 0 and wall1width < 900 then
  1908. wall1width = wall1width + 5
  1909. end
  1910. end
  1911. function serveBot() --THIS IS USED TO CHANGE TEXT/BALL DIRECTION ON DIFFERENT SERVES
  1912. --print("servebot called")
  1913. presence = {
  1914. state = "Playing Pong",
  1915. details = player1score .. " : " .. player2score,
  1916. startTimestamp = startTime,
  1917. largeImageKey = "pongnew",
  1918. largeImageText = "Nuclear Pong",
  1919. }
  1920. if (gameState == "1serve") then
  1921. updateTEXT = ""
  1922. if (gameMode ~= "practice") then
  1923. if isAndroid then
  1924. TEXT = "PLAYER 1, serve!(double-click)"
  1925. else
  1926. TEXT = "PLAYER 1, serve!(q)"
  1927. end
  1928. end
  1929. if ((globalState ~= "clienttest" and love.keyboard.isDown("q")) or (globalState == "clienttest" and lastSentKeyP1 == "q") or doubleclick1) then
  1930. TEXT = "Lets Begin!"
  1931. doubleclick1 = false
  1932. ball_DIR = 1
  1933. if maxBalls == 1 then
  1934. ball[1]:reset(1, 1)
  1935. else
  1936. for i = 1, maxBalls do
  1937. ball[i]:reset(i)
  1938. end
  1939. end
  1940. gameState = "play"
  1941. end
  1942. end
  1943. if (gameState == "2serve") then
  1944. if (gameMode ~= "practice") then
  1945. if isAndroid then
  1946. TEXT = "PLAYER 2, serve!(double-click)"
  1947. else
  1948. TEXT = "PLAYER 2, serve!(p)"
  1949. end
  1950. end
  1951. if (AGAINST_AI == 1) then
  1952. TEXT = ""
  1953. doubleclick2 = false
  1954. ball_DIR = -1
  1955. if maxBalls == 1 then
  1956. ball[2]:reset(i, 2)
  1957. else
  1958. for i = 1, maxBalls do
  1959. ball[i]:reset(i)
  1960. end
  1961. end
  1962. gameState = "play"
  1963. end
  1964. if (((globalState == "nettest" and lastSentKeyClient == "p") or ((globalState ~= "nettest") and love.keyboard.isDown("p")) or doubleclick2)and AGAINST_AI == 0) then
  1965. TEXT = "Lets Begin"
  1966. doubleclick2 = false
  1967. ball_DIR = -1
  1968. if maxBalls == 1 then
  1969. ball[1]:reset(1, 2)
  1970. else
  1971. for i = 1, maxBalls do
  1972. ball[i]:reset(i)
  1973. end
  1974. end
  1975. --love.window.setTitle("An atttttttt")
  1976. gameState = "play"
  1977. end
  1978. end
  1979. end
  1980. function mapChanger()
  1981. if (gameState == "editor") then
  1982. MAP_TYPE = 2
  1983. end
  1984. if (MAP_TYPE > 2) then
  1985. MAP_TYPE = 0
  1986. end
  1987. end
  1988. function resolutionChanger()
  1989. if (RESOLUTION_SET > 1) then
  1990. RESOLUTION_SET = 0
  1991. end
  1992. if (RESOLUTION_SET == 0) then
  1993. if (isFullscreen == 1) then
  1994. DIFFERENCE_X = 1
  1995. DIFFERENCE_Y = 1
  1996. OFFSET_X = 0
  1997. OFFSET_Y = 0
  1998. simpleScale.updateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, {fullscreen = false})
  1999. isFullscreen = 0
  2000. end
  2001. end
  2002. if (RESOLUTION_SET == 1) then
  2003. if (isFullscreen == 0) then
  2004. simpleScale.updateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, {fullscreen = true})
  2005. local newWidth = love.graphics.getWidth()
  2006. local newHeight = love.graphics.getHeight()
  2007. DIFFERENCE_X = VIRTUAL_WIDTH / newWidth
  2008. DIFFERENCE_Y = VIRTUAL_HEIGHT / newHeight
  2009. OFFSET_X = math.fmod(newWidth, VIRTUAL_WIDTH) / 2
  2010. OFFSET_Y = math.fmod(newHeight, VIRTUAL_HEIGHT) / 2
  2011. isFullscreen = 1
  2012. end
  2013. end
  2014. end
  2015. function resettinggenius()
  2016. maxBalls = 1
  2017. freePlay = false
  2018. for i = 1, maxBalls do
  2019. ball[i]:reset(i)
  2020. end
  2021. paddle_SPEED = 200
  2022. nuclearanimation = 3
  2023. timeIsSlow = false
  2024. timeIsSlow2 = false
  2025. serverinit = false
  2026. ts = 0
  2027. originalSpeed = 200
  2028. gameState = "menu"
  2029. ball[1].dx = 1
  2030. ball_DIR = 1
  2031. ball[1].dy = 1
  2032. globalState = "menu"
  2033. gameMode = "normal"
  2034. player1.height = 100
  2035. player2.height = 100
  2036. ballSet = 200
  2037. ballSpeed = ballSet
  2038. background_scroll_speed = ballSpeed / 20
  2039. player2.GREEN = 255
  2040. player2.BLUE = 255
  2041. player1.GREEN = 255
  2042. player1.BLUE = 255
  2043. player1score = 0
  2044. player2score = 0
  2045. potentialnuke1 = 0
  2046. potentialnuke2 = 0
  2047. striken = 0
  2048. areanuclear = 0
  2049. potentialstrike1 = 0
  2050. potentialstrike2 = 0
  2051. player1nukescore = 0
  2052. player2nukescore = 0
  2053. player1reverbav = 0
  2054. player2reverbav = 0
  2055. selecting = 0
  2056. AGAINST_AI = 0
  2057. end
  2058. function love.mousereleased(x, y, button)
  2059. love.keyboard.mouseisReleased = true
  2060. if (gameState == "editor") then
  2061. if (#walls < 1000 and button == 1 and blockinput ~= true) then
  2062. table.insert(walls, newWall((x ) * DIFFERENCE_Y , (y ) * DIFFERENCE_Y , 10, wall1width))
  2063. end
  2064. end
  2065. end
  2066. function ballsAlive()
  2067. for i = 1, maxBalls do
  2068. if ball[i].disabled == false then
  2069. --print("Ball " .. i .. " is not disabled")
  2070. return true
  2071. end
  2072. end
  2073. return false
  2074. end
  2075. function split(s, delimiter)
  2076. result = {}
  2077. for match in (s..delimiter):gmatch("(.-)"..delimiter) do
  2078. table.insert(result, match)
  2079. end
  2080. return result
  2081. end
  2082. address, port = IP, 12345
  2083. function checkCurrentServer(dt)
  2084. if GetIPType(IP) ~= 1 then
  2085. status = "offline"
  2086. end
  2087. if GetIPType(IP) == 1 then
  2088. if dserverinit == false then
  2089. --print("Switching IP")
  2090. socket = require "socket"
  2091. address, port = IP, 12345
  2092. --print(address)
  2093. udp = socket.udp()
  2094. udp:setpeername(address, port)
  2095. udp:settimeout(0)
  2096. dserverinit = true
  2097. end
  2098. if IP ~= address then dserverinit = false--print(IP .. " doesnt equal " .. address)
  2099. else
  2100. ts = ts + dt
  2101. --print(ts)
  2102. if ts > checkrate then
  2103. status = "offline"
  2104. --print("sent ping")
  2105. udp:send("HELLO")
  2106. local data
  2107. data = udp:receive()
  2108. if data then
  2109. --print("got answer!")
  2110. local p = split(data, '|')
  2111. status = p[1]
  2112. print("answer is " .. status)
  2113. else
  2114. print("no response!")
  2115. end
  2116. ts = 0
  2117. end
  2118. end
  2119. end
  2120. end
  2121. local gts = 0
  2122. hostinit = false
  2123. player1ip = "127.0.0.1"
  2124. player1port = "12345"
  2125. player2ip = "none"
  2126. player2port = nil
  2127. local p1ping = 0
  2128. local p2ping = 0
  2129. local requesterip
  2130. local requresterport
  2131. function selfHost(dt)
  2132. --print("Server running")
  2133. if not hostinit then
  2134. local socket = require('socket')
  2135. udp = socket.udp()
  2136. udp:setsockname('*', 12345)
  2137. udp:settimeout(0)
  2138. local s = socket.udp()
  2139. s:setpeername("74.125.115.104",80)
  2140. myip, _ = s:getsockname()
  2141. hostinit = true
  2142. else
  2143. gts = gts + dt
  2144. if gts > 0.015 then
  2145. local data, msg_or_ip, port_or_nil
  2146. local p1data, p2data
  2147. if table.empty(touches) then
  2148. lastSentKey = "g"
  2149. end
  2150. repeat
  2151. data, msg_or_ip, port_or_nil = udp:receivefrom()
  2152. if data then
  2153. if data == "HELLO" then
  2154. --print("getting pinged")
  2155. requesterip = msg_or_ip
  2156. requesterport = port_or_nil
  2157. else
  2158. --print(string.sub(data,1,1) .. "Playerlist: " .. player1ip .. " " .. player2ip)
  2159. if player2ip == msg_or_ip then
  2160. p2data = data .. '|' .. p2ping
  2161. p2ping = 0
  2162. else
  2163. if player2ip == "none" and msg_or_ip ~= player1ip then
  2164. player2ip = msg_or_ip
  2165. p2data = data .. '|' .. p2ping
  2166. p2ping = 0
  2167. player2port = port_or_nil
  2168. --print("CONNECTED: PLAYER 2 FROM: " .. player2ip)
  2169. elseif (player1ip ~= msg_or_ip and player2ip ~= msg_or_ip) then
  2170. --print("Lobby Full!" .. player1ip .. player2ip)
  2171. end
  2172. end
  2173. end
  2174. end
  2175. until not data
  2176. if player1ip ~= "none" then
  2177. p1ping = p1ping + 1
  2178. end
  2179. if player2ip == "none" then
  2180. confirmation = "S"
  2181. else
  2182. --print("Player2: " .. player2ip)
  2183. p2ping = p2ping + 1
  2184. if p2ping > 100 then
  2185. for i = 1, maxBalls do
  2186. ts = ts + dt
  2187. if ts > updaterate then
  2188. udp:sendto(tostring(lastSentKey) ..
  2189. '|' .. tostring(ball[1].dy) ..
  2190. '|' .. tostring(player2.y) ..
  2191. '|' .. tostring(player1.y) ..
  2192. '|' .. tostring(player1score) ..
  2193. '|' .. tostring(player2score) ..
  2194. '|' .. tostring(player1nukescore) ..
  2195. '|' .. tostring(player2nukescore) ..
  2196. '|' .. tostring(ball[1].x) ..
  2197. '|' .. tostring(ball[1].y) ..
  2198. '|' .. gameState ..
  2199. '|' .. tostring(ball[1].dx) ..
  2200. '|' .. tostring(ballSpeed) ..
  2201. '|' .. tostring(paddle_SPEED) ..
  2202. '|' .. tostring(player1striken) ..
  2203. '|' .. tostring(areanuclear) ..
  2204. "|HOST|".. p2ping, player2ip, player2port)
  2205. ts = 0
  2206. end
  2207. end
  2208. --print("PLAYER 2 DISCONNECTED")
  2209. p2data = nil
  2210. player2ip = "none"
  2211. player2port = nil
  2212. end
  2213. end
  2214. if player2port then
  2215. for i = 1, maxBalls do
  2216. ts = ts + dt
  2217. if ts > updaterate then
  2218. udp:sendto(tostring(lastSentKey) ..
  2219. '|' .. tostring(ball[1].dy) ..
  2220. '|' .. tostring(player2.y) ..
  2221. '|' .. tostring(player1.y) ..
  2222. '|' .. tostring(player1score) ..
  2223. '|' .. tostring(player2score) ..
  2224. '|' .. tostring(player1nukescore) ..
  2225. '|' .. tostring(player2nukescore) ..
  2226. '|' .. tostring(ball[1].x) ..
  2227. '|' .. tostring(ball[1].y) ..
  2228. '|' .. gameState ..
  2229. '|' .. tostring(ball[1].dx) ..
  2230. '|' .. tostring(ballSpeed) ..
  2231. '|' .. tostring(paddle_SPEED) ..
  2232. '|' .. tostring(player1striken) ..
  2233. '|' .. tostring(areanuclear) ..
  2234. "|HOST|".. p2ping, player2ip, player2port)
  2235. ts = 0
  2236. end
  2237. end
  2238. --print("SENT TO " .. player2ip .. ":" .. player2port .. " : " ..lastSentKey)
  2239. end
  2240. local datanumtest = 0
  2241. local datawaspassed = false
  2242. if p2data and player1port then
  2243. datawaspassed = true
  2244. --print("ReceivedINFO: " .. p2data)
  2245. confirmation = "N"
  2246. local p = split(p2data, '|')
  2247. if p[17] then
  2248. if tonumber(p[18]) > 90 then
  2249. confirmation = "L"
  2250. end
  2251. if p[17] ~= "CLIENT" then
  2252. confirmation = "U"
  2253. end
  2254. elseif p[1] == "RESPONSE" then
  2255. if p[2] == "1" then
  2256. elseif p[2] == "2" then
  2257. elseif p[2] == "3" then
  2258. end
  2259. else
  2260. confirmation = "U"
  2261. end
  2262. if p[17] then
  2263. if ball[1].disabled and ball[1].x > 20 and ball[1].x < VIRTUAL_WIDTH - 20 then
  2264. ball[1].disabled = false
  2265. --print("illegal disabling")
  2266. end
  2267. if gameState ~= "1serve" then
  2268. if (ball[1].x > VIRTUAL_WIDTH/2) then
  2269. if tonumber(p[9]) > VIRTUAL_WIDTH/2 then
  2270. die = tonumber(p[2])
  2271. lastSentKeyClient,
  2272. ball[1].dy,
  2273. player2.y,
  2274. player1score,
  2275. player2score,
  2276. player1nukescore,
  2277. player2nukescore,
  2278. ball[1].x,
  2279. ball[1].y,
  2280. gameState,
  2281. ball[1].dx,
  2282. ballSpeed,
  2283. paddle_SPEED, player2striken,
  2284. areanuclear = 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]), tonumber(p[15]), tonumber(p[16])
  2285. --print("ACCEPTED")
  2286. else
  2287. --print("DECLINED")
  2288. end
  2289. else
  2290. if tonumber(p[9]) > VIRTUAL_WIDTH/2 then
  2291. die = tonumber(p[2])
  2292. lastSentKeyClient,
  2293. ball[1].dy,
  2294. player2.y,
  2295. player1score,
  2296. player2score,
  2297. player1nukescore,
  2298. player2nukescore,
  2299. ball[1].x,
  2300. ball[1].y,
  2301. gameState,
  2302. ball[1].dx,
  2303. ballSpeed,
  2304. paddle_SPEED, player2striken,
  2305. areanuclear = 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]), tonumber(p[15]), tonumber(p[16])
  2306. --print("ACCEPTED")
  2307. else
  2308. --print("ENFORCED" .. ball[1].x .. " " .. ball[1].dx)
  2309. lastSentKeyClient = p[1]
  2310. player2.y = tonumber(p[4])
  2311. player2striken = tonumber(p[15])
  2312. end
  2313. end
  2314. end
  2315. end
  2316. --print("SENT TO " .. player1ip .. ":" .. player1port .. " : " .. string.sub(p2data,1,1))
  2317. --print("1::" .. p1data)
  2318. --print("2::" .. p2data)
  2319. --print("SENT1: " .. player2ip .. " " .. player2port .. " " .. p1data)
  2320. --print("SENT2: " .. player1ip .. " " .. player1port .. " " .. p2data)
  2321. end
  2322. if requesterip then
  2323. --print("getting pnged!")
  2324. if player2ip == "none" then
  2325. udp:sendto("clienttest", requesterip, requesterport)
  2326. --print("clienttest av to: " .. requesterip)
  2327. else
  2328. udp:sendto("full", requesterip, requesterport)
  2329. --print("full to: " .. msg_or_ip)
  2330. end
  2331. requesterip, requesterport = nil
  2332. end
  2333. gts = 0
  2334. end
  2335. end
  2336. end
  2337. local lastclick = 0
  2338. local clickInterval = 0.4
  2339. function love.touchpressed( id, x, y, dx, dy, pressure )
  2340. if isAndroid then
  2341. if x < love.graphics.getWidth()-OFFSET_X/2 then
  2342. actualX = (x - OFFSET_X/2) * DIFFERENCE_Y
  2343. else
  2344. actualX = 1380
  2345. end
  2346. local existsingID = touchExists(id)
  2347. if existsingID ~= -1 then
  2348. touches[existsingID].x = actualX
  2349. touches[existsingID].y = (y) * DIFFERENCE_Y
  2350. else
  2351. table.insert(touches, newTouch(id, actualX , (y) * DIFFERENCE_Y))
  2352. local time = love.timer.getTime()
  2353. if actualX < VIRTUAL_WIDTH/2 then
  2354. if time <= lastclick + clickInterval and actualX> 100 then
  2355. doubleclick1 = true
  2356. if gameState == "1serve" then
  2357. lastSentKey = "q"
  2358. else
  2359. lastSentKey = p1control.super
  2360. end
  2361. else
  2362. doubleclick1 = false
  2363. lastclick = time
  2364. end
  2365. else
  2366. if time <= lastclick + clickInterval and actualX < VIRTUAL_WIDTH-100 then
  2367. doubleclick2 = true
  2368. if gameState == "2serve" then
  2369. lastSentKey = "p"
  2370. else
  2371. lastSentKey = p2control.super
  2372. end
  2373. else
  2374. doubleclick2 = false
  2375. lastclick = time
  2376. end
  2377. end
  2378. end
  2379. end
  2380. end
  2381. function love.touchreleased( id, x, y, dx, dy, pressure )
  2382. if isAndroid then
  2383. if gameState == "start" then
  2384. resettinggenius()
  2385. gameState = "menu"
  2386. ball[1].dx = 1
  2387. ball_DIR = 1
  2388. ball[1].dy = 1
  2389. globalState = "menu"
  2390. hardmanager()
  2391. end
  2392. local existsingID = touchExists(id)
  2393. if existsingID ~= -1 then
  2394. table.remove(touches, existsingID)
  2395. end
  2396. end
  2397. end
  2398. function love.touchmoved( id, x, y, dx, dy, pressure )
  2399. if isAndroid then
  2400. if x < love.graphics.getWidth()-OFFSET_X/2 then
  2401. actualX = (x - OFFSET_X/2) * DIFFERENCE_Y
  2402. else
  2403. actualX = 1380
  2404. end
  2405. local existsingID = touchExists(id)
  2406. if existsingID ~= -1 then
  2407. touches[existsingID].x = actualX
  2408. touches[existsingID].y = (y ) * DIFFERENCE_Y
  2409. if touches[existsingID].originalX - touches[existsingID].x > 200 and
  2410. touches[existsingID].originalX < VIRTUAL_WIDTH/2 then
  2411. hold1 = true
  2412. lastSentKey = p1control.counter
  2413. else
  2414. hold1 = false
  2415. end
  2416. if touches[existsingID].x - touches[existsingID].originalX > 200 and
  2417. touches[existsingID].originalX > VIRTUAL_WIDTH/2 then
  2418. hold2 = true
  2419. lastSentKey = p2control.counter
  2420. else
  2421. hold2 = false
  2422. end
  2423. end
  2424. end
  2425. end
  2426. function touchExists(ID)
  2427. for i, touch in ipairs(touches) do
  2428. if touch.id == ID then
  2429. return i
  2430. end
  2431. end
  2432. return -1
  2433. end
  2434. function table.empty (self)
  2435. for _, _ in pairs(self) do
  2436. return false
  2437. end
  2438. return true
  2439. end
  2440. function sectortouched(sector)
  2441. for i, touch in ipairs(touches) do
  2442. if (AGAINST_AI == 1) then
  2443. if sector == 2 and touch.x < 100 and touch.y < player1.y then
  2444. lastSentKey = p1control.up
  2445. return true
  2446. elseif sector == 2 and touch.x > VIRTUAL_WIDTH/2+10 and touch.y < player1.y then
  2447. lastSentKey = p1control.up
  2448. return true
  2449. elseif sector == 3 and touch.x < 100 and touch.y > player1.y+player1.height*0.9 then
  2450. lastSentKey = p1control.down
  2451. return true
  2452. elseif sector == 3 and touch.x > VIRTUAL_WIDTH/2+10 and touch.y > player1.y+player1.height*0.9 then
  2453. lastSentKey = p1control.down
  2454. return true
  2455. end
  2456. else
  2457. if sector == 1 and touch.x > VIRTUAL_WIDTH-100 and touch.y < player2.y then
  2458. lastSentKey = p2control.up
  2459. return true
  2460. elseif sector == 2 and touch.x < 100 and touch.y < player1.y then
  2461. lastSentKey = p1control.up
  2462. return true
  2463. elseif sector == 3 and touch.x < 100 and touch.y > player1.y+player1.height*0.9 then
  2464. lastSentKey = p1control.down
  2465. return true
  2466. elseif sector == 4 and touch.x > VIRTUAL_WIDTH-100 and touch.y > player2.y+player1.height*0.9 then
  2467. lastSentKey = p2control.down
  2468. return true
  2469. end
  2470. end
  2471. end
  2472. return false
  2473. end
  2474. function showMessage()
  2475. --print (globalMessage)
  2476. if globalMessage ~= "none" then
  2477. love.graphics.printf("Low CPU mode active", 0, VIRTUAL_WIDTH/2, VIRTUAL_HEIGHT/2, "center")
  2478. end
  2479. end
  2480. function resetButtonX(arr)
  2481. for i, buttons in ipairs(arr) do
  2482. buttons.x = 1300
  2483. end
  2484. end
  2485. function discordRPC.joinRequest(userId, username, discriminator, avatar)
  2486. print(string.format("Discord: join request (%s, %s, %s, %s)", userId, username, discriminator, avatar))
  2487. discordRPC.respond(userId, "yes")
  2488. end
  2489. function discordRPC.joinGame(joinSecret)
  2490. print(string.format("Discord: join (%s)", joinSecret))
  2491. end