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.

2374 lines
68 KiB

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