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.

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