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.

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