A pong clone, but with a twist!
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

2161 linhas
62 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. for i = 1, maxBalls do
  856. ts = ts + dt
  857. if ts > updaterate then
  858. udp:send(tostring(lastSentKey) ..
  859. '|' .. tostring(ball[1].dy) ..
  860. '|' .. tostring(player2.y) ..
  861. '|' .. tostring(player1.y) ..
  862. '|' .. tostring(player1score) ..
  863. '|' .. tostring(player2score) ..
  864. '|' .. tostring(player1nukescore) ..
  865. '|' .. tostring(player2nukescore) ..
  866. '|' .. tostring(ball[1].x) ..
  867. '|' .. tostring(ball[1].y) ..
  868. '|' .. gameState ..
  869. '|' .. tostring(ball[1].dx) ..
  870. '|' .. tostring(ballSpeed) ..
  871. '|' .. tostring(paddle_SPEED) ..
  872. '|' .. tostring(player1striken) ..
  873. "|HOST")
  874. ts = 0
  875. end
  876. end
  877. local data
  878. local datanumtest = 0
  879. local datawaspassed = false
  880. repeat
  881. datanumtest = datanumtest + 1
  882. print("LATENCY: " .. tostring(datanumtest))
  883. data = udp:receive()
  884. if data then
  885. datawaspassed = true
  886. print("ReceivedINFO: " .. data)
  887. confirmation = "N"
  888. local p = split(data, '|')
  889. if p[16] then
  890. if tonumber(p[17]) > 90 then
  891. confirmation = "L"
  892. end
  893. if p[16] ~= "CLIENT" then
  894. confirmation = "U"
  895. end
  896. elseif p[1] == "RESPONSE" then
  897. if p[2] == "1" then
  898. elseif p[2] == "2" then
  899. elseif p[2] == "3" then
  900. end
  901. else
  902. confirmation = "U"
  903. end
  904. if p[16] then
  905. if ball[1].disabled and ball[1].x > 20 and ball[1].x < VIRTUAL_WIDTH - 20 then
  906. ball[1].disabled = false
  907. print("illegal disabling")
  908. end
  909. if gameState ~= "1serve" then
  910. if (ball[1].x > VIRTUAL_WIDTH/2) then
  911. if tonumber(p[9]) > VIRTUAL_WIDTH/2 then
  912. die = tonumber(p[2])
  913. lastSentKeyClient,
  914. ball[1].dy,
  915. player2.y,
  916. player1score,
  917. player2score,
  918. player1nukescore,
  919. player2nukescore,
  920. ball[1].x,
  921. ball[1].y,
  922. gameState,
  923. ball[1].dx,
  924. ballSpeed,
  925. paddle_SPEED,
  926. 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])
  927. print("ACCEPTED")
  928. else
  929. print("DECLINED")
  930. end
  931. else
  932. if tonumber(p[9]) > VIRTUAL_WIDTH/2 then
  933. die = tonumber(p[2])
  934. lastSentKeyClient,
  935. ball[1].dy,
  936. player2.y,
  937. player1score,
  938. player2score,
  939. player1nukescore,
  940. player2nukescore,
  941. ball[1].x,
  942. ball[1].y,
  943. gameState,
  944. ball[1].dx,
  945. ballSpeed,
  946. 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])
  947. print("ACCEPTED")
  948. else
  949. print("ENFORCED" .. ball[1].x .. " " .. ball[1].dx)
  950. lastSentKeyClient = p[1]
  951. player2striken = tonumber(p[15])
  952. player2.y = tonumber(p[4])
  953. end
  954. end
  955. end
  956. end
  957. end
  958. until not data
  959. if not datawaspassed then
  960. datawaspassedtimer = datawaspassedtimer + 1
  961. if datawaspassedtimer > 5 then
  962. confirmation = "D"
  963. datawaspassedtimer = 0
  964. end
  965. else
  966. datawaspassedtimer = 0
  967. end
  968. end
  969. function clienttest(dt)
  970. if clientinit == false then
  971. local socket = require "socket"
  972. local address, port = IP, 12345
  973. udp = socket.udp()
  974. udp:setpeername(address, port)
  975. udp:settimeout(0)
  976. clientinit = true
  977. end
  978. ts = ts + dt
  979. if ts > updaterate then
  980. udp:send(tostring(lastSentKey) ..
  981. '|' .. tostring(ball[1].dy) ..
  982. '|' .. tostring(player1.y) ..
  983. '|' .. tostring(player2.y) ..
  984. '|' .. tostring(player1score) ..
  985. '|' .. tostring(player2score) ..
  986. '|' .. tostring(player1nukescore) ..
  987. '|' .. tostring(player2nukescore) ..
  988. '|' .. tostring(ball[1].x) ..
  989. '|' .. tostring(ball[1].y) ..
  990. '|' .. gameState ..
  991. '|' .. tostring(ball[1].dx) ..
  992. '|' .. tostring(ballSpeed) ..
  993. '|' .. tostring(paddle_SPEED) ..
  994. '|' .. tostring(player2striken) ..
  995. "|CLIENT")
  996. ts = 0
  997. end
  998. local data
  999. local datanumtest = 0
  1000. local datawaspassed = false
  1001. repeat
  1002. datanumtest = datanumtest + 1
  1003. print("LATENCY: " .. tostring(datanumtest))
  1004. data = udp:receive()
  1005. if data then
  1006. print("RECEIVED DATA: " .. data)
  1007. datawaspassed = true
  1008. print("SENT TO SERVER:" .. lastSentKey)
  1009. confirmation = "N"
  1010. local p = split(data, '|')
  1011. if p[16] then
  1012. if p[16] ~= "HOST" then
  1013. confirmation = "U"
  1014. end
  1015. if tonumber(p[17]) > 90 then
  1016. confirmation = "L"
  1017. end
  1018. for i = 1, maxBalls do
  1019. local die = tonumber(p[2])
  1020. if (ball[i].x <= VIRTUAL_WIDTH/2) then
  1021. if tonumber(p[9]) <= VIRTUAL_WIDTH/2 then
  1022. 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])
  1023. print("ACCEPTED")
  1024. else
  1025. print("DECLINED")
  1026. end
  1027. else
  1028. if tonumber(p[9]) <= VIRTUAL_WIDTH/2 then
  1029. 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])
  1030. print("REROUTED")
  1031. else lastSentKeyClient = p[1]
  1032. player1.y = tonumber(p[4])
  1033. player1striken = tonumber(p[15])
  1034. print("ENFORCED")
  1035. end
  1036. end
  1037. end
  1038. else
  1039. confirmation = "U"
  1040. end
  1041. end
  1042. print("GOT: " .. lastSentKeyClient)
  1043. until not data
  1044. if not datawaspassed then
  1045. datawaspassedtimer = datawaspassedtimer + 1
  1046. if datawaspassedtimer > 5 then
  1047. confirmation = "D"
  1048. datawaspassedtimer = 0
  1049. end
  1050. else
  1051. datawaspassedtimer = 0
  1052. end
  1053. end
  1054. function wallbreaker(x, y)
  1055. if (gameState == "editor") then
  1056. for i, wall in ipairs(walls) do
  1057. if math.abs(wall.wallx - x) < 10 and math.abs(wall.wally - y) < 10 then
  1058. table.remove(walls, i)
  1059. end
  1060. end
  1061. end
  1062. end
  1063. function hardmanager(diff)
  1064. selecting = 1
  1065. if (diff == "easy") then
  1066. INDIC[1] = ">"
  1067. AGAINST_AI = 1
  1068. AI_SPEED = ballSet
  1069. AI_STRIKEMOD = 100
  1070. AI_NUKEMOD = 1000
  1071. AI_LEVEL = 350
  1072. difficultyl = 200
  1073. selecting = 0
  1074. gameState = "1serve"
  1075. globalState = "base"
  1076. end
  1077. if (diff == "normal") then
  1078. INDIC[2] = ">"
  1079. AI_SPEED = ballSet
  1080. AI_LEVEL = 500
  1081. AI_NUKEMOD = 250
  1082. AI_STRIKEMOD = 60
  1083. AGAINST_AI = 1
  1084. difficultyl = 300
  1085. selecting = 0
  1086. gameState = "1serve"
  1087. globalState = "base"
  1088. end
  1089. if (diff == "hard") then
  1090. INDIC[3] = ">"
  1091. AI_SPEED = ballSpeed * 1.1 + 50
  1092. AI_LEVEL = 700
  1093. AI_NUKEMOD = 200
  1094. AI_STRIKEMOD = 20
  1095. selecting = 0
  1096. difficultyl = 350
  1097. AGAINST_AI = 1
  1098. gameState = "1serve"
  1099. globalState = "base"
  1100. end
  1101. if (diff == "smart") then
  1102. INDIC[3] = ">"
  1103. AI_SPEED = ballSpeed * 1.1 + 50
  1104. AI_LEVEL = 1500
  1105. AI_NUKEMOD = 200
  1106. AI_STRIKEMOD = 20
  1107. selecting = 0
  1108. difficultyl = 350
  1109. AGAINST_AI = 1
  1110. gameState = "1serve"
  1111. globalState = "base"
  1112. end
  1113. if (diff == "practice") then
  1114. INDIC[3] = ">"
  1115. AI_SPEED = ballSpeed * 500 + 50
  1116. AI_LEVEL = 700
  1117. AI_NUKEMOD = 9000000000
  1118. AI_STRIKEMOD = 90000000
  1119. selecting = 0
  1120. difficultyl = 350
  1121. AGAINST_AI = 1
  1122. gameState = "base"
  1123. end
  1124. end
  1125. function dangerChecker() --CHECK IF CONTROLS ARE DUPLICATING
  1126. if (p1control.up == p1control.down) then
  1127. danger = "1up"
  1128. danger2 = "1down"
  1129. elseif (p1control.up == p1control.super) then
  1130. danger = "1up"
  1131. danger2 = "1special"
  1132. elseif (p1control.up == p1control.counter) then
  1133. danger = "1up"
  1134. danger2 = "1ct"
  1135. elseif (p1control.down == p1control.super) then
  1136. danger = "1down"
  1137. danger2 = "1special"
  1138. elseif (p1control.down == p1control.counter) then
  1139. danger = "1ct"
  1140. danger2 = "1down"
  1141. elseif (p1control.super == p1control.counter) then
  1142. danger = "1special"
  1143. danger2 = "1ct"
  1144. elseif (p2control.down == p2control.up) then
  1145. danger = "2down"
  1146. danger2 = "2up"
  1147. elseif (p2control.down == p2control.super) then
  1148. danger = "2down"
  1149. danger2 = "2special"
  1150. elseif (p2control.down == p2control.counter) then
  1151. danger = "2down"
  1152. danger2 = "2ct"
  1153. elseif (p2control.up == p2control.super) then
  1154. danger = "2up"
  1155. danger2 = "2special"
  1156. elseif (p2control.up == p2control.counter) then
  1157. danger = "2ct"
  1158. danger2 = "2up"
  1159. elseif (p2control.super == p2control.counter) then
  1160. danger = "2special"
  1161. danger2 = "2ct"
  1162. else
  1163. danger = "none"
  1164. danger2 = "none"
  1165. end
  1166. end
  1167. function love.keypressed(key)
  1168. if not isAndroid then
  1169. lastSentKey = key
  1170. end
  1171. if gameState == "chooseIP" then
  1172. if key == "backspace" then
  1173. -- get the byte offset to the last UTF-8 character in the string.
  1174. local byteoffset = utf8.offset(IPnew, -1)
  1175. if byteoffset then
  1176. -- remove the last UTF-8 character.
  1177. -- string.sub operates on bytes rather than UTF-8 characters, so we couldn't do string.sub(text, 1, -2).
  1178. IPnew = string.sub(IPnew, 1, byteoffset - 1)
  1179. end
  1180. end
  1181. end
  1182. if gameState == "assign" then
  1183. if (req == "p1up") then
  1184. p1control.up = key
  1185. currentKey = key
  1186. --love.window.setTitle(key)
  1187. gameState = "controlSettings"
  1188. end
  1189. if (req == "p2up") then
  1190. p2control.up = key
  1191. currentKey = key
  1192. --love.window.setTitle(key)
  1193. gameState = "controlSettings"
  1194. end
  1195. if (req == "p1down") then
  1196. p1control.down = key
  1197. currentKey = key
  1198. --love.window.setTitle(key)
  1199. gameState = "controlSettings"
  1200. end
  1201. if (req == "p2down") then
  1202. p2control.down = key
  1203. currentKey = key
  1204. -- love.window.setTitle(key)
  1205. gameState = "controlSettings"
  1206. end
  1207. if (req == "p1super") then
  1208. p1control.super = key
  1209. currentKey = key
  1210. -- love.window.setTitle(key)
  1211. gameState = "controlSettings"
  1212. end
  1213. if (req == "p2super") then
  1214. p2control.super = key
  1215. currentKey = key
  1216. -- love.window.setTitle(key)
  1217. gameState = "controlSettings"
  1218. end
  1219. if (req == "p1ct") then
  1220. p1control.counter = key
  1221. currentKey = key
  1222. -- love.window.setTitle(key)
  1223. gameState = "controlSettings"
  1224. end
  1225. if (req == "p2ct") then
  1226. p2control.counter = key
  1227. currentKey = key
  1228. --love.window.setTitle(key)
  1229. gameState = "controlSettings"
  1230. end
  1231. end
  1232. if key == "escape" then
  1233. if not isAndroid then
  1234. TEXT = "Escape Key"
  1235. love.event.quit()
  1236. end
  1237. elseif key == "enter" or key == "return" then
  1238. if gameState == "start" then
  1239. resettinggenius()
  1240. gameState = "menu"
  1241. globalState = "menu"
  1242. hardmanager()
  1243. elseif (gameState == "done") then
  1244. if (player1score > player2score) then
  1245. gameState = "2serve"
  1246. potentialnuke1 = 0
  1247. potentialnuke2 = 0
  1248. striken = 0
  1249. if (nuckemodactive == 0) then
  1250. areanuclear = 0
  1251. nuclearanimation = 3
  1252. end
  1253. potentialstrike1 = 0
  1254. potentialstrike2 = 0
  1255. player1nukescore = 0
  1256. player2nukescore = 0
  1257. else
  1258. gameState = "1serve"
  1259. resettinggenius()
  1260. for i = 1, maxBalls do
  1261. ball[i]:reset(i, 1)
  1262. end
  1263. end
  1264. else
  1265. gameState = "menu"
  1266. globalState = "menu"
  1267. if (love.math.random(0, 20) == 1) then
  1268. TEXT = "Nuclear Ching Chong"
  1269. else
  1270. TEXT = "Nuclear Pong"
  1271. end
  1272. resettinggenius()
  1273. for i = 1, maxBalls do
  1274. ball[i]:reset(i)
  1275. end
  1276. end
  1277. end
  1278. end
  1279. function love.keyreleased(key)
  1280. currentKey = " "
  1281. if lastSentKey == key and not isAndroid then
  1282. lastSentKey = "g"
  1283. end
  1284. end
  1285. function speedSetter(requesttype)
  1286. if (requesttype == "ball") then
  1287. if (ballSet > 550) then
  1288. ballSet = 0
  1289. paddle_SPEED = 0
  1290. else
  1291. ballSet = ballSet + 50
  1292. paddle_SPEED = paddle_SPEED + 5
  1293. end
  1294. ballSpeed = ballSet
  1295. end
  1296. if (requesttype == "snc") then
  1297. synctype = synctype + 1
  1298. if (synctype > 1) then
  1299. synctype = 0
  1300. end
  1301. if synctype == 0 then
  1302. synctext = "Independent"
  1303. end
  1304. if synctype == 1 then
  1305. synctext = "Synchronised"
  1306. end
  1307. end
  1308. if (requesttype == "nuclearmod") then
  1309. nuckemodactive = nuckemodactive + 1
  1310. if (nuckemodactive > 1) then
  1311. nuckemodactive = 0
  1312. end
  1313. if (nuckemodactive == 0) then
  1314. areanuclear = 0
  1315. nuclearanimation = 3
  1316. ballSet = 200
  1317. TEXT = "Nuclear Pong"
  1318. synctype = 0
  1319. maxspeed = 700
  1320. synctext = "Independent"
  1321. paddle_SPEED = ballSet
  1322. AI_SPEED = ballSet
  1323. end
  1324. if (nuckemodactive == 1) then
  1325. areanuclear = 1
  1326. ballSet = 2000
  1327. maxspeed = 2000
  1328. paddle_SPEED = ballSet
  1329. AI_SPEED = ballSet
  1330. synctext = "death is imminent"
  1331. end
  1332. ballSpeed = ballSet
  1333. end
  1334. if (requesttype == "practice") then
  1335. if (ballSpeed > 999) then
  1336. ballSpeed = 200
  1337. ballSet = 200
  1338. end
  1339. if (ballSpeed > 799) then
  1340. prtext = "Insane"
  1341. maxBalls = 5
  1342. elseif ballSpeed > 599 then
  1343. prtext = "Hard"
  1344. maxBalls = 4
  1345. elseif ballSpeed > 399 then
  1346. prtext = "Normal"
  1347. maxBalls = 3
  1348. elseif ballSpeed > 199 then
  1349. prtext = "Easy"
  1350. maxBalls = 3
  1351. end
  1352. ballSpeed = ballSpeed + 200
  1353. ballSet = ballSet + 200
  1354. end
  1355. if (requesttype == "reset") then
  1356. ballSpeed = 200
  1357. ballSet = 200
  1358. synctype = 0
  1359. prtext = "Easy"
  1360. maxBalls = 1
  1361. end
  1362. if (requesttype == "pc") then
  1363. if (playerCount == 2) then
  1364. playerCount = 1
  1365. playertext = "1v1"
  1366. elseif (playerCount == 1) then
  1367. playerCount = playerCount + 1
  1368. player3.x = player1.x + VIRTUAL_WIDTH / 2
  1369. player3.y = player3.y
  1370. playertext = "2v2"
  1371. end
  1372. end
  1373. if (requesttype == "ballz") then
  1374. if (maxBalls > 1) then
  1375. --love.window.setTitle("more than 4")
  1376. maxBalls = 1
  1377. else
  1378. maxBalls = maxBalls + 1
  1379. end
  1380. end
  1381. if requesttype == "ptw" then
  1382. if ptw == 10 then
  1383. ptw = 1
  1384. else
  1385. ptw = ptw + 1
  1386. end
  1387. end
  1388. end
  1389. function gameModeChanger()
  1390. if (gameState == "gameMode") then
  1391. local button_width = VIRTUAL_WIDTH * (1 / 3)
  1392. local BUTTON_HEIGHT = 50
  1393. local margin = 20
  1394. local hot = false
  1395. local cursor_y = 0
  1396. local total_height = (BUTTON_HEIGHT + margin) * #buttons
  1397. for i, button in ipairs(modeSelectorButtons) do
  1398. button.last = button.now
  1399. local bx = (VIRTUAL_WIDTH * 0.5) - (button_width * 0.5)
  1400. local by = (VIRTUAL_HEIGHT * 0.5) - (total_height * 0.5) + cursor_y
  1401. local color = {255, 255, 255, 255}
  1402. local mx, my = love.mouse.getPosition()
  1403. mx = mx * DIFFERENCE_X
  1404. my = my * DIFFERENCE_Y
  1405. hot = (mx > bx and mx < bx + button_width and my > by and my < by + BUTTON_HEIGHT) and i
  1406. if (hot == i) then
  1407. color = {10, 10, 0, 255}
  1408. end
  1409. button.now = love.mouse.isDown(1)
  1410. if button.now and not button.last and hot == i then
  1411. love.graphics.setColor(0, 0, 0, 1)
  1412. love.graphics.rectangle("fill", 0, 0, VIRTUAL_WIDTH, VIRTUAL_HEIGHT)
  1413. sounds["wallhit"]:play()
  1414. button.fn()
  1415. end
  1416. love.graphics.setColor(unpack(color))
  1417. love.graphics.rectangle("fill", bx, by, button_width, BUTTON_HEIGHT)
  1418. love.graphics.setColor(0, 0, 0, 255)
  1419. local textW = smallfont:getWidth(button.text)
  1420. local textH = smallfont:getHeight(button.text)
  1421. love.graphics.print(button.text, smallfont, VIRTUAL_WIDTH * 0.5 - textW * 0.5, by + textH * 0.5)
  1422. love.graphics.setColor(255, 255, 255, 255)
  1423. cursor_y = cursor_y + (BUTTON_HEIGHT + margin)
  1424. end
  1425. end
  1426. if (gameState == "multiMode") then
  1427. local button_width = VIRTUAL_WIDTH * (1 / 3)
  1428. local BUTTON_HEIGHT = 50
  1429. local margin = 20
  1430. local hot = false
  1431. local cursor_y = 0
  1432. local total_height = (BUTTON_HEIGHT + margin) * #buttons
  1433. for i, button in ipairs(playerCountButtons) do
  1434. button.last = button.now
  1435. local bx = (VIRTUAL_WIDTH * 0.5) - (button_width * 0.5)
  1436. local by = (VIRTUAL_HEIGHT * 0.3) - (total_height * 0.5) + cursor_y
  1437. if (button.text == "Play") then
  1438. by = by + by / 1.8
  1439. end
  1440. local color = {255, 255, 255, 255}
  1441. local mx, my = love.mouse.getPosition()
  1442. mx = mx * DIFFERENCE_X
  1443. my = my * DIFFERENCE_Y
  1444. hot = (mx > bx and mx < bx + button_width and my > by and my < by + BUTTON_HEIGHT) and i
  1445. if (hot == i) then
  1446. if (button.text == "Play") then
  1447. color = {0 / 255, 255 / 255, 0 / 255, 255}
  1448. else
  1449. color = {10, 10, 0, 255}
  1450. end
  1451. end
  1452. button.now = love.mouse.isDown(1)
  1453. if button.now and not button.last and hot == i then
  1454. love.graphics.setColor(0, 0, 0, 1)
  1455. love.graphics.rectangle("fill", 0, 0, VIRTUAL_WIDTH, VIRTUAL_HEIGHT)
  1456. sounds["wallhit"]:play()
  1457. if button.text == "Ball Speed: " and nuckemodactive == 1 then
  1458. else
  1459. button.fn()
  1460. end
  1461. end
  1462. love.graphics.setColor(unpack(color))
  1463. love.graphics.rectangle("fill", bx, by, button_width, BUTTON_HEIGHT)
  1464. love.graphics.setColor(0, 0, 0, 255)
  1465. local textW = smallfont:getWidth(button.text)
  1466. local textH = smallfont:getHeight(button.text)
  1467. if (button.text == "1v1") then
  1468. love.graphics.print(playertext, smallfont, VIRTUAL_WIDTH * 0.5 - textW * 0.5, by + textH * 0.5)
  1469. elseif button.text == "snc" then
  1470. if (nuckemodactive == 1) then
  1471. love.graphics.setColor(1, 0, 0, 1)
  1472. love.graphics.print(synctext, smallfont, VIRTUAL_WIDTH * 0.5 - textW * 0.5, by + textH * 0.5)
  1473. love.graphics.setColor(1, 1, 1, 1)
  1474. love.graphics.print(synctext, smallfont, VIRTUAL_WIDTH * 0.5 - textW * 0.5, by + textH * 0.5)
  1475. love.graphics.setColor(0, 0, 0, 1)
  1476. else
  1477. --
  1478. love.graphics.print(synctext, smallfont, VIRTUAL_WIDTH * 0.45 - textW * 0.5, by + textH * 0.5)
  1479. end
  1480. elseif (button.text == "ballCount") then
  1481. love.graphics.print(
  1482. "Ball Count: " .. maxBalls,
  1483. smallfont,
  1484. VIRTUAL_WIDTH * 0.5 - textW * 0.5,
  1485. by + textH * 0.5
  1486. )
  1487. elseif (button.text == "Ball Speed: ") then
  1488. if (nuckemodactive == 1) then
  1489. love.graphics.setColor(1, 0, 0, 1)
  1490. love.graphics.print(
  1491. "shaitan machina",
  1492. smallfont,
  1493. VIRTUAL_WIDTH * 0.5 - textW * 0.5,
  1494. by + textH * 0.5
  1495. )
  1496. love.graphics.setColor(1, 1, 1, 1)
  1497. love.graphics.print(
  1498. "shaitan machina",
  1499. smallfont,
  1500. VIRTUAL_WIDTH * 0.5 - textW * 0.5,
  1501. by + textH * 0.5
  1502. )
  1503. love.graphics.setColor(0, 0, 0, 1)
  1504. else
  1505. love.graphics.print(
  1506. button.text .. ballSet,
  1507. smallfont,
  1508. VIRTUAL_WIDTH * 0.5 - textW * 0.5,
  1509. by + textH * 0.5
  1510. )
  1511. end
  1512. elseif button.text == "ptw" then
  1513. love.graphics.print(
  1514. "Points to Win: " .. ptw,
  1515. smallfont,
  1516. VIRTUAL_WIDTH * 0.5 - textW * 1.5,
  1517. by + textH * 0.5
  1518. )
  1519. else
  1520. love.graphics.print(button.text, smallfont, VIRTUAL_WIDTH * 0.5 - textW * 0.5, by + textH * 0.5)
  1521. end
  1522. love.graphics.setColor(255, 255, 255, 255)
  1523. cursor_y = cursor_y + (BUTTON_HEIGHT + margin)
  1524. end
  1525. end
  1526. end
  1527. function love.draw(dt)
  1528. simpleScale.set()
  1529. if globalState == "selfhost" then
  1530. globalState = "nettest"
  1531. baseDraw()
  1532. globalState = "selfhost"
  1533. else
  1534. baseDraw()
  1535. end
  1536. if (globalState == "nettest" or globalState == "clienttest" or globalState == "selfhost") and confirmation == "D" then
  1537. love.graphics.clear(50 / 255, 50 / 255, 50 / 255, 255)
  1538. love.graphics.printf("WAIT FOR OPPONENT", 0, VIRTUAL_HEIGHT / 2, VIRTUAL_WIDTH, "center")
  1539. end
  1540. if (globalState == "nettest" or globalState == "clienttest" or globalState == "selfhost") and confirmation == "U" then
  1541. love.graphics.clear(50 / 255, 50 / 255, 50 / 255, 255)
  1542. love.graphics.printf("LOBBY FULL OR WRONG MODE CHOSEN", 0, VIRTUAL_HEIGHT / 2, VIRTUAL_WIDTH, "center")
  1543. end
  1544. if (globalState == "nettest" or globalState == "clienttest" or globalState == "selfhost") and confirmation == "L" then
  1545. love.graphics.clear(50 / 255, 50 / 255, 50 / 255, 255)
  1546. love.graphics.printf("POOR CONNECTION TO SERVER", 0, VIRTUAL_HEIGHT / 2, VIRTUAL_WIDTH, "center")
  1547. end
  1548. if (globalState == "nettest" or globalState == "clienttest" or globalState == "selfhost") and confirmation == "S" then
  1549. love.graphics.clear(50 / 255, 50 / 255, 50 / 255, 255)
  1550. love.graphics.printf("INTERNAL SERVER WAITING", 0, VIRTUAL_HEIGHT / 2, VIRTUAL_WIDTH, "center")
  1551. love.graphics.printf(myip, 0, VIRTUAL_HEIGHT / 2 + 120, VIRTUAL_WIDTH, "center")
  1552. end
  1553. simpleScale.unSet()
  1554. end
  1555. --Check if controls are duplicating
  1556. function controllerSer()
  1557. for i = 1, maxBalls do
  1558. if (ball[i].dy == 0) then
  1559. hitNum[i] = hitNum[i] + 1
  1560. if hitNum[i] >= 10 then
  1561. ball[i].dy = 1
  1562. hitNum[i] = 0
  1563. end
  1564. else
  1565. hitNum[i] = 0
  1566. end
  1567. end
  1568. end
  1569. function palleteController() --!!!!LEGACY CODE, MIGRATED TO Paddle.lua!!!!
  1570. if (areanuclear == 0) then
  1571. player1.RED = 1
  1572. player1.GREEN = 1
  1573. player1.BLUE = 1
  1574. end
  1575. if (areanuclear == 0) then
  1576. player2.RED = 1
  1577. player2.GREEN = 1
  1578. player2.BLUE = 1
  1579. end
  1580. if (areanuclear == 1) then
  1581. player1.RED = 0
  1582. player1.GREEN = 0
  1583. player1.BLUE = 0
  1584. end
  1585. if (areanuclear == 1) then
  1586. player2.RED = 0
  1587. player2.GREEN = 0
  1588. player2.BLUE = 0
  1589. end
  1590. end
  1591. function love.wheelmoved(x, y)
  1592. if (y < 0 and wall1width > 0) then
  1593. wall1width = wall1width - 5
  1594. elseif y > 0 and wall1width < 900 then
  1595. wall1width = wall1width + 5
  1596. end
  1597. end
  1598. function serveBot() --THIS IS USED TO CHANGE TEXT/BALL DIRECTION ON DIFFERENT SERVES
  1599. --print("servebot called")
  1600. if (gameState == "1serve") then
  1601. updateTEXT = ""
  1602. if (gameMode ~= "practice") then
  1603. if isAndroid then
  1604. TEXT = "PLAYER 1, serve!(double-click)"
  1605. else
  1606. TEXT = "PLAYER 1, serve!(q)"
  1607. end
  1608. end
  1609. if ((globalState ~= "clienttest" and love.keyboard.isDown("q")) or (globalState == "clienttest" and lastSentKeyP1 == "q") or doubleclick1) then
  1610. TEXT = "Lets Begin!"
  1611. ball_DIR = 1
  1612. if maxBalls == 1 then
  1613. ball[1]:reset(1, 1)
  1614. else
  1615. for i = 1, maxBalls do
  1616. ball[i]:reset(i)
  1617. end
  1618. end
  1619. gameState = "play"
  1620. end
  1621. end
  1622. if (gameState == "2serve") then
  1623. if (gameMode ~= "practice") then
  1624. if isAndroid then
  1625. TEXT = "PLAYER 2, serve!(double-click)"
  1626. else
  1627. TEXT = "PLAYER 2, serve!(p)"
  1628. end
  1629. end
  1630. if (AGAINST_AI == 1) then
  1631. TEXT = ""
  1632. ball_DIR = -1
  1633. if maxBalls == 1 then
  1634. ball[2]:reset(i, 2)
  1635. else
  1636. for i = 1, maxBalls do
  1637. ball[i]:reset(i)
  1638. end
  1639. end
  1640. gameState = "play"
  1641. end
  1642. if (((globalState == "nettest" and lastSentKeyClient == "p") or ((globalState ~= "nettest") and love.keyboard.isDown("p")) or doubleclick2)and AGAINST_AI == 0) then
  1643. TEXT = "Lets Begin"
  1644. ball_DIR = -1
  1645. if maxBalls == 1 then
  1646. ball[1]:reset(1, 2)
  1647. else
  1648. for i = 1, maxBalls do
  1649. ball[i]:reset(i)
  1650. end
  1651. end
  1652. --love.window.setTitle("An atttttttt")
  1653. gameState = "play"
  1654. end
  1655. end
  1656. end
  1657. function mapChanger()
  1658. if (gameState == "editor") then
  1659. MAP_TYPE = 2
  1660. end
  1661. if (MAP_TYPE > 2) then
  1662. MAP_TYPE = 0
  1663. end
  1664. end
  1665. function resolutionChanger()
  1666. if (RESOLUTION_SET > 1) then
  1667. RESOLUTION_SET = 0
  1668. end
  1669. if (RESOLUTION_SET == 0) then
  1670. if (isFullscreen == 1) then
  1671. DIFFERENCE_X = 1
  1672. DIFFERENCE_Y = 1
  1673. simpleScale.updateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, {fullscreen = false})
  1674. isFullscreen = 0
  1675. end
  1676. end
  1677. if (RESOLUTION_SET == 1) then
  1678. if (isFullscreen == 0) then
  1679. simpleScale.updateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, {fullscreen = true})
  1680. local newWidth = love.graphics.getWidth()
  1681. local newHeight = love.graphics.getHeight()
  1682. DIFFERENCE_X = VIRTUAL_WIDTH / newWidth
  1683. DIFFERENCE_Y = VIRTUAL_HEIGHT / newHeight
  1684. isFullscreen = 1
  1685. end
  1686. end
  1687. end
  1688. function resettinggenius()
  1689. maxBalls = 1
  1690. for i = 1, maxBalls do
  1691. ball[i]:reset(i)
  1692. end
  1693. paddle_SPEED = 200
  1694. nuclearanimation = 3
  1695. timeIsSlow = false
  1696. timeIsSlow2 = false
  1697. serverinit = false
  1698. ts = 0
  1699. originalSpeed = 200
  1700. gameState = "menu"
  1701. globalState = "menu"
  1702. gameMode = "normal"
  1703. player1.height = 100
  1704. player2.height = 100
  1705. ballSet = 200
  1706. ballSpeed = ballSet
  1707. player2.GREEN = 255
  1708. player2.BLUE = 255
  1709. player1.GREEN = 255
  1710. player1.BLUE = 255
  1711. player1score = 0
  1712. player2score = 0
  1713. potentialnuke1 = 0
  1714. potentialnuke2 = 0
  1715. striken = 0
  1716. areanuclear = 0
  1717. potentialstrike1 = 0
  1718. potentialstrike2 = 0
  1719. player1nukescore = 0
  1720. player2nukescore = 0
  1721. player1reverbav = 0
  1722. player2reverbav = 0
  1723. selecting = 0
  1724. AGAINST_AI = 0
  1725. end
  1726. function love.mousereleased(x, y, button)
  1727. love.keyboard.mouseisReleased = true
  1728. if (gameState == "editor") then
  1729. if (#walls < 1000 and button == 1 and blockinput ~= true) then
  1730. table.insert(walls, newWall(x * DIFFERENCE_X, y * DIFFERENCE_Y, 10, wall1width))
  1731. end
  1732. end
  1733. end
  1734. function ballsAlive()
  1735. for i = 1, maxBalls do
  1736. if ball[i].disabled == false then
  1737. print("Ball " .. i .. " is not disabled")
  1738. return true
  1739. end
  1740. end
  1741. return false
  1742. end
  1743. function split(s, delimiter)
  1744. result = {}
  1745. for match in (s..delimiter):gmatch("(.-)"..delimiter) do
  1746. table.insert(result, match)
  1747. end
  1748. return result
  1749. end
  1750. address, port = IP, 12345
  1751. function checkCurrentServer(dt)
  1752. if GetIPType(IP) ~= 1 then
  1753. status = "offline"
  1754. end
  1755. if GetIPType(IP) == 1 then
  1756. if dserverinit == false then
  1757. print("Switching IP")
  1758. socket = require "socket"
  1759. address, port = IP, 12345
  1760. print(address)
  1761. udp = socket.udp()
  1762. udp:setpeername(address, port)
  1763. udp:settimeout(0)
  1764. dserverinit = true
  1765. end
  1766. if IP ~= address then dserverinit = false print(IP .. " doesnt equal " .. address)
  1767. else
  1768. ts = ts + dt
  1769. --print(ts)
  1770. if ts > checkrate then
  1771. status = "offline"
  1772. print("sent ping")
  1773. udp:send("HELLO")
  1774. local data
  1775. data = udp:receive()
  1776. if data then
  1777. print("got answer!")
  1778. local p = split(data, '|')
  1779. status = p[1]
  1780. print("answer is " .. status)
  1781. else
  1782. print("no response!")
  1783. end
  1784. ts = 0
  1785. end
  1786. end
  1787. end
  1788. end
  1789. local gts = 0
  1790. hostinit = false
  1791. player1ip = "127.0.0.1"
  1792. player1port = "12345"
  1793. player2ip = "none"
  1794. player2port = nil
  1795. local p1ping = 0
  1796. local p2ping = 0
  1797. local requesterip
  1798. local requresterport
  1799. function selfHost(dt)
  1800. print("Server running")
  1801. if not hostinit then
  1802. local socket = require('socket')
  1803. udp = socket.udp()
  1804. udp:setsockname('*', 12345)
  1805. udp:settimeout(0)
  1806. local s = socket.udp()
  1807. s:setpeername("74.125.115.104",80)
  1808. myip, _ = s:getsockname()
  1809. hostinit = true
  1810. else
  1811. gts = gts + dt
  1812. if gts > 0.015 then
  1813. local data, msg_or_ip, port_or_nil
  1814. local p1data, p2data
  1815. repeat
  1816. data, msg_or_ip, port_or_nil = udp:receivefrom()
  1817. if data then
  1818. if data == "HELLO" then
  1819. requesterip = msg_or_ip
  1820. requesterport = port_or_nil
  1821. else
  1822. print(string.sub(data,1,1) .. "Playerlist: " .. player1ip .. " " .. player2ip)
  1823. if player2ip == msg_or_ip then
  1824. p2data = data .. '|' .. p2ping
  1825. p2ping = 0
  1826. else
  1827. if player2ip == "none" and msg_or_ip ~= player1ip then
  1828. player2ip = msg_or_ip
  1829. p2data = data .. '|' .. p2ping
  1830. p2ping = 0
  1831. player2port = port_or_nil
  1832. print("CONNECTED: PLAYER 2 FROM: " .. player2ip)
  1833. elseif (player1ip ~= msg_or_ip and player2ip ~= msg_or_ip) then
  1834. print("Lobby Full!" .. player1ip .. player2ip)
  1835. end
  1836. end
  1837. end
  1838. end
  1839. until not data
  1840. if player1ip ~= "none" then
  1841. p1ping = p1ping + 1
  1842. end
  1843. if player2ip == "none" then
  1844. confirmation = "S"
  1845. else
  1846. print("Player2: " .. player2ip)
  1847. p2ping = p2ping + 1
  1848. if p2ping > 100 then
  1849. for i = 1, maxBalls do
  1850. ts = ts + dt
  1851. if ts > updaterate then
  1852. udp:sendto(tostring(lastSentKey) ..
  1853. '|' .. tostring(ball[1].dy) ..
  1854. '|' .. tostring(player2.y) ..
  1855. '|' .. tostring(player1.y) ..
  1856. '|' .. tostring(player1score) ..
  1857. '|' .. tostring(player2score) ..
  1858. '|' .. tostring(player1nukescore) ..
  1859. '|' .. tostring(player2nukescore) ..
  1860. '|' .. tostring(ball[1].x) ..
  1861. '|' .. tostring(ball[1].y) ..
  1862. '|' .. gameState ..
  1863. '|' .. tostring(ball[1].dx) ..
  1864. '|' .. tostring(ballSpeed) ..
  1865. '|' .. tostring(paddle_SPEED) ..
  1866. "|HOST|".. p2ping, player2ip, player2port)
  1867. ts = 0
  1868. end
  1869. end
  1870. print("PLAYER 2 DISCONNECTED")
  1871. p2data = nil
  1872. player2ip = "none"
  1873. player2port = nil
  1874. end
  1875. end
  1876. if player2port then
  1877. for i = 1, maxBalls do
  1878. ts = ts + dt
  1879. if ts > updaterate then
  1880. udp:sendto(tostring(lastSentKey) ..
  1881. '|' .. tostring(ball[1].dy) ..
  1882. '|' .. tostring(player2.y) ..
  1883. '|' .. tostring(player1.y) ..
  1884. '|' .. tostring(player1score) ..
  1885. '|' .. tostring(player2score) ..
  1886. '|' .. tostring(player1nukescore) ..
  1887. '|' .. tostring(player2nukescore) ..
  1888. '|' .. tostring(ball[1].x) ..
  1889. '|' .. tostring(ball[1].y) ..
  1890. '|' .. gameState ..
  1891. '|' .. tostring(ball[1].dx) ..
  1892. '|' .. tostring(ballSpeed) ..
  1893. '|' .. tostring(paddle_SPEED) ..
  1894. "|HOST|".. p2ping, player2ip, player2port)
  1895. ts = 0
  1896. end
  1897. end
  1898. print("SENT TO " .. player2ip .. ":" .. player2port .. " : " ..lastSentKey)
  1899. end
  1900. local datanumtest = 0
  1901. local datawaspassed = false
  1902. if p2data and player1port then
  1903. datawaspassed = true
  1904. print("ReceivedINFO: " .. p2data)
  1905. confirmation = "N"
  1906. local p = split(p2data, '|')
  1907. if p[15] then
  1908. if tonumber(p[16]) > 90 then
  1909. confirmation = "L"
  1910. end
  1911. if p[15] ~= "CLIENT" then
  1912. confirmation = "U"
  1913. end
  1914. elseif p[1] == "RESPONSE" then
  1915. if p[2] == "1" then
  1916. elseif p[2] == "2" then
  1917. elseif p[2] == "3" then
  1918. end
  1919. else
  1920. confirmation = "U"
  1921. end
  1922. if p[15] then
  1923. if ball[1].disabled and ball[1].x > 20 and ball[1].x < VIRTUAL_WIDTH - 20 then
  1924. ball[1].disabled = false
  1925. print("illegal disabling")
  1926. end
  1927. if gameState ~= "1serve" then
  1928. if (ball[1].x > VIRTUAL_WIDTH/2) then
  1929. if tonumber(p[9]) > VIRTUAL_WIDTH/2 then
  1930. die = tonumber(p[2])
  1931. lastSentKeyClient,
  1932. ball[1].dy,
  1933. player2.y,
  1934. player1score,
  1935. player2score,
  1936. player1nukescore,
  1937. player2nukescore,
  1938. ball[1].x,
  1939. ball[1].y,
  1940. gameState,
  1941. ball[1].dx,
  1942. ballSpeed,
  1943. paddle_SPEED = 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])
  1944. print("ACCEPTED")
  1945. else
  1946. print("DECLINED")
  1947. end
  1948. else
  1949. if tonumber(p[9]) > VIRTUAL_WIDTH/2 then
  1950. die = tonumber(p[2])
  1951. lastSentKeyClient,
  1952. ball[1].dy,
  1953. player2.y,
  1954. player1score,
  1955. player2score,
  1956. player1nukescore,
  1957. player2nukescore,
  1958. ball[1].x,
  1959. ball[1].y,
  1960. gameState,
  1961. ball[1].dx,
  1962. ballSpeed,
  1963. paddle_SPEED = 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])
  1964. print("ACCEPTED")
  1965. else
  1966. print("ENFORCED" .. ball[1].x .. " " .. ball[1].dx)
  1967. lastSentKeyClient = p[1]
  1968. player2.y = tonumber(p[4])
  1969. end
  1970. end
  1971. end
  1972. end
  1973. print("SENT TO " .. player1ip .. ":" .. player1port .. " : " .. string.sub(p2data,1,1))
  1974. --print("1::" .. p1data)
  1975. --print("2::" .. p2data)
  1976. --print("SENT1: " .. player2ip .. " " .. player2port .. " " .. p1data)
  1977. --print("SENT2: " .. player1ip .. " " .. player1port .. " " .. p2data)
  1978. end
  1979. if requesterip then
  1980. print("getting pnged!")
  1981. if player2ip == "none" then
  1982. udp:sendto("clienttest", requesterip, requesterport)
  1983. print("clienttest av to: " .. requesterip)
  1984. else
  1985. udp:sendto("full", requesterip, requesterport)
  1986. print("full to: " .. msg_or_ip)
  1987. end
  1988. requesterip, requesterport = nil
  1989. end
  1990. gts = 0
  1991. end
  1992. end
  1993. end
  1994. local lastclick = 0
  1995. local clickInterval = 0.4
  1996. function love.touchpressed( id, x, y, dx, dy, pressure )
  1997. if isAndroid then
  1998. local existsingID = touchExists(id)
  1999. if existsingID ~= -1 then
  2000. touches[existsingID].x = x * DIFFERENCE_X
  2001. touches[existsingID].y = y * DIFFERENCE_Y
  2002. else
  2003. table.insert(touches, newTouch(id, x*DIFFERENCE_X, y*DIFFERENCE_Y))
  2004. local time = love.timer.getTime()
  2005. if x * DIFFERENCE_X < VIRTUAL_WIDTH/2 then
  2006. if time <= lastclick + clickInterval and x*DIFFERENCE_X > 50 then
  2007. doubleclick1 = true
  2008. if gameState == "1serve" then
  2009. lastSentKey = "q"
  2010. else
  2011. lastSentKey = p1control.super
  2012. end
  2013. else
  2014. doubleclick1 = false
  2015. lastclick = time
  2016. end
  2017. else
  2018. if time <= lastclick + clickInterval and x*DIFFERENCE_X > VIRTUAL_WIDTH-50 then
  2019. doubleclick2 = true
  2020. if gameState == "2serve" then
  2021. lastSentKey = "p"
  2022. else
  2023. lastSentKey = p2control.super
  2024. end
  2025. else
  2026. doubleclick2 = false
  2027. lastclick = time
  2028. end
  2029. end
  2030. end
  2031. end
  2032. end
  2033. function love.touchreleased( id, x, y, dx, dy, pressure )
  2034. if isAndroid then
  2035. if gameState == "start" then
  2036. resettinggenius()
  2037. gameState = "menu"
  2038. globalState = "menu"
  2039. hardmanager()
  2040. end
  2041. local existsingID = touchExists(id)
  2042. if existsingID ~= -1 then
  2043. table.remove(touches, existsingID)
  2044. end
  2045. end
  2046. end
  2047. function love.touchmoved( id, x, y, dx, dy, pressure )
  2048. if isAndroid then
  2049. local existsingID = touchExists(id)
  2050. if existsingID ~= -1 then
  2051. touches[existsingID].x = x * DIFFERENCE_X
  2052. touches[existsingID].y = y * DIFFERENCE_Y
  2053. if touches[existsingID].originalX - touches[existsingID].x > 200 and
  2054. touches[existsingID].originalX < VIRTUAL_WIDTH/2 then
  2055. hold1 = true
  2056. lastSentKey = p1control.counter
  2057. else
  2058. hold1 = false
  2059. end
  2060. if touches[existsingID].x - touches[existsingID].originalX > 200 and
  2061. touches[existsingID].originalX > VIRTUAL_WIDTH/2 then
  2062. hold2 = true
  2063. lastSentKey = p2control.counter
  2064. else
  2065. hold2 = false
  2066. end
  2067. end
  2068. end
  2069. end
  2070. function touchExists(ID)
  2071. for i, touch in ipairs(touches) do
  2072. if touch.id == ID then
  2073. return i
  2074. end
  2075. end
  2076. return -1
  2077. end
  2078. function table.empty (self)
  2079. for _, _ in pairs(self) do
  2080. return false
  2081. end
  2082. return true
  2083. end
  2084. function sectortouched(sector)
  2085. for i, touch in ipairs(touches) do
  2086. if sector == 1 and touch.x > VIRTUAL_WIDTH-60 and touch.y < VIRTUAL_HEIGHT/2 then
  2087. lastSentKey = p2control.up
  2088. return true
  2089. elseif sector == 2 and touch.x < 60 and touch.y < VIRTUAL_HEIGHT/2 then
  2090. lastSentKey = p1control.up
  2091. return true
  2092. elseif sector == 3 and touch.x < 60 and touch.y > VIRTUAL_HEIGHT/2 then
  2093. lastSentKey = p1control.down
  2094. return true
  2095. elseif sector == 4 and touch.x > VIRTUAL_WIDTH-60 and touch.y > VIRTUAL_HEIGHT/2 then
  2096. lastSentKey = p2control.down
  2097. return true
  2098. end
  2099. end
  2100. return false
  2101. end