Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

2429 Zeilen
70 KiB

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