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.

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