A pong clone, but with a twist!
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

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