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.

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