Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

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