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.

2522 rader
72 KiB

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