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.

2506 lines
71 KiB

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