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

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