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.

2445 lines
70 KiB

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