A pong clone, but with a twist!
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

2528 rader
72 KiB

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