A pong clone, but with a twist!
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.

2375 line
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. ["beep"] = love.audio.newSource("audio/hit1.mp3", "static"),
  814. ["wallhit"] = love.audio.newSource("audio/hit2.wav", "static"),
  815. ["win"] = love.audio.newSource("win.wav", "static"),
  816. ["score"] = love.audio.newSource("audio/score.wav", "static"),
  817. ["nuke"] = love.audio.newSource("audio/bomb.wav", "static"),
  818. ["striking"] = love.audio.newSource("audio/superhit.wav", "static"),
  819. ["nuclearhit"] = love.audio.newSource("audio/hit1.mp3", "static"),
  820. ["time"] = love.audio.newSource("audio/time.wav", "static")
  821. }
  822. love.graphics.setDefaultFilter("nearest", "nearest")
  823. --comic sans lmao
  824. math.randomseed(os.time())
  825. smallfont = love.graphics.newFont("font.ttf", 25)
  826. scorefont = love.graphics.newFont("font.ttf", 60)
  827. love.graphics.setFont(smallfont)
  828. --push:setupScreen(VIRTUAL_WIDTH, VIRTUAL_HEIGHT, WINDOW_WIDTH, WINDOW_HEIGHT, {
  829. -- fullscreen = isFullscreen,
  830. -- resizable = true,
  831. -- vsync = true,
  832. --})
  833. player1score = 0
  834. player2score = 0
  835. areanuclear = 0
  836. player1nukescore = 0
  837. player2nukescore = 0
  838. striken = 0
  839. soundtype = 1
  840. soundturn = 1
  841. potentialstrike1 = 0
  842. potentialstrike2 = 0
  843. potentialnuke1 = 0
  844. potentialnuke2 = 0
  845. player1striken = 0
  846. player2striken = 0
  847. randomtext = 0
  848. selecting = 0
  849. number = 0
  850. elec = 1
  851. INDIC = {
  852. "",
  853. "",
  854. "",
  855. ""
  856. }
  857. --playe1nuke
  858. player1 = paddle(0, 30, 10, 100, 1)
  859. player2 = paddle(VIRTUAL_WIDTH * 0.99, VIRTUAL_HEIGHT * 0.88, 10, 100, 2)
  860. player3 = paddle(5000, 5000, 10, 100)
  861. player4 = paddle(5000, 5000, 10, 100)
  862. ball = {}
  863. ball[1] = eball(VIRTUAL_WIDTH / 2, VIRTUAL_HEIGHT / 2 - 2, 16, 16)
  864. ball[2] = eball(VIRTUAL_WIDTH / 1.9, VIRTUAL_HEIGHT / 2 - 2, 16, 16)
  865. ball[3] = eball(VIRTUAL_WIDTH / 1.8, VIRTUAL_HEIGHT / 2 - 2, 16, 16)
  866. ball[4] = eball(VIRTUAL_WIDTH / 2.2, VIRTUAL_HEIGHT / 2 - 2, 16, 16)
  867. ball[5] = eball(VIRTUAL_WIDTH / 2.1, VIRTUAL_HEIGHT / 2 - 2, 16, 16)
  868. myscreen = fullScreener(RESOLUTION_SET, isFullscreen, DIFFERENCE_X, DIFFERENCE_Y, OFFSET_X, OFFSET_Y)
  869. if isAndroid then
  870. myscreen:toggle(VIRTUAL_HEIGHT, VIRTUAL_WIDTH)
  871. DIFFERENCE_X = myscreen.c
  872. DIFFERENCE_Y = myscreen.d
  873. OFFSET_X = myscreen.e
  874. OFFSET_Y = myscreen.f
  875. end
  876. mymenu = mainMenu()
  877. ballSpeed = 200
  878. ballDX = math.random(2) == 1 and 100 or -100
  879. ballDY = math.random(-50, 50)
  880. gameState = "animation"
  881. end
  882. t = 0
  883. shakeDuration = 0
  884. shakeMagnitude = 1
  885. function startShake(duration, magnitude)
  886. t, shakeDuration, shakeMagnitude = 0, duration or 1, magnitude or 5
  887. end
  888. function displayFPS()
  889. --love.window.setTitle(love.timer.getFPS())
  890. --love.window.setTitle(globalState .. " " .. gameState .. " " .. paddle_SPEED .. " " .. p1bonus .. " " .. player1.dy)
  891. if love.keyboard.isDown("space") then
  892. player1nukescore = 200
  893. player1score = player1score + 0.2
  894. player2nukescore = 200
  895. end
  896. end
  897. function speedControl()
  898. if (ballSpeed > maxspeed and gameState == "play") then
  899. ballSpeed = maxspeed
  900. end
  901. end
  902. function love.update(dt)
  903. --print("IMPORTANT!!!!!" .. globalState .. gameState)
  904. staticanimatorcounter(dt)
  905. player1.goal = -1
  906. player2.goal = -1
  907. if gameState == "chooseIP" then
  908. checkCurrentServer(dt)
  909. end
  910. if debug then
  911. displayFPS()
  912. print(player2.y .. " " .. player2.goal .. " " .. player2.dy .. " " .. AI_SPEED .. " " .. paddle_SPEED .. " " .. lastSentKeyClient)
  913. end
  914. if globalState == "base" and not paused then
  915. basegame(dt)
  916. end
  917. if globalState == "menu" then
  918. debugCheck(dt)
  919. if gameState ~= "animation" then
  920. menuDemo(dt)
  921. end
  922. end
  923. if gameState ~= "animation" then
  924. musicController('norm', 1)
  925. end
  926. if globalState == "nettest" then
  927. --print("Confcode: " .. confirmation)
  928. if confirmation == "N" then
  929. basegame(dt)
  930. end
  931. nettest(dt)
  932. end
  933. if globalState == "selfhost" then
  934. --print("Confcode: " .. confirmation)
  935. if confirmation == "N" then
  936. globalState = "nettest"
  937. basegame(dt)
  938. end
  939. globalState = "selfhost"
  940. selfHost(dt)
  941. IP = "127.0.0.1"
  942. end
  943. if globalState == "clienttest" then
  944. ts = ts + dt
  945. if confirmation == "N" then
  946. lastSentKeyP1 = lastSentKeyClient
  947. clientsBaseGame(dt)
  948. end
  949. clienttest(dt)
  950. end
  951. end
  952. serverinit = false
  953. dserverinit = false
  954. datawaspassedtimer = 0
  955. clientinit = false
  956. function love.textinput(t)
  957. if gameState == "chooseIP" then
  958. IPnew = IPnew .. t
  959. end
  960. end
  961. function nettest(dt)
  962. --print("nettest running")
  963. if serverinit == false then
  964. local socket = require "socket"
  965. local address, port = IP, 12345
  966. --print(address)
  967. udp = socket.udp()
  968. udp:setpeername(address, port)
  969. udp:settimeout(0)
  970. serverinit = true
  971. end
  972. if isAndroid then
  973. if table.empty(touches) then
  974. lastSentKey = "g"
  975. end
  976. end
  977. for i = 1, maxBalls do
  978. ts = ts + dt
  979. if ts > updaterate then
  980. udp:send(tostring(lastSentKey) ..
  981. '|' .. tostring(ball[1].dy) ..
  982. '|' .. tostring(player2.y) ..
  983. '|' .. tostring(player1.y) ..
  984. '|' .. tostring(player1score) ..
  985. '|' .. tostring(player2score) ..
  986. '|' .. tostring(player1nukescore) ..
  987. '|' .. tostring(player2nukescore) ..
  988. '|' .. tostring(ball[1].x) ..
  989. '|' .. tostring(ball[1].y) ..
  990. '|' .. gameState ..
  991. '|' .. tostring(ball[1].dx) ..
  992. '|' .. tostring(ballSpeed) ..
  993. '|' .. tostring(paddle_SPEED) ..
  994. '|' .. tostring(player1striken) ..
  995. '|' .. tostring(areanuclear) ..
  996. "|HOST")
  997. ts = 0
  998. end
  999. end
  1000. local data
  1001. local datanumtest = 0
  1002. local datawaspassed = false
  1003. repeat
  1004. datanumtest = datanumtest + 1
  1005. --print("LATENCY: " .. tostring(datanumtest))
  1006. data = udp:receive()
  1007. if data then
  1008. datawaspassed = true
  1009. --print("ReceivedINFO: " .. data)
  1010. confirmation = "N"
  1011. local p = split(data, '|')
  1012. if p[17] then
  1013. if tonumber(p[18]) > 90 then
  1014. confirmation = "L"
  1015. end
  1016. if p[17] ~= "CLIENT" then
  1017. confirmation = "U"
  1018. end
  1019. elseif p[1] == "RESPONSE" then
  1020. if p[2] == "1" then
  1021. elseif p[2] == "2" then
  1022. elseif p[2] == "3" then
  1023. end
  1024. else
  1025. confirmation = "U"
  1026. end
  1027. if p[17] then
  1028. if ball[1].disabled and ball[1].x > 20 and ball[1].x < VIRTUAL_WIDTH - 20 then
  1029. ball[1].disabled = false
  1030. --print("illegal disabling")
  1031. end
  1032. if gameState ~= "1serve" then
  1033. if (ball[1].x > VIRTUAL_WIDTH/2) then
  1034. if tonumber(p[9]) > VIRTUAL_WIDTH/2 then
  1035. die = tonumber(p[2])
  1036. lastSentKeyClient,
  1037. ball[1].dy,
  1038. player2.y,
  1039. player1score,
  1040. player2score,
  1041. player1nukescore,
  1042. player2nukescore,
  1043. ball[1].x,
  1044. ball[1].y,
  1045. gameState,
  1046. ball[1].dx,
  1047. ballSpeed,
  1048. paddle_SPEED,
  1049. player2striken,
  1050. 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])
  1051. --print("ACCEPTED")
  1052. else
  1053. --print("DECLINED")
  1054. end
  1055. else
  1056. if tonumber(p[9]) > VIRTUAL_WIDTH/2 then
  1057. die = tonumber(p[2])
  1058. lastSentKeyClient,
  1059. ball[1].dy,
  1060. player2.y,
  1061. player1score,
  1062. player2score,
  1063. player1nukescore,
  1064. player2nukescore,
  1065. ball[1].x,
  1066. ball[1].y,
  1067. gameState,
  1068. ball[1].dx,
  1069. ballSpeed,
  1070. paddle_SPEED, player2striken,
  1071. 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])
  1072. --print("ACCEPTED")
  1073. else
  1074. --print("ENFORCED" .. ball[1].x .. " " .. ball[1].dx)
  1075. lastSentKeyClient = p[1]
  1076. player2striken = tonumber(p[15])
  1077. player2.y = tonumber(p[4])
  1078. end
  1079. end
  1080. end
  1081. end
  1082. end
  1083. until not data
  1084. if not datawaspassed then
  1085. datawaspassedtimer = datawaspassedtimer + 1
  1086. if datawaspassedtimer > 15 then
  1087. confirmation = "D"
  1088. datawaspassedtimer = 0
  1089. end
  1090. else
  1091. datawaspassedtimer = 0
  1092. end
  1093. end
  1094. function clienttest(dt)
  1095. if clientinit == false then
  1096. local socket = require "socket"
  1097. local address, port = IP, 12345
  1098. udp = socket.udp()
  1099. udp:setpeername(address, port)
  1100. udp:settimeout(0)
  1101. clientinit = true
  1102. end
  1103. if isAndroid then
  1104. if table.empty(touches) then
  1105. lastSentKey = "g"
  1106. end
  1107. end
  1108. ts = ts + dt
  1109. if ts > updaterate then
  1110. udp:send(tostring(lastSentKey) ..
  1111. '|' .. tostring(ball[1].dy) ..
  1112. '|' .. tostring(player1.y) ..
  1113. '|' .. tostring(player2.y) ..
  1114. '|' .. tostring(player1score) ..
  1115. '|' .. tostring(player2score) ..
  1116. '|' .. tostring(player1nukescore) ..
  1117. '|' .. tostring(player2nukescore) ..
  1118. '|' .. tostring(ball[1].x) ..
  1119. '|' .. tostring(ball[1].y) ..
  1120. '|' .. gameState ..
  1121. '|' .. tostring(ball[1].dx) ..
  1122. '|' .. tostring(ballSpeed) ..
  1123. '|' .. tostring(paddle_SPEED) ..
  1124. '|' .. tostring(player2striken) ..
  1125. '|' .. tostring(areanuclear) ..
  1126. "|CLIENT")
  1127. ts = 0
  1128. end
  1129. local data
  1130. local datanumtest = 0
  1131. local datawaspassed = false
  1132. repeat
  1133. datanumtest = datanumtest + 1
  1134. --print("LATENCY: " .. tostring(datanumtest))
  1135. data = udp:receive()
  1136. if data then
  1137. --print("RECEIVED DATA: " .. data)
  1138. datawaspassed = true
  1139. --print("SENT TO SERVER:" .. lastSentKey)
  1140. confirmation = "N"
  1141. local p = split(data, '|')
  1142. if p[17] then
  1143. if p[17] ~= "HOST" then
  1144. confirmation = "U"
  1145. end
  1146. if tonumber(p[18]) > 90 then
  1147. confirmation = "L"
  1148. end
  1149. for i = 1, maxBalls do
  1150. local die = tonumber(p[2])
  1151. if (ball[i].x <= VIRTUAL_WIDTH/2) then
  1152. if tonumber(p[9]) <= VIRTUAL_WIDTH/2 then
  1153. 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])
  1154. --print("ACCEPTED")
  1155. else
  1156. --print("DECLINED")
  1157. end
  1158. else
  1159. if tonumber(p[9]) <= VIRTUAL_WIDTH/2 then
  1160. 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])
  1161. --print("REROUTED")
  1162. else lastSentKeyClient = p[1]
  1163. player1.y = tonumber(p[4])
  1164. player1striken = tonumber(p[15])
  1165. --print("ENFORCED")
  1166. end
  1167. end
  1168. end
  1169. else
  1170. confirmation = "U"
  1171. end
  1172. end
  1173. --print("GOT: " .. lastSentKeyClient)
  1174. until not data
  1175. if not datawaspassed then
  1176. datawaspassedtimer = datawaspassedtimer + 1
  1177. if datawaspassedtimer > 15 then
  1178. confirmation = "D"
  1179. datawaspassedtimer = 0
  1180. end
  1181. else
  1182. datawaspassedtimer = 0
  1183. end
  1184. end
  1185. function wallbreaker(x, y)
  1186. if (gameState == "editor") then
  1187. for i, wall in ipairs(walls) do
  1188. if math.abs(wall.wallx - x) < 10 and math.abs(wall.wally - y) < 10 then
  1189. table.remove(walls, i)
  1190. end
  1191. end
  1192. end
  1193. end
  1194. function hardmanager(diff)
  1195. selecting = 1
  1196. if (diff == "easy") then
  1197. INDIC[1] = ">"
  1198. AGAINST_AI = 1
  1199. AI_SPEED = ballSet
  1200. AI_STRIKEMOD = 100
  1201. AI_NUKEMOD = 1000
  1202. AI_LEVEL = 350
  1203. difficultyl = 200
  1204. selecting = 0
  1205. gameState = "1serve"
  1206. globalState = "base"
  1207. end
  1208. if (diff == "normal") then
  1209. INDIC[2] = ">"
  1210. AI_SPEED = ballSet
  1211. AI_LEVEL = 500
  1212. AI_NUKEMOD = 250
  1213. AI_STRIKEMOD = 60
  1214. AGAINST_AI = 1
  1215. difficultyl = 300
  1216. selecting = 0
  1217. gameState = "1serve"
  1218. globalState = "base"
  1219. end
  1220. if (diff == "hard") then
  1221. INDIC[3] = ">"
  1222. AI_SPEED = ballSpeed * 1.1 + 50
  1223. AI_LEVEL = 700
  1224. AI_NUKEMOD = 200
  1225. AI_STRIKEMOD = 20
  1226. selecting = 0
  1227. difficultyl = 350
  1228. AGAINST_AI = 1
  1229. gameState = "1serve"
  1230. globalState = "base"
  1231. end
  1232. if (diff == "smart") then
  1233. INDIC[3] = ">"
  1234. AI_SPEED = ballSpeed * 1.1 + 50
  1235. AI_LEVEL = 1500
  1236. AI_NUKEMOD = 200
  1237. AI_STRIKEMOD = 20
  1238. selecting = 0
  1239. difficultyl = 350
  1240. AGAINST_AI = 1
  1241. gameState = "1serve"
  1242. globalState = "base"
  1243. end
  1244. if (diff == "practice") then
  1245. INDIC[3] = ">"
  1246. AI_SPEED = ballSpeed * 500 + 50
  1247. AI_LEVEL = 700
  1248. AI_NUKEMOD = 9000000000
  1249. AI_STRIKEMOD = 90000000
  1250. selecting = 0
  1251. difficultyl = 350
  1252. AGAINST_AI = 1
  1253. gameState = "base"
  1254. end
  1255. end
  1256. function dangerChecker() --CHECK IF CONTROLS ARE DUPLICATING
  1257. if (p1control.up == p1control.down) then
  1258. danger = "1up"
  1259. danger2 = "1down"
  1260. elseif (p1control.up == p1control.super) then
  1261. danger = "1up"
  1262. danger2 = "1special"
  1263. elseif (p1control.up == p1control.counter) then
  1264. danger = "1up"
  1265. danger2 = "1ct"
  1266. elseif (p1control.down == p1control.super) then
  1267. danger = "1down"
  1268. danger2 = "1special"
  1269. elseif (p1control.down == p1control.counter) then
  1270. danger = "1ct"
  1271. danger2 = "1down"
  1272. elseif (p1control.super == p1control.counter) then
  1273. danger = "1special"
  1274. danger2 = "1ct"
  1275. elseif (p2control.down == p2control.up) then
  1276. danger = "2down"
  1277. danger2 = "2up"
  1278. elseif (p2control.down == p2control.super) then
  1279. danger = "2down"
  1280. danger2 = "2special"
  1281. elseif (p2control.down == p2control.counter) then
  1282. danger = "2down"
  1283. danger2 = "2ct"
  1284. elseif (p2control.up == p2control.super) then
  1285. danger = "2up"
  1286. danger2 = "2special"
  1287. elseif (p2control.up == p2control.counter) then
  1288. danger = "2ct"
  1289. danger2 = "2up"
  1290. elseif (p2control.super == p2control.counter) then
  1291. danger = "2special"
  1292. danger2 = "2ct"
  1293. else
  1294. danger = "none"
  1295. danger2 = "none"
  1296. end
  1297. end
  1298. function love.keypressed(key)
  1299. if not isAndroid then
  1300. lastSentKey = key
  1301. end
  1302. if gameState == "chooseIP" then
  1303. if key == "backspace" then
  1304. -- get the byte offset to the last UTF-8 character in the string.
  1305. local byteoffset = utf8.offset(IPnew, -1)
  1306. if byteoffset then
  1307. -- remove the last UTF-8 character.
  1308. -- string.sub operates on bytes rather than UTF-8 characters, so we couldn't do string.sub(text, 1, -2).
  1309. IPnew = string.sub(IPnew, 1, byteoffset - 1)
  1310. end
  1311. end
  1312. end
  1313. if gameState == "assign" then
  1314. if (req == "p1up") then
  1315. p1control.up = key
  1316. currentKey = key
  1317. --love.window.setTitle(key)
  1318. gameState = "controlSettings"
  1319. end
  1320. if (req == "p2up") then
  1321. p2control.up = key
  1322. currentKey = key
  1323. --love.window.setTitle(key)
  1324. gameState = "controlSettings"
  1325. end
  1326. if (req == "p1down") then
  1327. p1control.down = key
  1328. currentKey = key
  1329. --love.window.setTitle(key)
  1330. gameState = "controlSettings"
  1331. end
  1332. if (req == "p2down") then
  1333. p2control.down = key
  1334. currentKey = key
  1335. -- love.window.setTitle(key)
  1336. gameState = "controlSettings"
  1337. end
  1338. if (req == "p1super") then
  1339. p1control.super = key
  1340. currentKey = key
  1341. -- love.window.setTitle(key)
  1342. gameState = "controlSettings"
  1343. end
  1344. if (req == "p2super") then
  1345. p2control.super = key
  1346. currentKey = key
  1347. -- love.window.setTitle(key)
  1348. gameState = "controlSettings"
  1349. end
  1350. if (req == "p1ct") then
  1351. p1control.counter = key
  1352. currentKey = key
  1353. -- love.window.setTitle(key)
  1354. gameState = "controlSettings"
  1355. end
  1356. if (req == "p2ct") then
  1357. p2control.counter = key
  1358. currentKey = key
  1359. --love.window.setTitle(key)
  1360. gameState = "controlSettings"
  1361. end
  1362. end
  1363. if key == "escape" then
  1364. if not isAndroid and globalState == "base" and gameState ~= "done" then
  1365. if paused then
  1366. paused = false
  1367. TEXT = "Let's Continue"
  1368. else
  1369. paused = true
  1370. TEXT = "PAUSED"
  1371. end
  1372. end
  1373. elseif key == "enter" or key == "return" then
  1374. if gameState == "start" then
  1375. resettinggenius()
  1376. gameState = "menu"
  1377. ball[1].dx = 1
  1378. ball[1].dy = 1
  1379. globalState = "menu"
  1380. hardmanager()
  1381. elseif (gameState == "done") then
  1382. if (player1score > player2score) then
  1383. gameState = "2serve"
  1384. potentialnuke1 = 0
  1385. potentialnuke2 = 0
  1386. striken = 0
  1387. if (nuckemodactive == 0) then
  1388. areanuclear = 0
  1389. nuclearanimation = 3
  1390. end
  1391. potentialstrike1 = 0
  1392. potentialstrike2 = 0
  1393. player1nukescore = 0
  1394. player2nukescore = 0
  1395. else
  1396. gameState = "1serve"
  1397. resettinggenius()
  1398. for i = 1, maxBalls do
  1399. ball[i]:reset(i, 1)
  1400. end
  1401. end
  1402. else
  1403. gameState = "menu"
  1404. ball[1].dx = 1
  1405. ball[1].dy = 1
  1406. globalState = "menu"
  1407. if (love.math.random(0, 20) == 1) then
  1408. TEXT = "Nuclear Ching Chong"
  1409. else
  1410. TEXT = "Nuclear Pong"
  1411. end
  1412. resettinggenius()
  1413. for i = 1, maxBalls do
  1414. ball[i]:reset(i)
  1415. end
  1416. end
  1417. end
  1418. end
  1419. function love.keyreleased(key)
  1420. currentKey = " "
  1421. if lastSentKey == key and not isAndroid then
  1422. lastSentKey = "g"
  1423. end
  1424. end
  1425. function speedSetter(requesttype)
  1426. if (requesttype == "ball") then
  1427. if (ballSet > 550) then
  1428. ballSet = 0
  1429. paddle_SPEED = 0
  1430. else
  1431. ballSet = ballSet + 50
  1432. paddle_SPEED = paddle_SPEED + 5
  1433. end
  1434. ballSpeed = ballSet
  1435. end
  1436. if (requesttype == "snc") then
  1437. synctype = synctype + 1
  1438. if (synctype > 1) then
  1439. synctype = 0
  1440. end
  1441. if synctype == 0 then
  1442. synctext = "Independent"
  1443. end
  1444. if synctype == 1 then
  1445. synctext = "Synchronised"
  1446. end
  1447. end
  1448. if (requesttype == "nuclearmod") then
  1449. nuckemodactive = nuckemodactive + 1
  1450. if (nuckemodactive > 1) then
  1451. nuckemodactive = 0
  1452. end
  1453. if (nuckemodactive == 0) then
  1454. areanuclear = 0
  1455. nuclearanimation = 3
  1456. ballSet = 200
  1457. TEXT = "Nuclear Pong"
  1458. synctype = 0
  1459. maxspeed = 700
  1460. synctext = "Independent"
  1461. paddle_SPEED = ballSet
  1462. AI_SPEED = ballSet
  1463. end
  1464. if (nuckemodactive == 1) then
  1465. areanuclear = 1
  1466. ballSet = 2000
  1467. maxspeed = 2000
  1468. paddle_SPEED = ballSet
  1469. AI_SPEED = ballSet
  1470. synctext = "death is imminent"
  1471. end
  1472. ballSpeed = ballSet
  1473. end
  1474. if (requesttype == "practice") then
  1475. if (ballSpeed > 999) then
  1476. ballSpeed = 200
  1477. ballSet = 200
  1478. end
  1479. if (ballSpeed > 799) then
  1480. prtext = "Insane"
  1481. maxBalls = 5
  1482. elseif ballSpeed > 599 then
  1483. prtext = "Hard"
  1484. maxBalls = 4
  1485. elseif ballSpeed > 399 then
  1486. prtext = "Normal"
  1487. maxBalls = 3
  1488. elseif ballSpeed > 199 then
  1489. prtext = "Easy"
  1490. maxBalls = 3
  1491. end
  1492. ballSpeed = ballSpeed + 200
  1493. ballSet = ballSet + 200
  1494. end
  1495. if (requesttype == "reset") then
  1496. ballSpeed = 200
  1497. ballSet = 200
  1498. synctype = 0
  1499. prtext = "Easy"
  1500. maxBalls = 1
  1501. end
  1502. if (requesttype == "pc") then
  1503. if (playerCount == 2) then
  1504. playerCount = 1
  1505. playertext = "1v1"
  1506. elseif (playerCount == 1) then
  1507. playerCount = playerCount + 1
  1508. player3.x = player1.x + VIRTUAL_WIDTH / 2
  1509. player3.y = player3.y
  1510. playertext = "2v2"
  1511. end
  1512. end
  1513. if (requesttype == "ballz") then
  1514. if (maxBalls > 1) then
  1515. --love.window.setTitle("more than 4")
  1516. maxBalls = 1
  1517. else
  1518. maxBalls = maxBalls + 1
  1519. end
  1520. end
  1521. if requesttype == "ptw" then
  1522. if ptw == 10 then
  1523. ptw = 1
  1524. else
  1525. ptw = ptw + 1
  1526. end
  1527. end
  1528. end
  1529. function gameModeChanger()
  1530. if (gameState == "gameMode") then
  1531. local button_width = VIRTUAL_WIDTH * (1 / 3)
  1532. local BUTTON_HEIGHT = 50
  1533. local margin = 20
  1534. local hot = false
  1535. local cursor_y = 0
  1536. local total_height = (BUTTON_HEIGHT + margin) * #buttons
  1537. for i, button in ipairs(modeSelectorButtons) do
  1538. button.last = button.now
  1539. local bx = (VIRTUAL_WIDTH * 0.5) - (button_width * 0.5)
  1540. local by = (VIRTUAL_HEIGHT * 0.5) - (total_height * 0.5) + cursor_y
  1541. local color = {255, 255, 255, 255}
  1542. local mx, my = love.mouse.getPosition()
  1543. mx = mx
  1544. my = my
  1545. mx = mx * DIFFERENCE_X
  1546. my = my * DIFFERENCE_Y
  1547. hot = (mx > bx and mx < bx + button_width and my > by and my < by + BUTTON_HEIGHT) and i
  1548. if (hot == i) then
  1549. color = {10, 10, 0, 255}
  1550. end
  1551. button.now = love.mouse.isDown(1)
  1552. if button.now and not button.last and hot == i then
  1553. love.graphics.setColor(0, 0, 0, 1)
  1554. love.graphics.rectangle("fill", 0, 0, VIRTUAL_WIDTH, VIRTUAL_HEIGHT)
  1555. sounds["wallhit"]:play()
  1556. button.fn()
  1557. end
  1558. love.graphics.setColor(unpack(color))
  1559. love.graphics.rectangle("fill", bx, by, button_width, BUTTON_HEIGHT)
  1560. love.graphics.setColor(0, 0, 0, 255)
  1561. local textW = smallfont:getWidth(button.text)
  1562. local textH = smallfont:getHeight(button.text)
  1563. love.graphics.print(button.text, smallfont, VIRTUAL_WIDTH * 0.5 - textW * 0.5, by + textH * 0.5)
  1564. love.graphics.setColor(255, 255, 255, 255)
  1565. cursor_y = cursor_y + (BUTTON_HEIGHT + margin)
  1566. end
  1567. end
  1568. if (gameState == "multiMode") then
  1569. local button_width = VIRTUAL_WIDTH * (1 / 3)
  1570. local BUTTON_HEIGHT = 50
  1571. local margin = 20
  1572. local hot = false
  1573. local cursor_y = 0
  1574. local total_height = (BUTTON_HEIGHT + margin) * #buttons
  1575. for i, button in ipairs(playerCountButtons) do
  1576. button.last = button.now
  1577. local bx = (VIRTUAL_WIDTH * 0.5) - (button_width * 0.5)
  1578. local by = (VIRTUAL_HEIGHT * 0.3) - (total_height * 0.5) + cursor_y
  1579. if (button.text == "Play") then
  1580. by = by + by / 1.8
  1581. end
  1582. local color = {255, 255, 255, 255}
  1583. local mx, my = love.mouse.getPosition()
  1584. mx = mx
  1585. my = my
  1586. mx = mx * DIFFERENCE_X
  1587. my = my * DIFFERENCE_Y
  1588. hot = (mx > bx and mx < bx + button_width and my > by and my < by + BUTTON_HEIGHT) and i
  1589. if (hot == i) then
  1590. if (button.text == "Play") then
  1591. color = {0 / 255, 255 / 255, 0 / 255, 255}
  1592. else
  1593. color = {10, 10, 0, 255}
  1594. end
  1595. end
  1596. button.now = love.mouse.isDown(1)
  1597. if button.now and not button.last and hot == i then
  1598. love.graphics.setColor(0, 0, 0, 1)
  1599. love.graphics.rectangle("fill", 0, 0, VIRTUAL_WIDTH, VIRTUAL_HEIGHT)
  1600. sounds["wallhit"]:play()
  1601. if button.text == "Ball Speed: " and nuckemodactive == 1 then
  1602. else
  1603. button.fn()
  1604. end
  1605. end
  1606. love.graphics.setColor(unpack(color))
  1607. love.graphics.rectangle("fill", bx, by, button_width, BUTTON_HEIGHT)
  1608. love.graphics.setColor(0, 0, 0, 255)
  1609. local textW = smallfont:getWidth(button.text)
  1610. local textH = smallfont:getHeight(button.text)
  1611. if (button.text == "1v1") then
  1612. love.graphics.print(playertext, smallfont, VIRTUAL_WIDTH * 0.5 - textW * 0.5, by + textH * 0.5)
  1613. elseif button.text == "snc" then
  1614. if (nuckemodactive == 1) then
  1615. love.graphics.setColor(1, 0, 0, 1)
  1616. love.graphics.print(synctext, smallfont, VIRTUAL_WIDTH * 0.5 - textW * 0.5, by + textH * 0.5)
  1617. love.graphics.setColor(1, 1, 1, 1)
  1618. love.graphics.print(synctext, smallfont, VIRTUAL_WIDTH * 0.5 - textW * 0.5, by + textH * 0.5)
  1619. love.graphics.setColor(0, 0, 0, 1)
  1620. else
  1621. --
  1622. love.graphics.print(synctext, smallfont, VIRTUAL_WIDTH * 0.45 - textW * 0.5, by + textH * 0.5)
  1623. end
  1624. elseif (button.text == "ballCount") then
  1625. love.graphics.print(
  1626. "Ball Count: " .. maxBalls,
  1627. smallfont,
  1628. VIRTUAL_WIDTH * 0.5 - textW * 0.5,
  1629. by + textH * 0.5
  1630. )
  1631. elseif (button.text == "Ball Speed: ") then
  1632. if (nuckemodactive == 1) then
  1633. love.graphics.setColor(1, 0, 0, 1)
  1634. love.graphics.print(
  1635. "shaitan machina",
  1636. smallfont,
  1637. VIRTUAL_WIDTH * 0.5 - textW * 0.5,
  1638. by + textH * 0.5
  1639. )
  1640. love.graphics.setColor(1, 1, 1, 1)
  1641. love.graphics.print(
  1642. "shaitan machina",
  1643. smallfont,
  1644. VIRTUAL_WIDTH * 0.5 - textW * 0.5,
  1645. by + textH * 0.5
  1646. )
  1647. love.graphics.setColor(0, 0, 0, 1)
  1648. else
  1649. love.graphics.print(
  1650. button.text .. ballSet,
  1651. smallfont,
  1652. VIRTUAL_WIDTH * 0.5 - textW * 0.5,
  1653. by + textH * 0.5
  1654. )
  1655. end
  1656. elseif button.text == "ptw" then
  1657. love.graphics.print(
  1658. "Points to Win: " .. ptw,
  1659. smallfont,
  1660. VIRTUAL_WIDTH * 0.5 - textW * 1.5,
  1661. by + textH * 0.5
  1662. )
  1663. else
  1664. love.graphics.print(button.text, smallfont, VIRTUAL_WIDTH * 0.5 - textW * 0.5, by + textH * 0.5)
  1665. end
  1666. love.graphics.setColor(255, 255, 255, 255)
  1667. cursor_y = cursor_y + (BUTTON_HEIGHT + margin)
  1668. end
  1669. end
  1670. end
  1671. function love.draw(dt)
  1672. simpleScale.set()
  1673. if globalState == "selfhost" then
  1674. globalState = "nettest"
  1675. baseDraw()
  1676. globalState = "selfhost"
  1677. else
  1678. baseDraw()
  1679. end
  1680. if (globalState == "nettest" or globalState == "clienttest" or globalState == "selfhost") and confirmation == "D" then
  1681. love.graphics.clear(50 / 255, 50 / 255, 50 / 255, 255)
  1682. love.graphics.printf("WAIT FOR OPPONENT", 0, VIRTUAL_HEIGHT / 2, VIRTUAL_WIDTH, "center")
  1683. end
  1684. if (globalState == "nettest" or globalState == "clienttest" or globalState == "selfhost") and confirmation == "U" then
  1685. love.graphics.clear(50 / 255, 50 / 255, 50 / 255, 255)
  1686. love.graphics.printf("LOBBY FULL OR WRONG MODE CHOSEN", 0, VIRTUAL_HEIGHT / 2, VIRTUAL_WIDTH, "center")
  1687. end
  1688. if (globalState == "nettest" or globalState == "clienttest" or globalState == "selfhost") and confirmation == "L" then
  1689. love.graphics.clear(50 / 255, 50 / 255, 50 / 255, 255)
  1690. love.graphics.printf("POOR CONNECTION TO SERVER", 0, VIRTUAL_HEIGHT / 2, VIRTUAL_WIDTH, "center")
  1691. end
  1692. if (globalState == "nettest" or globalState == "clienttest" or globalState == "selfhost") and confirmation == "S" then
  1693. love.graphics.clear(50 / 255, 50 / 255, 50 / 255, 255)
  1694. love.graphics.printf("INTERNAL SERVER WAITING", 0, VIRTUAL_HEIGHT / 2, VIRTUAL_WIDTH, "center")
  1695. love.graphics.printf(myip, 0, VIRTUAL_HEIGHT / 2 + 120, VIRTUAL_WIDTH, "center")
  1696. end
  1697. if isAndroid then
  1698. androidDraw()
  1699. love.keyboard.mouseisReleased = false
  1700. end
  1701. if debug then
  1702. if touches then
  1703. for i, touch in ipairs(touches) do
  1704. love.graphics.printf(touch.x, 0, VIRTUAL_HEIGHT / 2, VIRTUAL_WIDTH, "center")
  1705. end
  1706. if doubleclick1 then
  1707. TEXT = "DOUBLECLICK1"
  1708. elseif doubleclick2 then TEXT = "DOUBLECLICK2"
  1709. else TEXT = "NO"
  1710. end
  1711. end
  1712. end
  1713. simpleScale.unSet()
  1714. end
  1715. --Check if controls are duplicating
  1716. function controllerSer()
  1717. for i = 1, maxBalls do
  1718. if (ball[i].dy == 0) then
  1719. hitNum[i] = hitNum[i] + 1
  1720. if hitNum[i] >= 10 then
  1721. ball[i].dy = 1
  1722. hitNum[i] = 0
  1723. end
  1724. else
  1725. hitNum[i] = 0
  1726. end
  1727. end
  1728. end
  1729. function palleteController() --!!!!LEGACY CODE, MIGRATED TO Paddle.lua!!!!
  1730. if (areanuclear == 0) then
  1731. player1.RED = 1
  1732. player1.GREEN = 1
  1733. player1.BLUE = 1
  1734. end
  1735. if (areanuclear == 0) then
  1736. player2.RED = 1
  1737. player2.GREEN = 1
  1738. player2.BLUE = 1
  1739. end
  1740. if (areanuclear == 1) then
  1741. player1.RED = 0
  1742. player1.GREEN = 0
  1743. player1.BLUE = 0
  1744. end
  1745. if (areanuclear == 1) then
  1746. player2.RED = 0
  1747. player2.GREEN = 0
  1748. player2.BLUE = 0
  1749. end
  1750. end
  1751. function love.wheelmoved(x, y)
  1752. if (y < 0 and wall1width > 0) then
  1753. wall1width = wall1width - 5
  1754. elseif y > 0 and wall1width < 900 then
  1755. wall1width = wall1width + 5
  1756. end
  1757. end
  1758. function serveBot() --THIS IS USED TO CHANGE TEXT/BALL DIRECTION ON DIFFERENT SERVES
  1759. --print("servebot called")
  1760. if (gameState == "1serve") then
  1761. updateTEXT = ""
  1762. if (gameMode ~= "practice") then
  1763. if isAndroid then
  1764. TEXT = "PLAYER 1, serve!(double-click)"
  1765. else
  1766. TEXT = "PLAYER 1, serve!(q)"
  1767. end
  1768. end
  1769. if ((globalState ~= "clienttest" and love.keyboard.isDown("q")) or (globalState == "clienttest" and lastSentKeyP1 == "q") or doubleclick1) then
  1770. TEXT = "Lets Begin!"
  1771. doubleclick1 = false
  1772. ball_DIR = 1
  1773. if maxBalls == 1 then
  1774. ball[1]:reset(1, 1)
  1775. else
  1776. for i = 1, maxBalls do
  1777. ball[i]:reset(i)
  1778. end
  1779. end
  1780. gameState = "play"
  1781. end
  1782. end
  1783. if (gameState == "2serve") then
  1784. if (gameMode ~= "practice") then
  1785. if isAndroid then
  1786. TEXT = "PLAYER 2, serve!(double-click)"
  1787. else
  1788. TEXT = "PLAYER 2, serve!(p)"
  1789. end
  1790. end
  1791. if (AGAINST_AI == 1) then
  1792. TEXT = ""
  1793. doubleclick2 = false
  1794. ball_DIR = -1
  1795. if maxBalls == 1 then
  1796. ball[2]:reset(i, 2)
  1797. else
  1798. for i = 1, maxBalls do
  1799. ball[i]:reset(i)
  1800. end
  1801. end
  1802. gameState = "play"
  1803. end
  1804. if (((globalState == "nettest" and lastSentKeyClient == "p") or ((globalState ~= "nettest") and love.keyboard.isDown("p")) or doubleclick2)and AGAINST_AI == 0) then
  1805. TEXT = "Lets Begin"
  1806. doubleclick2 = false
  1807. ball_DIR = -1
  1808. if maxBalls == 1 then
  1809. ball[1]:reset(1, 2)
  1810. else
  1811. for i = 1, maxBalls do
  1812. ball[i]:reset(i)
  1813. end
  1814. end
  1815. --love.window.setTitle("An atttttttt")
  1816. gameState = "play"
  1817. end
  1818. end
  1819. end
  1820. function mapChanger()
  1821. if (gameState == "editor") then
  1822. MAP_TYPE = 2
  1823. end
  1824. if (MAP_TYPE > 2) then
  1825. MAP_TYPE = 0
  1826. end
  1827. end
  1828. function resolutionChanger()
  1829. if (RESOLUTION_SET > 1) then
  1830. RESOLUTION_SET = 0
  1831. end
  1832. if (RESOLUTION_SET == 0) then
  1833. if (isFullscreen == 1) then
  1834. DIFFERENCE_X = 1
  1835. DIFFERENCE_Y = 1
  1836. OFFSET_X = 0
  1837. OFFSET_Y = 0
  1838. simpleScale.updateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, {fullscreen = false})
  1839. isFullscreen = 0
  1840. end
  1841. end
  1842. if (RESOLUTION_SET == 1) then
  1843. if (isFullscreen == 0) then
  1844. simpleScale.updateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, {fullscreen = true})
  1845. local newWidth = love.graphics.getWidth()
  1846. local newHeight = love.graphics.getHeight()
  1847. DIFFERENCE_X = VIRTUAL_WIDTH / newWidth
  1848. DIFFERENCE_Y = VIRTUAL_HEIGHT / newHeight
  1849. OFFSET_X = math.fmod(newWidth, VIRTUAL_WIDTH) / 2
  1850. OFFSET_Y = math.fmod(newHeight, VIRTUAL_HEIGHT) / 2
  1851. isFullscreen = 1
  1852. end
  1853. end
  1854. end
  1855. function resettinggenius()
  1856. maxBalls = 1
  1857. for i = 1, maxBalls do
  1858. ball[i]:reset(i)
  1859. end
  1860. paddle_SPEED = 200
  1861. nuclearanimation = 3
  1862. timeIsSlow = false
  1863. timeIsSlow2 = false
  1864. serverinit = false
  1865. ts = 0
  1866. originalSpeed = 200
  1867. gameState = "menu"
  1868. ball[1].dx = 1
  1869. ball_DIR = 1
  1870. ball[1].dy = 1
  1871. globalState = "menu"
  1872. gameMode = "normal"
  1873. player1.height = 100
  1874. player2.height = 100
  1875. ballSet = 200
  1876. ballSpeed = ballSet
  1877. player2.GREEN = 255
  1878. player2.BLUE = 255
  1879. player1.GREEN = 255
  1880. player1.BLUE = 255
  1881. player1score = 0
  1882. player2score = 0
  1883. potentialnuke1 = 0
  1884. potentialnuke2 = 0
  1885. striken = 0
  1886. areanuclear = 0
  1887. potentialstrike1 = 0
  1888. potentialstrike2 = 0
  1889. player1nukescore = 0
  1890. player2nukescore = 0
  1891. player1reverbav = 0
  1892. player2reverbav = 0
  1893. selecting = 0
  1894. AGAINST_AI = 0
  1895. end
  1896. function love.mousereleased(x, y, button)
  1897. love.keyboard.mouseisReleased = true
  1898. if (gameState == "editor") then
  1899. if (#walls < 1000 and button == 1 and blockinput ~= true) then
  1900. table.insert(walls, newWall((x ) * DIFFERENCE_Y , (y ) * DIFFERENCE_Y , 10, wall1width))
  1901. end
  1902. end
  1903. end
  1904. function ballsAlive()
  1905. for i = 1, maxBalls do
  1906. if ball[i].disabled == false then
  1907. --print("Ball " .. i .. " is not disabled")
  1908. return true
  1909. end
  1910. end
  1911. return false
  1912. end
  1913. function split(s, delimiter)
  1914. result = {}
  1915. for match in (s..delimiter):gmatch("(.-)"..delimiter) do
  1916. table.insert(result, match)
  1917. end
  1918. return result
  1919. end
  1920. address, port = IP, 12345
  1921. function checkCurrentServer(dt)
  1922. if GetIPType(IP) ~= 1 then
  1923. status = "offline"
  1924. end
  1925. if GetIPType(IP) == 1 then
  1926. if dserverinit == false then
  1927. --print("Switching IP")
  1928. socket = require "socket"
  1929. address, port = IP, 12345
  1930. --print(address)
  1931. udp = socket.udp()
  1932. udp:setpeername(address, port)
  1933. udp:settimeout(0)
  1934. dserverinit = true
  1935. end
  1936. if IP ~= address then dserverinit = false--print(IP .. " doesnt equal " .. address)
  1937. else
  1938. ts = ts + dt
  1939. --print(ts)
  1940. if ts > checkrate then
  1941. status = "offline"
  1942. --print("sent ping")
  1943. udp:send("HELLO")
  1944. local data
  1945. data = udp:receive()
  1946. if data then
  1947. --print("got answer!")
  1948. local p = split(data, '|')
  1949. status = p[1]
  1950. print("answer is " .. status)
  1951. else
  1952. print("no response!")
  1953. end
  1954. ts = 0
  1955. end
  1956. end
  1957. end
  1958. end
  1959. local gts = 0
  1960. hostinit = false
  1961. player1ip = "127.0.0.1"
  1962. player1port = "12345"
  1963. player2ip = "none"
  1964. player2port = nil
  1965. local p1ping = 0
  1966. local p2ping = 0
  1967. local requesterip
  1968. local requresterport
  1969. function selfHost(dt)
  1970. --print("Server running")
  1971. if not hostinit then
  1972. local socket = require('socket')
  1973. udp = socket.udp()
  1974. udp:setsockname('*', 12345)
  1975. udp:settimeout(0)
  1976. local s = socket.udp()
  1977. s:setpeername("74.125.115.104",80)
  1978. myip, _ = s:getsockname()
  1979. hostinit = true
  1980. else
  1981. gts = gts + dt
  1982. if gts > 0.015 then
  1983. local data, msg_or_ip, port_or_nil
  1984. local p1data, p2data
  1985. if table.empty(touches) then
  1986. lastSentKey = "g"
  1987. end
  1988. repeat
  1989. data, msg_or_ip, port_or_nil = udp:receivefrom()
  1990. if data then
  1991. if data == "HELLO" then
  1992. --print("getting pinged")
  1993. requesterip = msg_or_ip
  1994. requesterport = port_or_nil
  1995. else
  1996. --print(string.sub(data,1,1) .. "Playerlist: " .. player1ip .. " " .. player2ip)
  1997. if player2ip == msg_or_ip then
  1998. p2data = data .. '|' .. p2ping
  1999. p2ping = 0
  2000. else
  2001. if player2ip == "none" and msg_or_ip ~= player1ip then
  2002. player2ip = msg_or_ip
  2003. p2data = data .. '|' .. p2ping
  2004. p2ping = 0
  2005. player2port = port_or_nil
  2006. --print("CONNECTED: PLAYER 2 FROM: " .. player2ip)
  2007. elseif (player1ip ~= msg_or_ip and player2ip ~= msg_or_ip) then
  2008. --print("Lobby Full!" .. player1ip .. player2ip)
  2009. end
  2010. end
  2011. end
  2012. end
  2013. until not data
  2014. if player1ip ~= "none" then
  2015. p1ping = p1ping + 1
  2016. end
  2017. if player2ip == "none" then
  2018. confirmation = "S"
  2019. else
  2020. --print("Player2: " .. player2ip)
  2021. p2ping = p2ping + 1
  2022. if p2ping > 100 then
  2023. for i = 1, maxBalls do
  2024. ts = ts + dt
  2025. if ts > updaterate then
  2026. udp:sendto(tostring(lastSentKey) ..
  2027. '|' .. tostring(ball[1].dy) ..
  2028. '|' .. tostring(player2.y) ..
  2029. '|' .. tostring(player1.y) ..
  2030. '|' .. tostring(player1score) ..
  2031. '|' .. tostring(player2score) ..
  2032. '|' .. tostring(player1nukescore) ..
  2033. '|' .. tostring(player2nukescore) ..
  2034. '|' .. tostring(ball[1].x) ..
  2035. '|' .. tostring(ball[1].y) ..
  2036. '|' .. gameState ..
  2037. '|' .. tostring(ball[1].dx) ..
  2038. '|' .. tostring(ballSpeed) ..
  2039. '|' .. tostring(paddle_SPEED) ..
  2040. '|' .. tostring(player1striken) ..
  2041. '|' .. tostring(areanuclear) ..
  2042. "|HOST|".. p2ping, player2ip, player2port)
  2043. ts = 0
  2044. end
  2045. end
  2046. --print("PLAYER 2 DISCONNECTED")
  2047. p2data = nil
  2048. player2ip = "none"
  2049. player2port = nil
  2050. end
  2051. end
  2052. if player2port then
  2053. for i = 1, maxBalls do
  2054. ts = ts + dt
  2055. if ts > updaterate then
  2056. udp:sendto(tostring(lastSentKey) ..
  2057. '|' .. tostring(ball[1].dy) ..
  2058. '|' .. tostring(player2.y) ..
  2059. '|' .. tostring(player1.y) ..
  2060. '|' .. tostring(player1score) ..
  2061. '|' .. tostring(player2score) ..
  2062. '|' .. tostring(player1nukescore) ..
  2063. '|' .. tostring(player2nukescore) ..
  2064. '|' .. tostring(ball[1].x) ..
  2065. '|' .. tostring(ball[1].y) ..
  2066. '|' .. gameState ..
  2067. '|' .. tostring(ball[1].dx) ..
  2068. '|' .. tostring(ballSpeed) ..
  2069. '|' .. tostring(paddle_SPEED) ..
  2070. '|' .. tostring(player1striken) ..
  2071. '|' .. tostring(areanuclear) ..
  2072. "|HOST|".. p2ping, player2ip, player2port)
  2073. ts = 0
  2074. end
  2075. end
  2076. --print("SENT TO " .. player2ip .. ":" .. player2port .. " : " ..lastSentKey)
  2077. end
  2078. local datanumtest = 0
  2079. local datawaspassed = false
  2080. if p2data and player1port then
  2081. datawaspassed = true
  2082. --print("ReceivedINFO: " .. p2data)
  2083. confirmation = "N"
  2084. local p = split(p2data, '|')
  2085. if p[17] then
  2086. if tonumber(p[18]) > 90 then
  2087. confirmation = "L"
  2088. end
  2089. if p[17] ~= "CLIENT" then
  2090. confirmation = "U"
  2091. end
  2092. elseif p[1] == "RESPONSE" then
  2093. if p[2] == "1" then
  2094. elseif p[2] == "2" then
  2095. elseif p[2] == "3" then
  2096. end
  2097. else
  2098. confirmation = "U"
  2099. end
  2100. if p[17] then
  2101. if ball[1].disabled and ball[1].x > 20 and ball[1].x < VIRTUAL_WIDTH - 20 then
  2102. ball[1].disabled = false
  2103. --print("illegal disabling")
  2104. end
  2105. if gameState ~= "1serve" then
  2106. if (ball[1].x > VIRTUAL_WIDTH/2) then
  2107. if tonumber(p[9]) > VIRTUAL_WIDTH/2 then
  2108. die = tonumber(p[2])
  2109. lastSentKeyClient,
  2110. ball[1].dy,
  2111. player2.y,
  2112. player1score,
  2113. player2score,
  2114. player1nukescore,
  2115. player2nukescore,
  2116. ball[1].x,
  2117. ball[1].y,
  2118. gameState,
  2119. ball[1].dx,
  2120. ballSpeed,
  2121. paddle_SPEED, player2striken,
  2122. 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])
  2123. --print("ACCEPTED")
  2124. else
  2125. --print("DECLINED")
  2126. end
  2127. else
  2128. if tonumber(p[9]) > VIRTUAL_WIDTH/2 then
  2129. die = tonumber(p[2])
  2130. lastSentKeyClient,
  2131. ball[1].dy,
  2132. player2.y,
  2133. player1score,
  2134. player2score,
  2135. player1nukescore,
  2136. player2nukescore,
  2137. ball[1].x,
  2138. ball[1].y,
  2139. gameState,
  2140. ball[1].dx,
  2141. ballSpeed,
  2142. paddle_SPEED, player2striken,
  2143. 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])
  2144. --print("ACCEPTED")
  2145. else
  2146. --print("ENFORCED" .. ball[1].x .. " " .. ball[1].dx)
  2147. lastSentKeyClient = p[1]
  2148. player2.y = tonumber(p[4])
  2149. player2striken = tonumber(p[15])
  2150. end
  2151. end
  2152. end
  2153. end
  2154. --print("SENT TO " .. player1ip .. ":" .. player1port .. " : " .. string.sub(p2data,1,1))
  2155. --print("1::" .. p1data)
  2156. --print("2::" .. p2data)
  2157. --print("SENT1: " .. player2ip .. " " .. player2port .. " " .. p1data)
  2158. --print("SENT2: " .. player1ip .. " " .. player1port .. " " .. p2data)
  2159. end
  2160. if requesterip then
  2161. --print("getting pnged!")
  2162. if player2ip == "none" then
  2163. udp:sendto("clienttest", requesterip, requesterport)
  2164. --print("clienttest av to: " .. requesterip)
  2165. else
  2166. udp:sendto("full", requesterip, requesterport)
  2167. --print("full to: " .. msg_or_ip)
  2168. end
  2169. requesterip, requesterport = nil
  2170. end
  2171. gts = 0
  2172. end
  2173. end
  2174. end
  2175. local lastclick = 0
  2176. local clickInterval = 0.4
  2177. function love.touchpressed( id, x, y, dx, dy, pressure )
  2178. if isAndroid then
  2179. if x < love.graphics.getWidth()-OFFSET_X/2 then
  2180. actualX = (x - OFFSET_X/2) * DIFFERENCE_Y
  2181. else
  2182. actualX = 1380
  2183. end
  2184. local existsingID = touchExists(id)
  2185. if existsingID ~= -1 then
  2186. touches[existsingID].x = actualX
  2187. touches[existsingID].y = (y) * DIFFERENCE_Y
  2188. else
  2189. table.insert(touches, newTouch(id, actualX , (y) * DIFFERENCE_Y))
  2190. local time = love.timer.getTime()
  2191. if actualX < VIRTUAL_WIDTH/2 then
  2192. if time <= lastclick + clickInterval and actualX> 100 then
  2193. doubleclick1 = true
  2194. if gameState == "1serve" then
  2195. lastSentKey = "q"
  2196. else
  2197. lastSentKey = p1control.super
  2198. end
  2199. else
  2200. doubleclick1 = false
  2201. lastclick = time
  2202. end
  2203. else
  2204. if time <= lastclick + clickInterval and actualX < VIRTUAL_WIDTH-100 then
  2205. doubleclick2 = true
  2206. if gameState == "2serve" then
  2207. lastSentKey = "p"
  2208. else
  2209. lastSentKey = p2control.super
  2210. end
  2211. else
  2212. doubleclick2 = false
  2213. lastclick = time
  2214. end
  2215. end
  2216. end
  2217. end
  2218. end
  2219. function love.touchreleased( id, x, y, dx, dy, pressure )
  2220. if isAndroid then
  2221. if gameState == "start" then
  2222. resettinggenius()
  2223. gameState = "menu"
  2224. ball[1].dx = 1
  2225. ball_DIR = 1
  2226. ball[1].dy = 1
  2227. globalState = "menu"
  2228. hardmanager()
  2229. end
  2230. local existsingID = touchExists(id)
  2231. if existsingID ~= -1 then
  2232. table.remove(touches, existsingID)
  2233. end
  2234. end
  2235. end
  2236. function love.touchmoved( id, x, y, dx, dy, pressure )
  2237. if isAndroid then
  2238. if x < love.graphics.getWidth()-OFFSET_X/2 then
  2239. actualX = (x - OFFSET_X/2) * DIFFERENCE_Y
  2240. else
  2241. actualX = 1380
  2242. end
  2243. local existsingID = touchExists(id)
  2244. if existsingID ~= -1 then
  2245. touches[existsingID].x = actualX
  2246. touches[existsingID].y = (y ) * DIFFERENCE_Y
  2247. if touches[existsingID].originalX - touches[existsingID].x > 200 and
  2248. touches[existsingID].originalX < VIRTUAL_WIDTH/2 then
  2249. hold1 = true
  2250. lastSentKey = p1control.counter
  2251. else
  2252. hold1 = false
  2253. end
  2254. if touches[existsingID].x - touches[existsingID].originalX > 200 and
  2255. touches[existsingID].originalX > VIRTUAL_WIDTH/2 then
  2256. hold2 = true
  2257. lastSentKey = p2control.counter
  2258. else
  2259. hold2 = false
  2260. end
  2261. end
  2262. end
  2263. end
  2264. function touchExists(ID)
  2265. for i, touch in ipairs(touches) do
  2266. if touch.id == ID then
  2267. return i
  2268. end
  2269. end
  2270. return -1
  2271. end
  2272. function table.empty (self)
  2273. for _, _ in pairs(self) do
  2274. return false
  2275. end
  2276. return true
  2277. end
  2278. function sectortouched(sector)
  2279. for i, touch in ipairs(touches) do
  2280. if (AGAINST_AI == 1) then
  2281. if sector == 2 and touch.x < 100 and touch.y < player1.y then
  2282. lastSentKey = p1control.up
  2283. return true
  2284. elseif sector == 2 and touch.x > VIRTUAL_WIDTH/2+10 and touch.y < player1.y then
  2285. lastSentKey = p1control.up
  2286. return true
  2287. elseif sector == 3 and touch.x < 100 and touch.y > player1.y+player1.height*0.9 then
  2288. lastSentKey = p1control.down
  2289. return true
  2290. elseif sector == 3 and touch.x > VIRTUAL_WIDTH/2+10 and touch.y > player1.y+player1.height*0.9 then
  2291. lastSentKey = p1control.down
  2292. return true
  2293. end
  2294. else
  2295. if sector == 1 and touch.x > VIRTUAL_WIDTH-100 and touch.y < player2.y then
  2296. lastSentKey = p2control.up
  2297. return true
  2298. elseif sector == 2 and touch.x < 100 and touch.y < player1.y then
  2299. lastSentKey = p1control.up
  2300. return true
  2301. elseif sector == 3 and touch.x < 100 and touch.y > player1.y+player1.height*0.9 then
  2302. lastSentKey = p1control.down
  2303. return true
  2304. elseif sector == 4 and touch.x > VIRTUAL_WIDTH-100 and touch.y > player2.y+player1.height*0.9 then
  2305. lastSentKey = p2control.down
  2306. return true
  2307. end
  2308. end
  2309. end
  2310. return false
  2311. end