A pong clone, but with a twist!
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

1681 行
46 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. debug = true
  13. --GLOBAL VARIABLES
  14. status = "offline"
  15. gameMode = "normal"
  16. ts = 0
  17. globalState = "menu"
  18. timeIsSlow = false
  19. timeIsSlow2 = false
  20. originalSpeed = 200
  21. explosionRange = 0
  22. blockinput = false
  23. wall1width = 30
  24. nuclearanimation = 3
  25. easternum = 0
  26. ball_DIR = 0
  27. updaterate = 0.015
  28. RED = 255
  29. hitNum = {}
  30. hitNum[1] = 0
  31. hitNum[2] = 0
  32. hitNum[3] = 0
  33. confirmation = "N"
  34. hitNum[4] = 0
  35. p1bonus = 0
  36. p2bonus = 0
  37. hitNum[5] = 0
  38. hitNum[6] = 0
  39. GREEN = 255
  40. IP = '45.76.95.31'
  41. BLUE = 255
  42. updateTEXT = "Chalkboard Update"
  43. maxBalls = 1
  44. playerCount = 1
  45. player1reverbav = 0
  46. playertext = "1v1"
  47. player2reverbav = 0
  48. elapsed = 0
  49. rotation = 0
  50. TEXT = "Nuclear Pong"
  51. currentKey = " "
  52. ptw = 10
  53. --CHECKING IF CONTROLS ARE TAKEN
  54. danger = "none"
  55. danger2 = "none"
  56. nuckemodactive = 0
  57. maxspeed = 700
  58. DIFFERENCE_X = 1
  59. DIFFERENCE_Y = 1
  60. paddle_SPEED = 20
  61. textamount = 15
  62. AI_STRIKEMOD = 1000
  63. resolutionWin = 0
  64. AGAINST_AI = 0
  65. RESOLUTION_SET = 0
  66. AI_NUKEMOD = 1000
  67. animstart = true
  68. AI_SPEED = 30
  69. craz = 0
  70. AI_LEVEL = 500
  71. isFullscreen = 0
  72. prtext = "Easy"
  73. lastSentKey = "c"
  74. MAP_TYPE = 0
  75. lastSentKeyClient = "c"
  76. difficultyl = 300
  77. req = "pp"
  78. ballSet = 200
  79. p1control = {up = "a", down = "z", super = "s", counter = "x"}
  80. p2control = {up = ";", down = ".", super = "l", counter = ","}
  81. synctext = "Independent"
  82. synctype = 0
  83. function newButton(text, fn)
  84. return {
  85. text = text,
  86. fn = fn,
  87. now = false,
  88. last = false
  89. }
  90. end
  91. function love.keyboard.mouseWasReleased()
  92. return love.keyboard.mouseisReleased
  93. end
  94. function autoSave(dt)
  95. autoTimer = autoTimer + dt
  96. end
  97. function balancer()
  98. if (player2score == 9 or player1score == 9) then
  99. shakeDuration = 5
  100. if debug then
  101. --print("Shaking set to match almost over")
  102. end
  103. end
  104. if (player1score < player2score) then
  105. p1bonus = (player2score - player1score) * 5
  106. else
  107. p1bonus = 0
  108. end
  109. if (player2score < player1score) then
  110. p2bonus = (player1score - player2score) * 5
  111. else
  112. p2bonus = 0
  113. end
  114. end
  115. function newWall(wallx, wally, wallwidth, wallheight)
  116. return {
  117. wallx = wallx,
  118. wally = wally,
  119. walwidth = wallwidth,
  120. wallheight = wallheight
  121. }
  122. end
  123. speedParameters = {}
  124. buttons = {}
  125. IPselect = {}
  126. difbuttons = {}
  127. settings = {}
  128. walls = {}
  129. editorpicks = {}
  130. controlSettings = {}
  131. modeSelectorButtons = {}
  132. pracdiff = {}
  133. playerCountButtons = {}
  134. function controlChanger()
  135. if (gameState == "assign") then
  136. love.graphics.clear(50 / 255, 50 / 255, 50 / 255, 255)
  137. love.graphics.printf("SELECT BUTTON", 0, VIRTUAL_HEIGHT / 2, VIRTUAL_WIDTH, "center")
  138. end
  139. end
  140. function love.load()
  141. love.keyboard.setKeyRepeat(true)
  142. simpleScale.setWindow(VIRTUAL_WIDTH, VIRTUAL_HEIGHT, WINDOW_WIDTH, WINDOW_HEIGHT)
  143. configfile = io.open("config.lua", "r")
  144. configsave = io.open("config.lua", "w")
  145. shader = love.graphics.newShader(shader_code)
  146. time_1 = 0
  147. --print("Debug active")
  148. --load
  149. testwalls = love.filesystem.load("save.lua")()
  150. if testwalls ~= nil then
  151. walls = love.filesystem.load("save.lua")()
  152. end
  153. light = 0
  154. image = love.graphics.newImage("Madi.png")
  155. table.insert(
  156. editorpicks,
  157. newButton(
  158. "C",
  159. function()
  160. for k in pairs(walls) do
  161. walls[k] = nil
  162. end
  163. end
  164. )
  165. )
  166. table.insert(
  167. editorpicks,
  168. newButton(
  169. "S",
  170. function()
  171. love.filesystem.write("save.lua", serialize(walls))
  172. end
  173. )
  174. )
  175. table.insert(
  176. editorpicks,
  177. newButton(
  178. "L",
  179. function()
  180. walls = love.filesystem.load("save.lua")()
  181. end
  182. )
  183. )
  184. table.insert(
  185. buttons,
  186. newButton(
  187. "Singleplayer",
  188. function()
  189. gameState = "gameMode"
  190. end
  191. )
  192. )
  193. table.insert(
  194. buttons,
  195. newButton(
  196. "Online",
  197. function()
  198. MAP_TYPE = 0
  199. gameState = "chooseIP"
  200. end
  201. )
  202. )
  203. table.insert(
  204. IPselect,
  205. newButton(
  206. "Host",
  207. function()
  208. globalState = "nettest"
  209. AGAINST_AI = 0
  210. gameState = "1serve"
  211. ball[1]:reset(1, 1)
  212. end
  213. )
  214. )
  215. table.insert(
  216. IPselect,
  217. newButton(
  218. "Guest",
  219. function()
  220. globalState = "clienttest"
  221. AGAINST_AI = 0
  222. gameState = "1serve"
  223. ball[1]:reset(1, 1)
  224. end
  225. )
  226. )
  227. table.insert(
  228. buttons,
  229. newButton(
  230. "Multiplayer",
  231. function()
  232. gameState = "multiMode"
  233. end
  234. )
  235. )
  236. table.insert(
  237. buttons,
  238. newButton(
  239. "Settings",
  240. function()
  241. AGAINST_AI = 0
  242. gameState = "windowsettings"
  243. end
  244. )
  245. )
  246. table.insert(
  247. buttons,
  248. newButton(
  249. "Exit",
  250. function()
  251. love.event.quit(0)
  252. end
  253. )
  254. )
  255. table.insert(
  256. difbuttons,
  257. newButton(
  258. "Easy",
  259. function()
  260. hardmanager("easy")
  261. end
  262. )
  263. )
  264. table.insert(
  265. difbuttons,
  266. newButton(
  267. "Normal",
  268. function()
  269. hardmanager("normal")
  270. end
  271. )
  272. )
  273. table.insert(
  274. difbuttons,
  275. newButton(
  276. "Hard",
  277. function()
  278. hardmanager("hard")
  279. end
  280. )
  281. )
  282. table.insert(
  283. difbuttons,
  284. newButton(
  285. "Smart",
  286. function()
  287. hardmanager("smart")
  288. end
  289. )
  290. )
  291. --table.insert(
  292. -- settings,
  293. -- newButton(
  294. -- "Change Map",
  295. -- function()
  296. -- MAP_TYPE = MAP_TYPE + 1
  297. -- end
  298. -- )
  299. --)
  300. table.insert(
  301. settings,
  302. newButton(
  303. "Toggle Fullscreen",
  304. function()
  305. myscreen:toggle(VIRTUAL_HEIGHT, VIRTUAL_WIDTH)
  306. DIFFERENCE_X = myscreen.c
  307. DIFFERENCE_Y = myscreen.d
  308. end
  309. )
  310. )
  311. table.insert(
  312. settings,
  313. newButton(
  314. "Editor",
  315. function()
  316. gameState = "editor"
  317. end
  318. )
  319. )
  320. table.insert(
  321. settings,
  322. newButton(
  323. "Speed Settings",
  324. function()
  325. gameState = "speedSettings"
  326. end
  327. )
  328. )
  329. table.insert(
  330. settings,
  331. newButton(
  332. "Control Settings",
  333. function()
  334. gameState = "controlSettings"
  335. end
  336. )
  337. )
  338. table.insert(
  339. settings,
  340. newButton(
  341. "Back to Menu",
  342. function()
  343. gameState = "menu"
  344. end
  345. )
  346. )
  347. table.insert(
  348. speedParameters,
  349. newButton(
  350. "Back to Menu",
  351. function()
  352. gameState = "windowsettings"
  353. end
  354. )
  355. )
  356. --table.insert(speedParameters, newButton("Ball Speed: ", function() speedSetter('ball') end))
  357. table.insert(
  358. playerCountButtons,
  359. newButton(
  360. "Ball Speed: ",
  361. function()
  362. speedSetter("ball")
  363. end
  364. )
  365. )
  366. --table.insert(speedParameters, newButton("snc", function() speedSetter('snc') end))
  367. table.insert(
  368. playerCountButtons,
  369. newButton(
  370. "snc",
  371. function()
  372. speedSetter("snc")
  373. end
  374. )
  375. )
  376. table.insert(
  377. speedParameters,
  378. newButton(
  379. "NUCLEAR MODE",
  380. function()
  381. speedSetter("nuclearmod")
  382. end
  383. )
  384. )
  385. table.insert(
  386. controlSettings,
  387. newButton(
  388. "1up",
  389. function()
  390. gameState = "assign"
  391. req = "p1up"
  392. end
  393. )
  394. )
  395. table.insert(
  396. controlSettings,
  397. newButton(
  398. "1down",
  399. function()
  400. gameState = "assign"
  401. req = "p1down"
  402. end
  403. )
  404. )
  405. table.insert(
  406. controlSettings,
  407. newButton(
  408. "1special",
  409. function()
  410. gameState = "assign"
  411. req = "p1super"
  412. end
  413. )
  414. )
  415. table.insert(
  416. controlSettings,
  417. newButton(
  418. "1ct",
  419. function()
  420. gameState = "assign"
  421. req = "p1ct"
  422. end
  423. )
  424. )
  425. table.insert(
  426. controlSettings,
  427. newButton(
  428. "2up",
  429. function()
  430. gameState = "assign"
  431. req = "p2up"
  432. end
  433. )
  434. )
  435. table.insert(
  436. controlSettings,
  437. newButton(
  438. "2down",
  439. function()
  440. gameState = "assign"
  441. req = "p2down"
  442. end
  443. )
  444. )
  445. table.insert(
  446. controlSettings,
  447. newButton(
  448. "2special",
  449. function()
  450. gameState = "assign"
  451. req = "p2super"
  452. end
  453. )
  454. )
  455. table.insert(
  456. controlSettings,
  457. newButton(
  458. "2ct",
  459. function()
  460. gameState = "assign"
  461. req = "p2ct"
  462. end
  463. )
  464. )
  465. table.insert(
  466. controlSettings,
  467. newButton(
  468. "Default",
  469. function()
  470. p1control = {up = "a", down = "z", super = "s", counter = "x"}
  471. p2control = {up = ";", down = ".", super = "l", counter = ","}
  472. end
  473. )
  474. )
  475. table.insert(
  476. controlSettings,
  477. newButton(
  478. "Return",
  479. function()
  480. gameState = "windowsettings"
  481. end
  482. )
  483. )
  484. table.insert(
  485. modeSelectorButtons,
  486. newButton(
  487. "Nuclear Pong",
  488. function()
  489. gameState = "difficulty"
  490. end
  491. )
  492. )
  493. table.insert(
  494. modeSelectorButtons,
  495. newButton(
  496. "Main Menu",
  497. function()
  498. gameState = "menu"
  499. end
  500. )
  501. )
  502. table.insert(
  503. pracdiff,
  504. newButton(
  505. "Silverblade",
  506. function()
  507. speedSetter("practice")
  508. end
  509. )
  510. )
  511. table.insert(
  512. pracdiff,
  513. newButton(
  514. "Return",
  515. function()
  516. speedSetter("reset")
  517. gameState = "gameMode"
  518. end
  519. )
  520. )
  521. table.insert(
  522. pracdiff,
  523. newButton(
  524. "Go!",
  525. function()
  526. gameMode = "practice"
  527. hardmanager("practice")
  528. end
  529. )
  530. )
  531. --table.insert(playerCountButtons, newButton("1v1", function() speedSetter('pc') end))
  532. table.insert(
  533. playerCountButtons,
  534. newButton(
  535. "ballCount",
  536. function()
  537. speedSetter("ballz")
  538. end
  539. )
  540. )
  541. table.insert(
  542. difbuttons,
  543. newButton(
  544. "ballCount",
  545. function()
  546. speedSetter("ballz")
  547. end
  548. )
  549. )
  550. table.insert(
  551. playerCountButtons,
  552. newButton(
  553. "Return",
  554. function()
  555. speedSetter("reset")
  556. gameState = "menu"
  557. end
  558. )
  559. )
  560. table.insert(
  561. playerCountButtons,
  562. newButton(
  563. "ptw",
  564. function()
  565. speedSetter("ptw")
  566. end
  567. )
  568. )
  569. table.insert(
  570. playerCountButtons,
  571. newButton(
  572. "Play",
  573. function()
  574. AGAINST_AI = 0
  575. gameState = "1serve"
  576. globalState = "base"
  577. end
  578. )
  579. )
  580. table.insert(
  581. playerCountButtons,
  582. newButton(
  583. "Reverse Play",
  584. function()
  585. gameState = "1serve"
  586. gameMode = "reversegame"
  587. globalState = "base"
  588. end
  589. )
  590. )
  591. --table.insert(speedParameters, newButton("Ball Speed: ", function() speedSetter() end))
  592. love.window.setTitle("NUCLEAR PONG")
  593. textphrases = {
  594. "Amazing",
  595. "Superb",
  596. "Absolutely beautiful!",
  597. "Awesome",
  598. "Look at That!",
  599. "Great",
  600. "Nice",
  601. "Boom!",
  602. "Dangerous!",
  603. "Astonishing!",
  604. "u/ebernerd saved me",
  605. "Absolutely Wonderful!",
  606. "Exsquisite",
  607. "Delicate",
  608. "Pow!",
  609. "Great Hit",
  610. "all hail nazarbayev"
  611. }
  612. sounds = {
  613. ["updateMusic"] = love.audio.newSource("audio/theme1.mp3", "static"),
  614. ["gayTheme"] = love.audio.newSource("audio/theme2.mp3", "static"),
  615. ["gayTheme2"] = love.audio.newSource("audio/theme3.mp3", "static"),
  616. ["gayTheme3"] = love.audio.newSource("audio/theme4.mp3", "static"),
  617. ["beep"] = love.audio.newSource("audio/hit1.mp3", "static"),
  618. ["wallhit"] = love.audio.newSource("audio/hit2.wav", "static"),
  619. ["win"] = love.audio.newSource("win.wav", "static"),
  620. ["score"] = love.audio.newSource("audio/score.wav", "static"),
  621. ["nuke"] = love.audio.newSource("audio/bomb.wav", "static"),
  622. ["striking"] = love.audio.newSource("audio/superhit.wav", "static"),
  623. ["nuclearhit"] = love.audio.newSource("audio/hit1.mp3", "static"),
  624. ["time"] = love.audio.newSource("audio/time.wav", "static")
  625. }
  626. love.graphics.setDefaultFilter("nearest", "nearest")
  627. --comic sans lmao
  628. math.randomseed(os.time())
  629. smallfont = love.graphics.newFont("font.ttf", 25)
  630. scorefont = love.graphics.newFont("font.ttf", 60)
  631. love.graphics.setFont(smallfont)
  632. --push:setupScreen(VIRTUAL_WIDTH, VIRTUAL_HEIGHT, WINDOW_WIDTH, WINDOW_HEIGHT, {
  633. -- fullscreen = isFullscreen,
  634. -- resizable = true,
  635. -- vsync = true,
  636. --})
  637. player1score = 0
  638. player2score = 0
  639. areanuclear = 0
  640. player1nukescore = 0
  641. player2nukescore = 0
  642. striken = 0
  643. soundtype = 1
  644. soundturn = 1
  645. potentialstrike1 = 0
  646. potentialstrike2 = 0
  647. potentialnuke1 = 0
  648. potentialnuke2 = 0
  649. player1striken = 0
  650. player2striken = 0
  651. randomtext = 0
  652. selecting = 0
  653. number = 0
  654. elec = 1
  655. INDIC = {
  656. "",
  657. "",
  658. "",
  659. ""
  660. }
  661. --playe1nuke
  662. player1 = paddle(0, 30, 10, 100, 1)
  663. player2 = paddle(VIRTUAL_WIDTH * 0.99, VIRTUAL_HEIGHT * 0.88, 10, 100, 2)
  664. player3 = paddle(5000, 5000, 10, 100)
  665. player4 = paddle(5000, 5000, 10, 100)
  666. ball = {}
  667. ball[1] = eball(VIRTUAL_WIDTH / 2, VIRTUAL_HEIGHT / 2 - 2, 16, 16)
  668. ball[2] = eball(VIRTUAL_WIDTH / 1.9, VIRTUAL_HEIGHT / 2 - 2, 16, 16)
  669. ball[3] = eball(VIRTUAL_WIDTH / 1.8, VIRTUAL_HEIGHT / 2 - 2, 16, 16)
  670. ball[4] = eball(VIRTUAL_WIDTH / 2.2, VIRTUAL_HEIGHT / 2 - 2, 16, 16)
  671. ball[5] = eball(VIRTUAL_WIDTH / 2.1, VIRTUAL_HEIGHT / 2 - 2, 16, 16)
  672. myscreen = fullScreener(RESOLUTION_SET, isFullscreen, DIFFERENCE_X, DIFFERENCE_Y)
  673. mymenu = mainMenu()
  674. ballSpeed = 200
  675. ballDX = math.random(2) == 1 and 100 or -100
  676. ballDY = math.random(-50, 50)
  677. gameState = "animation"
  678. end
  679. t = 0
  680. shakeDuration = 0
  681. shakeMagnitude = 1
  682. function startShake(duration, magnitude)
  683. t, shakeDuration, shakeMagnitude = 0, duration or 1, magnitude or 5
  684. end
  685. function displayFPS()
  686. --love.window.setTitle(love.timer.getFPS())
  687. love.window.setTitle(globalState .. " " .. gameState)
  688. if love.keyboard.isDown("space") then
  689. player1nukescore = 200
  690. player1score = player1score + 0.2
  691. player2nukescore = 200
  692. end
  693. end
  694. function speedControl()
  695. if (ballSpeed > maxspeed and gameState == "play") then
  696. ballSpeed = maxspeed
  697. end
  698. end
  699. function love.update(dt)
  700. --print("IMPORTANT!!!!!" .. globalState .. gameState)
  701. staticanimatorcounter(dt)
  702. if gameState == "chooseIP" then
  703. checkCurrentServer(dt)
  704. end
  705. musicController('norm', 1)
  706. if debug then
  707. displayFPS()
  708. end
  709. if globalState == "base" then
  710. basegame(dt)
  711. end
  712. if globalState == "menu" then
  713. debugCheck(dt)
  714. end
  715. if globalState == "nettest" then
  716. --print("Confcode: " .. confirmation)
  717. if confirmation == "N" then
  718. basegame(dt)
  719. end
  720. nettest(dt)
  721. end
  722. if globalState == "clienttest" then
  723. ts = ts + dt
  724. if confirmation == "N" then
  725. lastSentKeyP1 = lastSentKeyClient
  726. clientsBaseGame(dt)
  727. end
  728. clienttest(dt)
  729. end
  730. end
  731. serverinit = false
  732. datawaspassedtimer = 0
  733. clientinit = false
  734. function love.textinput(t)
  735. if gameState == "chooseIP" then
  736. IP = IP .. t
  737. end
  738. end
  739. function nettest(dt)
  740. if serverinit == false then
  741. local socket = require "socket"
  742. local address, port = IP, 12345
  743. print(address)
  744. udp = socket.udp()
  745. udp:setpeername(address, port)
  746. udp:settimeout(0)
  747. serverinit = true
  748. end
  749. for i = 1, maxBalls do
  750. ts = ts + dt
  751. if ts > updaterate then
  752. udp:send(tostring(lastSentKey) ..
  753. '|' .. tostring(ball[1].dy) ..
  754. '|' .. tostring(player2.y) ..
  755. '|' .. tostring(player1.y) ..
  756. '|' .. tostring(player1score) ..
  757. '|' .. tostring(player2score) ..
  758. '|' .. tostring(player1nukescore) ..
  759. '|' .. tostring(player2nukescore) ..
  760. '|' .. tostring(ball[1].x) ..
  761. '|' .. tostring(ball[1].y) ..
  762. '|' .. gameState ..
  763. '|' .. tostring(ball[1].dx) ..
  764. '|' .. tostring(ballSpeed) ..
  765. '|' .. tostring(paddle_SPEED) ..
  766. "|HOST")
  767. ts = 0
  768. end
  769. end
  770. local data
  771. local datanumtest = 0
  772. local datawaspassed = false
  773. repeat
  774. datanumtest = datanumtest + 1
  775. print("LATENCY: " .. tostring(datanumtest))
  776. data = udp:receive()
  777. if data then
  778. datawaspassed = true
  779. print("ReceivedINFO: " .. data)
  780. confirmation = "N"
  781. local p = split(data, '|')
  782. if p[15] then
  783. if tonumber(p[16]) > 90 then
  784. confirmation = "L"
  785. end
  786. if p[15] ~= "CLIENT" then
  787. confirmation = "U"
  788. end
  789. elseif p[1] == "RESPONSE" then
  790. if p[2] == "1" then
  791. elseif p[2] == "2" then
  792. elseif p[2] == "3" then
  793. end
  794. else
  795. confirmation = "U"
  796. end
  797. if ball[1].disabled and ball[1].x > 20 and ball[1].x < VIRTUAL_WIDTH - 20 then
  798. ball[1].disabled = false
  799. print("illegal disabling")
  800. end
  801. if (ball[1].x > VIRTUAL_WIDTH/2) then
  802. if tonumber(p[9]) > VIRTUAL_WIDTH/2 then
  803. die = tonumber(p[2])
  804. lastSentKeyClient,
  805. ball[1].dy,
  806. player2.y,
  807. player1score,
  808. player2score,
  809. player1nukescore,
  810. player2nukescore,
  811. ball[1].x,
  812. ball[1].y,
  813. gameState,
  814. ball[1].dx,
  815. ballSpeed,
  816. 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])
  817. print("ACCEPTED")
  818. else
  819. print("DECLINED")
  820. end
  821. else
  822. if tonumber(p[9]) > VIRTUAL_WIDTH/2 then
  823. die = tonumber(p[2])
  824. lastSentKeyClient,
  825. ball[1].dy,
  826. player2.y,
  827. player1score,
  828. player2score,
  829. player1nukescore,
  830. player2nukescore,
  831. ball[1].x,
  832. ball[1].y,
  833. gameState,
  834. ball[1].dx,
  835. ballSpeed,
  836. 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])
  837. print("ACCEPTED")
  838. else
  839. print("ENFORCED" .. ball[1].x .. " " .. ball[1].dx)
  840. lastSentKeyClient = p[1]
  841. player2.y = tonumber(p[4])
  842. end
  843. end
  844. end
  845. until not data
  846. if not datawaspassed then
  847. datawaspassedtimer = datawaspassedtimer + 1
  848. if datawaspassedtimer > 5 then
  849. confirmation = "D"
  850. datawaspassedtimer = 0
  851. end
  852. else
  853. datawaspassedtimer = 0
  854. end
  855. end
  856. function clienttest(dt)
  857. if clientinit == false then
  858. local socket = require "socket"
  859. local address, port = IP, 12345
  860. udp = socket.udp()
  861. udp:setpeername(address, port)
  862. udp:settimeout(0)
  863. clientinit = true
  864. end
  865. ts = ts + dt
  866. if ts > updaterate then
  867. udp:send(tostring(lastSentKey) ..
  868. '|' .. tostring(ball[1].dy) ..
  869. '|' .. tostring(player1.y) ..
  870. '|' .. tostring(player2.y) ..
  871. '|' .. tostring(player1score) ..
  872. '|' .. tostring(player2score) ..
  873. '|' .. tostring(player1nukescore) ..
  874. '|' .. tostring(player2nukescore) ..
  875. '|' .. tostring(ball[1].x) ..
  876. '|' .. tostring(ball[1].y) ..
  877. '|' .. gameState ..
  878. '|' .. tostring(ball[1].dx) ..
  879. '|' .. tostring(ballSpeed) ..
  880. '|' .. tostring(paddle_SPEED) ..
  881. "|CLIENT")
  882. ts = 0
  883. end
  884. local data
  885. local datanumtest = 0
  886. local datawaspassed = false
  887. repeat
  888. datanumtest = datanumtest + 1
  889. print("LATENCY: " .. tostring(datanumtest))
  890. data = udp:receive()
  891. if data then
  892. print("RECEIVED DATA: " .. data)
  893. datawaspassed = true
  894. print("SENT TO SERVER:" .. lastSentKey)
  895. confirmation = "N"
  896. local p = split(data, '|')
  897. if p[15] then
  898. if p[15] ~= "HOST" then
  899. confirmation = "U"
  900. end
  901. if tonumber(p[16]) > 90 then
  902. confirmation = "L"
  903. end
  904. for i = 1, maxBalls do
  905. local die = tonumber(p[2])
  906. if (ball[i].x <= VIRTUAL_WIDTH/2) then
  907. if tonumber(p[9]) <= VIRTUAL_WIDTH/2 then
  908. lastSentKeyClient, ball[i].dy, player1.y, player1score, player2score, player1nukescore, player2nukescore, ball[i].x, ball[i].y, gameState, ball[i].dx, ballSpeed, 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])
  909. print("ACCEPTED")
  910. else
  911. print("DECLINED")
  912. end
  913. else
  914. if tonumber(p[9]) <= VIRTUAL_WIDTH/2 then
  915. lastSentKeyClient, ball[i].dy, player1.y, player1score, player2score, player1nukescore, player2nukescore, ball[i].x, ball[i].y, gameState, ball[i].dx, ballSpeed, 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])
  916. print("REROUTED")
  917. else lastSentKeyClient = p[1]
  918. player1.y = tonumber(p[4])
  919. print("ENFORCED")
  920. end
  921. end
  922. end
  923. else
  924. confirmation = "U"
  925. end
  926. end
  927. print("GOT: " .. lastSentKeyClient)
  928. until not data
  929. if not datawaspassed then
  930. datawaspassedtimer = datawaspassedtimer + 1
  931. if datawaspassedtimer > 5 then
  932. confirmation = "D"
  933. datawaspassedtimer = 0
  934. end
  935. else
  936. datawaspassedtimer = 0
  937. end
  938. end
  939. function wallbreaker(x, y)
  940. if (gameState == "editor") then
  941. for i, wall in ipairs(walls) do
  942. if math.abs(wall.wallx - x) < 10 and math.abs(wall.wally - y) < 10 then
  943. table.remove(walls, i)
  944. end
  945. end
  946. end
  947. end
  948. function hardmanager(diff)
  949. selecting = 1
  950. if (diff == "easy") then
  951. INDIC[1] = ">"
  952. AGAINST_AI = 1
  953. AI_SPEED = ballSet / 10
  954. AI_STRIKEMOD = 100
  955. AI_NUKEMOD = 1000
  956. AI_LEVEL = 350
  957. difficultyl = 200
  958. selecting = 0
  959. gameState = "1serve"
  960. globalState = "base"
  961. end
  962. if (diff == "normal") then
  963. INDIC[2] = ">"
  964. AI_SPEED = ballSet / 10
  965. AI_LEVEL = 500
  966. AI_NUKEMOD = 250
  967. AI_STRIKEMOD = 60
  968. AGAINST_AI = 1
  969. difficultyl = 300
  970. selecting = 0
  971. gameState = "1serve"
  972. globalState = "base"
  973. end
  974. if (diff == "hard") then
  975. INDIC[3] = ">"
  976. AI_SPEED = ballSpeed * 1.1 + 50
  977. AI_SPEED = AI_SPEED / 10
  978. AI_LEVEL = 700
  979. AI_NUKEMOD = 200
  980. AI_STRIKEMOD = 20
  981. selecting = 0
  982. difficultyl = 350
  983. AGAINST_AI = 1
  984. gameState = "1serve"
  985. globalState = "base"
  986. end
  987. if (diff == "smart") then
  988. INDIC[3] = ">"
  989. AI_SPEED = ballSpeed * 1.1 + 50
  990. AI_SPEED = AI_SPEED / 10
  991. AI_LEVEL = 1500
  992. AI_NUKEMOD = 200
  993. AI_STRIKEMOD = 20
  994. selecting = 0
  995. difficultyl = 350
  996. AGAINST_AI = 1
  997. gameState = "1serve"
  998. globalState = "base"
  999. end
  1000. if (diff == "practice") then
  1001. INDIC[3] = ">"
  1002. AI_SPEED = ballSpeed * 500 + 50
  1003. AI_SPEED = AI_SPEED / 10
  1004. AI_LEVEL = 700
  1005. AI_NUKEMOD = 9000000000
  1006. AI_STRIKEMOD = 90000000
  1007. selecting = 0
  1008. difficultyl = 350
  1009. AGAINST_AI = 1
  1010. gameState = "base"
  1011. end
  1012. end
  1013. function dangerChecker() --CHECK IF CONTROLS ARE DUPLICATING
  1014. if (p1control.up == p1control.down) then
  1015. danger = "1up"
  1016. danger2 = "1down"
  1017. elseif (p1control.up == p1control.super) then
  1018. danger = "1up"
  1019. danger2 = "1special"
  1020. elseif (p1control.up == p1control.counter) then
  1021. danger = "1up"
  1022. danger2 = "1ct"
  1023. elseif (p1control.down == p1control.super) then
  1024. danger = "1down"
  1025. danger2 = "1special"
  1026. elseif (p1control.down == p1control.counter) then
  1027. danger = "1ct"
  1028. danger2 = "1down"
  1029. elseif (p1control.super == p1control.counter) then
  1030. danger = "1special"
  1031. danger2 = "1ct"
  1032. elseif (p2control.down == p2control.up) then
  1033. danger = "2down"
  1034. danger2 = "2up"
  1035. elseif (p2control.down == p2control.super) then
  1036. danger = "2down"
  1037. danger2 = "2special"
  1038. elseif (p2control.down == p2control.counter) then
  1039. danger = "2down"
  1040. danger2 = "2ct"
  1041. elseif (p2control.up == p2control.super) then
  1042. danger = "2up"
  1043. danger2 = "2special"
  1044. elseif (p2control.up == p2control.counter) then
  1045. danger = "2ct"
  1046. danger2 = "2up"
  1047. elseif (p2control.super == p2control.counter) then
  1048. danger = "2special"
  1049. danger2 = "2ct"
  1050. else
  1051. danger = "none"
  1052. danger2 = "none"
  1053. end
  1054. end
  1055. function love.keypressed(key)
  1056. lastSentKey = key
  1057. if gameState == "chooseIP" then
  1058. if key == "backspace" then
  1059. -- get the byte offset to the last UTF-8 character in the string.
  1060. local byteoffset = utf8.offset(IP, -1)
  1061. if byteoffset then
  1062. -- remove the last UTF-8 character.
  1063. -- string.sub operates on bytes rather than UTF-8 characters, so we couldn't do string.sub(text, 1, -2).
  1064. IP = string.sub(IP, 1, byteoffset - 1)
  1065. end
  1066. end
  1067. end
  1068. if gameState == "assign" then
  1069. if (req == "p1up") then
  1070. p1control.up = key
  1071. currentKey = key
  1072. --love.window.setTitle(key)
  1073. gameState = "controlSettings"
  1074. end
  1075. if (req == "p2up") then
  1076. p2control.up = key
  1077. currentKey = key
  1078. --love.window.setTitle(key)
  1079. gameState = "controlSettings"
  1080. end
  1081. if (req == "p1down") then
  1082. p1control.down = key
  1083. currentKey = key
  1084. --love.window.setTitle(key)
  1085. gameState = "controlSettings"
  1086. end
  1087. if (req == "p2down") then
  1088. p2control.down = key
  1089. currentKey = key
  1090. -- love.window.setTitle(key)
  1091. gameState = "controlSettings"
  1092. end
  1093. if (req == "p1super") then
  1094. p1control.super = key
  1095. currentKey = key
  1096. -- love.window.setTitle(key)
  1097. gameState = "controlSettings"
  1098. end
  1099. if (req == "p2super") then
  1100. p2control.super = key
  1101. currentKey = key
  1102. -- love.window.setTitle(key)
  1103. gameState = "controlSettings"
  1104. end
  1105. if (req == "p1ct") then
  1106. p1control.counter = key
  1107. currentKey = key
  1108. -- love.window.setTitle(key)
  1109. gameState = "controlSettings"
  1110. end
  1111. if (req == "p2ct") then
  1112. p2control.counter = key
  1113. currentKey = key
  1114. --love.window.setTitle(key)
  1115. gameState = "controlSettings"
  1116. end
  1117. end
  1118. if key == "escape" then
  1119. TEXT = "Escape Key"
  1120. love.event.quit()
  1121. elseif key == "enter" or key == "return" then
  1122. if gameState == "start" then
  1123. resettinggenius()
  1124. gameState = "menu"
  1125. globalState = "menu"
  1126. hardmanager()
  1127. elseif (gameState == "done") then
  1128. if (player1score > player2score) then
  1129. gameState = "2serve"
  1130. potentialnuke1 = 0
  1131. potentialnuke2 = 0
  1132. striken = 0
  1133. if (nuckemodactive == 0) then
  1134. areanuclear = 0
  1135. nuclearanimation = 3
  1136. end
  1137. potentialstrike1 = 0
  1138. potentialstrike2 = 0
  1139. player1nukescore = 0
  1140. player2nukescore = 0
  1141. else
  1142. gameState = "1serve"
  1143. resettinggenius()
  1144. for i = 1, maxBalls do
  1145. ball[i]:reset(i, 1)
  1146. end
  1147. end
  1148. else
  1149. gameState = "menu"
  1150. globalState = "menu"
  1151. if (love.math.random(0, 10) == 1) then
  1152. TEXT = "Nuclear Ching Chong"
  1153. else
  1154. TEXT = "Nuclear Pong"
  1155. end
  1156. resettinggenius()
  1157. for i = 1, maxBalls do
  1158. ball[i]:reset(i)
  1159. end
  1160. end
  1161. end
  1162. end
  1163. function love.keyreleased(key)
  1164. currentKey = " "
  1165. if lastSentKey == key then
  1166. lastSentKey = "g"
  1167. end
  1168. end
  1169. function speedSetter(requesttype)
  1170. if (requesttype == "ball") then
  1171. if (ballSet > 550) then
  1172. ballSet = 0
  1173. paddle_SPEED = 0
  1174. else
  1175. ballSet = ballSet + 50
  1176. paddle_SPEED = paddle_SPEED + 5
  1177. end
  1178. ballSpeed = ballSet
  1179. end
  1180. if (requesttype == "snc") then
  1181. synctype = synctype + 1
  1182. if (synctype > 1) then
  1183. synctype = 0
  1184. end
  1185. if synctype == 0 then
  1186. synctext = "Independent"
  1187. end
  1188. if synctype == 1 then
  1189. synctext = "Synchronised"
  1190. end
  1191. end
  1192. if (requesttype == "nuclearmod") then
  1193. nuckemodactive = nuckemodactive + 1
  1194. if (nuckemodactive > 1) then
  1195. nuckemodactive = 0
  1196. end
  1197. if (nuckemodactive == 0) then
  1198. areanuclear = 0
  1199. nuclearanimation = 3
  1200. ballSet = 200
  1201. TEXT = "Nuclear Pong"
  1202. synctype = 0
  1203. maxspeed = 700
  1204. synctext = "Independent"
  1205. paddle_SPEED = ballSet / 10
  1206. AI_SPEED = ballSet / 10
  1207. end
  1208. if (nuckemodactive == 1) then
  1209. areanuclear = 1
  1210. ballSet = 2000
  1211. maxspeed = 2000
  1212. paddle_SPEED = ballSet / 10
  1213. AI_SPEED = ballSet / 10
  1214. synctext = "death is imminent"
  1215. end
  1216. ballSpeed = ballSet
  1217. end
  1218. if (requesttype == "practice") then
  1219. if (ballSpeed > 999) then
  1220. ballSpeed = 200
  1221. ballSet = 200
  1222. end
  1223. if (ballSpeed > 799) then
  1224. prtext = "Insane"
  1225. maxBalls = 5
  1226. elseif ballSpeed > 599 then
  1227. prtext = "Hard"
  1228. maxBalls = 4
  1229. elseif ballSpeed > 399 then
  1230. prtext = "Normal"
  1231. maxBalls = 3
  1232. elseif ballSpeed > 199 then
  1233. prtext = "Easy"
  1234. maxBalls = 3
  1235. end
  1236. ballSpeed = ballSpeed + 200
  1237. ballSet = ballSet + 200
  1238. end
  1239. if (requesttype == "reset") then
  1240. ballSpeed = 200
  1241. ballSet = 200
  1242. synctype = 0
  1243. prtext = "Easy"
  1244. maxBalls = 1
  1245. end
  1246. if (requesttype == "pc") then
  1247. if (playerCount == 2) then
  1248. playerCount = 1
  1249. playertext = "1v1"
  1250. elseif (playerCount == 1) then
  1251. playerCount = playerCount + 1
  1252. player3.x = player1.x + VIRTUAL_WIDTH / 2
  1253. player3.y = player3.y
  1254. playertext = "2v2"
  1255. end
  1256. end
  1257. if (requesttype == "ballz") then
  1258. if (maxBalls > 1) then
  1259. --love.window.setTitle("more than 4")
  1260. maxBalls = 1
  1261. else
  1262. maxBalls = maxBalls + 1
  1263. end
  1264. end
  1265. if requesttype == "ptw" then
  1266. if ptw == 10 then
  1267. ptw = 1
  1268. else
  1269. ptw = ptw + 1
  1270. end
  1271. end
  1272. end
  1273. function gameModeChanger()
  1274. if (gameState == "gameMode") then
  1275. local button_width = VIRTUAL_WIDTH * (1 / 3)
  1276. local BUTTON_HEIGHT = 50
  1277. local margin = 20
  1278. local hot = false
  1279. local cursor_y = 0
  1280. local total_height = (BUTTON_HEIGHT + margin) * #buttons
  1281. for i, button in ipairs(modeSelectorButtons) do
  1282. button.last = button.now
  1283. local bx = (VIRTUAL_WIDTH * 0.5) - (button_width * 0.5)
  1284. local by = (VIRTUAL_HEIGHT * 0.5) - (total_height * 0.5) + cursor_y
  1285. local color = {255, 255, 255, 255}
  1286. local mx, my = love.mouse.getPosition()
  1287. mx = mx * DIFFERENCE_X
  1288. my = my * DIFFERENCE_Y
  1289. hot = (mx > bx and mx < bx + button_width and my > by and my < by + BUTTON_HEIGHT) and i
  1290. if (hot == i) then
  1291. color = {10, 10, 0, 255}
  1292. end
  1293. button.now = love.mouse.isDown(1)
  1294. if button.now and not button.last and hot == i then
  1295. love.graphics.setColor(0, 0, 0, 1)
  1296. love.graphics.rectangle("fill", 0, 0, VIRTUAL_WIDTH, VIRTUAL_HEIGHT)
  1297. sounds["wallhit"]:play()
  1298. button.fn()
  1299. end
  1300. love.graphics.setColor(unpack(color))
  1301. love.graphics.rectangle("fill", bx, by, button_width, BUTTON_HEIGHT)
  1302. love.graphics.setColor(0, 0, 0, 255)
  1303. local textW = smallfont:getWidth(button.text)
  1304. local textH = smallfont:getHeight(button.text)
  1305. love.graphics.print(button.text, smallfont, VIRTUAL_WIDTH * 0.5 - textW * 0.5, by + textH * 0.5)
  1306. love.graphics.setColor(255, 255, 255, 255)
  1307. cursor_y = cursor_y + (BUTTON_HEIGHT + margin)
  1308. end
  1309. end
  1310. if (gameState == "multiMode") then
  1311. local button_width = VIRTUAL_WIDTH * (1 / 3)
  1312. local BUTTON_HEIGHT = 50
  1313. local margin = 20
  1314. local hot = false
  1315. local cursor_y = 0
  1316. local total_height = (BUTTON_HEIGHT + margin) * #buttons
  1317. for i, button in ipairs(playerCountButtons) do
  1318. button.last = button.now
  1319. local bx = (VIRTUAL_WIDTH * 0.5) - (button_width * 0.5)
  1320. local by = (VIRTUAL_HEIGHT * 0.3) - (total_height * 0.5) + cursor_y
  1321. if (button.text == "Play") then
  1322. by = by + by / 1.8
  1323. end
  1324. local color = {255, 255, 255, 255}
  1325. local mx, my = love.mouse.getPosition()
  1326. mx = mx * DIFFERENCE_X
  1327. my = my * DIFFERENCE_Y
  1328. hot = (mx > bx and mx < bx + button_width and my > by and my < by + BUTTON_HEIGHT) and i
  1329. if (hot == i) then
  1330. if (button.text == "Play") then
  1331. color = {0 / 255, 255 / 255, 0 / 255, 255}
  1332. else
  1333. color = {10, 10, 0, 255}
  1334. end
  1335. end
  1336. button.now = love.mouse.isDown(1)
  1337. if button.now and not button.last and hot == i then
  1338. love.graphics.setColor(0, 0, 0, 1)
  1339. love.graphics.rectangle("fill", 0, 0, VIRTUAL_WIDTH, VIRTUAL_HEIGHT)
  1340. sounds["wallhit"]:play()
  1341. if button.text == "Ball Speed: " and nuckemodactive == 1 then
  1342. else
  1343. button.fn()
  1344. end
  1345. end
  1346. love.graphics.setColor(unpack(color))
  1347. love.graphics.rectangle("fill", bx, by, button_width, BUTTON_HEIGHT)
  1348. love.graphics.setColor(0, 0, 0, 255)
  1349. local textW = smallfont:getWidth(button.text)
  1350. local textH = smallfont:getHeight(button.text)
  1351. if (button.text == "1v1") then
  1352. love.graphics.print(playertext, smallfont, VIRTUAL_WIDTH * 0.5 - textW * 0.5, by + textH * 0.5)
  1353. elseif button.text == "snc" then
  1354. if (nuckemodactive == 1) then
  1355. love.graphics.setColor(1, 0, 0, 1)
  1356. love.graphics.print(synctext, smallfont, VIRTUAL_WIDTH * 0.5 - textW * 0.5, by + textH * 0.5)
  1357. love.graphics.setColor(1, 1, 1, 1)
  1358. love.graphics.print(synctext, smallfont, VIRTUAL_WIDTH * 0.5 - textW * 0.5, by + textH * 0.5)
  1359. love.graphics.setColor(0, 0, 0, 1)
  1360. else
  1361. --
  1362. love.graphics.print(synctext, smallfont, VIRTUAL_WIDTH * 0.45 - textW * 0.5, by + textH * 0.5)
  1363. end
  1364. elseif (button.text == "ballCount") then
  1365. love.graphics.print(
  1366. "Ball Count: " .. maxBalls,
  1367. smallfont,
  1368. VIRTUAL_WIDTH * 0.5 - textW * 0.5,
  1369. by + textH * 0.5
  1370. )
  1371. elseif (button.text == "Ball Speed: ") then
  1372. if (nuckemodactive == 1) then
  1373. love.graphics.setColor(1, 0, 0, 1)
  1374. love.graphics.print(
  1375. "shaitan machina",
  1376. smallfont,
  1377. VIRTUAL_WIDTH * 0.5 - textW * 0.5,
  1378. by + textH * 0.5
  1379. )
  1380. love.graphics.setColor(1, 1, 1, 1)
  1381. love.graphics.print(
  1382. "shaitan machina",
  1383. smallfont,
  1384. VIRTUAL_WIDTH * 0.5 - textW * 0.5,
  1385. by + textH * 0.5
  1386. )
  1387. love.graphics.setColor(0, 0, 0, 1)
  1388. else
  1389. love.graphics.print(
  1390. button.text .. ballSet,
  1391. smallfont,
  1392. VIRTUAL_WIDTH * 0.5 - textW * 0.5,
  1393. by + textH * 0.5
  1394. )
  1395. end
  1396. elseif button.text == "ptw" then
  1397. love.graphics.print(
  1398. "Points to Win: " .. ptw,
  1399. smallfont,
  1400. VIRTUAL_WIDTH * 0.5 - textW * 1.5,
  1401. by + textH * 0.5
  1402. )
  1403. else
  1404. love.graphics.print(button.text, smallfont, VIRTUAL_WIDTH * 0.5 - textW * 0.5, by + textH * 0.5)
  1405. end
  1406. love.graphics.setColor(255, 255, 255, 255)
  1407. cursor_y = cursor_y + (BUTTON_HEIGHT + margin)
  1408. end
  1409. end
  1410. end
  1411. function love.draw(dt)
  1412. simpleScale.set()
  1413. baseDraw()
  1414. if (globalState == "nettest" or globalState == "clienttest") and confirmation == "D" then
  1415. love.graphics.clear(50 / 255, 50 / 255, 50 / 255, 255)
  1416. love.graphics.printf("WAIT FOR OPPONENT", 0, VIRTUAL_HEIGHT / 2, VIRTUAL_WIDTH, "center")
  1417. end
  1418. if (globalState == "nettest" or globalState == "clienttest") and confirmation == "U" then
  1419. love.graphics.clear(50 / 255, 50 / 255, 50 / 255, 255)
  1420. love.graphics.printf("LOBBY FULL OR WRONG MODE CHOSEN", 0, VIRTUAL_HEIGHT / 2, VIRTUAL_WIDTH, "center")
  1421. end
  1422. if (globalState == "nettest" or globalState == "clienttest") and confirmation == "L" then
  1423. love.graphics.clear(50 / 255, 50 / 255, 50 / 255, 255)
  1424. love.graphics.printf("POOR CONNECTION TO SERVER", 0, VIRTUAL_HEIGHT / 2, VIRTUAL_WIDTH, "center")
  1425. end
  1426. simpleScale.unSet()
  1427. end
  1428. --Check if controls are duplicating
  1429. function controllerSer()
  1430. for i = 1, maxBalls do
  1431. if (ball[i].dy == 0) then
  1432. hitNum[i] = hitNum[i] + 1
  1433. if hitNum[i] >= 10 then
  1434. ball[i].dy = 1
  1435. hitNum[i] = 0
  1436. end
  1437. else
  1438. hitNum[i] = 0
  1439. end
  1440. end
  1441. end
  1442. function palleteController() --!!!!LEGACY CODE, MIGRATED TO Paddle.lua!!!!
  1443. if (areanuclear == 0) then
  1444. player1.RED = 1
  1445. player1.GREEN = 1
  1446. player1.BLUE = 1
  1447. end
  1448. if (areanuclear == 0) then
  1449. player2.RED = 1
  1450. player2.GREEN = 1
  1451. player2.BLUE = 1
  1452. end
  1453. if (areanuclear == 1) then
  1454. player1.RED = 0
  1455. player1.GREEN = 0
  1456. player1.BLUE = 0
  1457. end
  1458. if (areanuclear == 1) then
  1459. player2.RED = 0
  1460. player2.GREEN = 0
  1461. player2.BLUE = 0
  1462. end
  1463. end
  1464. function love.wheelmoved(x, y)
  1465. if (y < 0 and wall1width > 0) then
  1466. wall1width = wall1width - 5
  1467. elseif y > 0 and wall1width < 900 then
  1468. wall1width = wall1width + 5
  1469. end
  1470. end
  1471. function serveBot() --THIS IS USED TO CHANGE TEXT/BALL DIRECTION ON DIFFERENT SERVES
  1472. --print("servebot called")
  1473. if (gameState == "1serve") then
  1474. updateTEXT = ""
  1475. if (gameMode ~= "practice") then
  1476. TEXT = "PLAYER 1, serve!(q)"
  1477. end
  1478. if ((globalState ~= "clienttest" and love.keyboard.isDown("q")) or (globalState == "clienttest" and lastSentKeyP1 == "q")) then
  1479. TEXT = "Lets Begin!"
  1480. ball_DIR = 1
  1481. for i = 1, maxBalls do
  1482. ball[i]:reset(i, 1)
  1483. end
  1484. gameState = "play"
  1485. end
  1486. end
  1487. if (gameState == "2serve") then
  1488. TEXT = "PLAYER 2, serve!(p)"
  1489. if (AGAINST_AI == 1) then
  1490. TEXT = ""
  1491. ball_DIR = -1
  1492. for i = 1, maxBalls do
  1493. ball[i]:reset(i, 2)
  1494. end
  1495. gameState = "play"
  1496. end
  1497. if (((globalState == "nettest" and lastSentKeyClient == "p") or ((globalState ~= "nettest") and love.keyboard.isDown("p")))and AGAINST_AI == 0) then
  1498. TEXT = "Lets Begin"
  1499. ball_DIR = -1
  1500. for i = 1, maxBalls do
  1501. ball[i]:reset(i, 2)
  1502. end
  1503. --love.window.setTitle("An atttttttt")
  1504. gameState = "play"
  1505. end
  1506. end
  1507. end
  1508. function mapChanger()
  1509. if (gameState == "editor") then
  1510. MAP_TYPE = 2
  1511. end
  1512. if (MAP_TYPE > 2) then
  1513. MAP_TYPE = 0
  1514. end
  1515. end
  1516. function resolutionChanger()
  1517. if (RESOLUTION_SET > 1) then
  1518. RESOLUTION_SET = 0
  1519. end
  1520. if (RESOLUTION_SET == 0) then
  1521. if (isFullscreen == 1) then
  1522. DIFFERENCE_X = 1
  1523. DIFFERENCE_Y = 1
  1524. simpleScale.updateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, {fullscreen = false})
  1525. isFullscreen = 0
  1526. end
  1527. end
  1528. if (RESOLUTION_SET == 1) then
  1529. if (isFullscreen == 0) then
  1530. simpleScale.updateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, {fullscreen = true})
  1531. local newWidth = love.graphics.getWidth()
  1532. local newHeight = love.graphics.getHeight()
  1533. DIFFERENCE_X = VIRTUAL_WIDTH / newWidth
  1534. DIFFERENCE_Y = VIRTUAL_HEIGHT / newHeight
  1535. isFullscreen = 1
  1536. end
  1537. end
  1538. end
  1539. function resettinggenius()
  1540. maxBalls = 1
  1541. for i = 1, maxBalls do
  1542. ball[i]:reset(i)
  1543. end
  1544. paddle_SPEED = 20
  1545. nuclearanimation = 3
  1546. timeIsSlow = false
  1547. timeIsSlow2 = false
  1548. originalSpeed = 200
  1549. gameState = "menu"
  1550. globalState = "menu"
  1551. gameMode = "normal"
  1552. player1.height = 100
  1553. player2.height = 100
  1554. ballSet = 200
  1555. ballSpeed = ballSet
  1556. player2.GREEN = 255
  1557. player2.BLUE = 255
  1558. player1.GREEN = 255
  1559. player1.BLUE = 255
  1560. player1score = 0
  1561. player2score = 0
  1562. potentialnuke1 = 0
  1563. potentialnuke2 = 0
  1564. striken = 0
  1565. areanuclear = 0
  1566. potentialstrike1 = 0
  1567. potentialstrike2 = 0
  1568. player1nukescore = 0
  1569. player2nukescore = 0
  1570. player1reverbav = 0
  1571. player2reverbav = 0
  1572. selecting = 0
  1573. AGAINST_AI = 0
  1574. end
  1575. function love.mousereleased(x, y, button)
  1576. love.keyboard.mouseisReleased = true
  1577. if (gameState == "editor") then
  1578. if (#walls < 1000 and button == 1 and blockinput ~= true) then
  1579. table.insert(walls, newWall(x * DIFFERENCE_X, y * DIFFERENCE_Y, 10, wall1width))
  1580. end
  1581. end
  1582. end
  1583. function ballsAlive()
  1584. for i = 1, maxBalls do
  1585. if ball[i].disabled == false then
  1586. print("Ball " .. i .. " is not disabled")
  1587. return true
  1588. end
  1589. end
  1590. return false
  1591. end
  1592. function split(s, delimiter)
  1593. result = {}
  1594. for match in (s..delimiter):gmatch("(.-)"..delimiter) do
  1595. table.insert(result, match)
  1596. end
  1597. return result
  1598. end
  1599. function checkCurrentServer(dt)
  1600. ts = ts + dt
  1601. local socket = require "socket"
  1602. local address, port = IP, 12345
  1603. udp = socket.udp()
  1604. udp:setpeername(address, port)
  1605. udp:settimeout(0)
  1606. if ts > updaterate then
  1607. print("sent ping")
  1608. udp:send("HELLO")
  1609. ts = 0
  1610. end
  1611. status = "offline"
  1612. local data
  1613. local datanumtest = 0
  1614. local datawaspassed = false
  1615. data = udp:receive()
  1616. repeat
  1617. datanumtest = datanumtest + 1
  1618. print("LATENCY: " .. tostring(datanumtest))
  1619. data = udp:receive()
  1620. if data then
  1621. datawaspassed = true
  1622. print("ReceivedINFO: " .. data)
  1623. local p = split(data, '|')
  1624. end
  1625. until not data
  1626. end