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.

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