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.

2502 lines
71 KiB

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