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

main.lua 54 KiB

4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920
  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 == "selfhost" then
  726. --print("Confcode: " .. confirmation)
  727. if confirmation == "N" then
  728. globalState = "nettest"
  729. basegame(dt)
  730. end
  731. globalState = "selfhost"
  732. selfHost(dt)
  733. end
  734. if globalState == "clienttest" then
  735. ts = ts + dt
  736. if confirmation == "N" then
  737. lastSentKeyP1 = lastSentKeyClient
  738. clientsBaseGame(dt)
  739. end
  740. clienttest(dt)
  741. end
  742. end
  743. serverinit = false
  744. dserverinit = false
  745. datawaspassedtimer = 0
  746. clientinit = false
  747. function love.textinput(t)
  748. if gameState == "chooseIP" then
  749. IP = IP .. t
  750. end
  751. end
  752. function nettest(dt)
  753. if serverinit == false then
  754. local socket = require "socket"
  755. local address, port = IP, 12345
  756. print(address)
  757. udp = socket.udp()
  758. udp:setpeername(address, port)
  759. udp:settimeout(0)
  760. serverinit = true
  761. end
  762. for i = 1, maxBalls do
  763. ts = ts + dt
  764. if ts > updaterate then
  765. udp:send(tostring(lastSentKey) ..
  766. '|' .. tostring(ball[1].dy) ..
  767. '|' .. tostring(player2.y) ..
  768. '|' .. tostring(player1.y) ..
  769. '|' .. tostring(player1score) ..
  770. '|' .. tostring(player2score) ..
  771. '|' .. tostring(player1nukescore) ..
  772. '|' .. tostring(player2nukescore) ..
  773. '|' .. tostring(ball[1].x) ..
  774. '|' .. tostring(ball[1].y) ..
  775. '|' .. gameState ..
  776. '|' .. tostring(ball[1].dx) ..
  777. '|' .. tostring(ballSpeed) ..
  778. '|' .. tostring(paddle_SPEED) ..
  779. "|HOST")
  780. ts = 0
  781. end
  782. end
  783. local data
  784. local datanumtest = 0
  785. local datawaspassed = false
  786. repeat
  787. datanumtest = datanumtest + 1
  788. print("LATENCY: " .. tostring(datanumtest))
  789. data = udp:receive()
  790. if data then
  791. datawaspassed = true
  792. print("ReceivedINFO: " .. data)
  793. confirmation = "N"
  794. local p = split(data, '|')
  795. if p[15] then
  796. if tonumber(p[16]) > 90 then
  797. confirmation = "L"
  798. end
  799. if p[15] ~= "CLIENT" then
  800. confirmation = "U"
  801. end
  802. elseif p[1] == "RESPONSE" then
  803. if p[2] == "1" then
  804. elseif p[2] == "2" then
  805. elseif p[2] == "3" then
  806. end
  807. else
  808. confirmation = "U"
  809. end
  810. if ball[1].disabled and ball[1].x > 20 and ball[1].x < VIRTUAL_WIDTH - 20 then
  811. ball[1].disabled = false
  812. print("illegal disabling")
  813. end
  814. if (ball[1].x > VIRTUAL_WIDTH/2) then
  815. if tonumber(p[9]) > VIRTUAL_WIDTH/2 then
  816. die = tonumber(p[2])
  817. lastSentKeyClient,
  818. ball[1].dy,
  819. player2.y,
  820. player1score,
  821. player2score,
  822. player1nukescore,
  823. player2nukescore,
  824. ball[1].x,
  825. ball[1].y,
  826. gameState,
  827. ball[1].dx,
  828. ballSpeed,
  829. 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])
  830. print("ACCEPTED")
  831. else
  832. print("DECLINED")
  833. end
  834. else
  835. if tonumber(p[9]) > VIRTUAL_WIDTH/2 then
  836. die = tonumber(p[2])
  837. lastSentKeyClient,
  838. ball[1].dy,
  839. player2.y,
  840. player1score,
  841. player2score,
  842. player1nukescore,
  843. player2nukescore,
  844. ball[1].x,
  845. ball[1].y,
  846. gameState,
  847. ball[1].dx,
  848. ballSpeed,
  849. 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])
  850. print("ACCEPTED")
  851. else
  852. print("ENFORCED" .. ball[1].x .. " " .. ball[1].dx)
  853. lastSentKeyClient = p[1]
  854. player2.y = tonumber(p[4])
  855. end
  856. end
  857. end
  858. until not data
  859. if not datawaspassed then
  860. datawaspassedtimer = datawaspassedtimer + 1
  861. if datawaspassedtimer > 5 then
  862. confirmation = "D"
  863. datawaspassedtimer = 0
  864. end
  865. else
  866. datawaspassedtimer = 0
  867. end
  868. end
  869. function clienttest(dt)
  870. if clientinit == false then
  871. local socket = require "socket"
  872. local address, port = IP, 12345
  873. udp = socket.udp()
  874. udp:setpeername(address, port)
  875. udp:settimeout(0)
  876. clientinit = true
  877. end
  878. ts = ts + dt
  879. if ts > updaterate then
  880. udp:send(tostring(lastSentKey) ..
  881. '|' .. tostring(ball[1].dy) ..
  882. '|' .. tostring(player1.y) ..
  883. '|' .. tostring(player2.y) ..
  884. '|' .. tostring(player1score) ..
  885. '|' .. tostring(player2score) ..
  886. '|' .. tostring(player1nukescore) ..
  887. '|' .. tostring(player2nukescore) ..
  888. '|' .. tostring(ball[1].x) ..
  889. '|' .. tostring(ball[1].y) ..
  890. '|' .. gameState ..
  891. '|' .. tostring(ball[1].dx) ..
  892. '|' .. tostring(ballSpeed) ..
  893. '|' .. tostring(paddle_SPEED) ..
  894. "|CLIENT")
  895. ts = 0
  896. end
  897. local data
  898. local datanumtest = 0
  899. local datawaspassed = false
  900. repeat
  901. datanumtest = datanumtest + 1
  902. print("LATENCY: " .. tostring(datanumtest))
  903. data = udp:receive()
  904. if data then
  905. print("RECEIVED DATA: " .. data)
  906. datawaspassed = true
  907. print("SENT TO SERVER:" .. lastSentKey)
  908. confirmation = "N"
  909. local p = split(data, '|')
  910. if p[15] then
  911. if p[15] ~= "HOST" then
  912. confirmation = "U"
  913. end
  914. if tonumber(p[16]) > 90 then
  915. confirmation = "L"
  916. end
  917. for i = 1, maxBalls do
  918. local die = tonumber(p[2])
  919. if (ball[i].x <= VIRTUAL_WIDTH/2) then
  920. if tonumber(p[9]) <= VIRTUAL_WIDTH/2 then
  921. 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])
  922. print("ACCEPTED")
  923. else
  924. print("DECLINED")
  925. end
  926. else
  927. if tonumber(p[9]) <= VIRTUAL_WIDTH/2 then
  928. 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])
  929. print("REROUTED")
  930. else lastSentKeyClient = p[1]
  931. player1.y = tonumber(p[4])
  932. print("ENFORCED")
  933. end
  934. end
  935. end
  936. else
  937. confirmation = "U"
  938. end
  939. end
  940. print("GOT: " .. lastSentKeyClient)
  941. until not data
  942. if not datawaspassed then
  943. datawaspassedtimer = datawaspassedtimer + 1
  944. if datawaspassedtimer > 5 then
  945. confirmation = "D"
  946. datawaspassedtimer = 0
  947. end
  948. else
  949. datawaspassedtimer = 0
  950. end
  951. end
  952. function wallbreaker(x, y)
  953. if (gameState == "editor") then
  954. for i, wall in ipairs(walls) do
  955. if math.abs(wall.wallx - x) < 10 and math.abs(wall.wally - y) < 10 then
  956. table.remove(walls, i)
  957. end
  958. end
  959. end
  960. end
  961. function hardmanager(diff)
  962. selecting = 1
  963. if (diff == "easy") then
  964. INDIC[1] = ">"
  965. AGAINST_AI = 1
  966. AI_SPEED = ballSet
  967. AI_STRIKEMOD = 100
  968. AI_NUKEMOD = 1000
  969. AI_LEVEL = 350
  970. difficultyl = 200
  971. selecting = 0
  972. gameState = "1serve"
  973. globalState = "base"
  974. end
  975. if (diff == "normal") then
  976. INDIC[2] = ">"
  977. AI_SPEED = ballSet
  978. AI_LEVEL = 500
  979. AI_NUKEMOD = 250
  980. AI_STRIKEMOD = 60
  981. AGAINST_AI = 1
  982. difficultyl = 300
  983. selecting = 0
  984. gameState = "1serve"
  985. globalState = "base"
  986. end
  987. if (diff == "hard") then
  988. INDIC[3] = ">"
  989. AI_SPEED = ballSpeed * 1.1 + 50
  990. AI_LEVEL = 700
  991. AI_NUKEMOD = 200
  992. AI_STRIKEMOD = 20
  993. selecting = 0
  994. difficultyl = 350
  995. AGAINST_AI = 1
  996. gameState = "1serve"
  997. globalState = "base"
  998. end
  999. if (diff == "smart") then
  1000. INDIC[3] = ">"
  1001. AI_SPEED = ballSpeed * 1.1 + 50
  1002. AI_LEVEL = 1500
  1003. AI_NUKEMOD = 200
  1004. AI_STRIKEMOD = 20
  1005. selecting = 0
  1006. difficultyl = 350
  1007. AGAINST_AI = 1
  1008. gameState = "1serve"
  1009. globalState = "base"
  1010. end
  1011. if (diff == "practice") then
  1012. INDIC[3] = ">"
  1013. AI_SPEED = ballSpeed * 500 + 50
  1014. AI_LEVEL = 700
  1015. AI_NUKEMOD = 9000000000
  1016. AI_STRIKEMOD = 90000000
  1017. selecting = 0
  1018. difficultyl = 350
  1019. AGAINST_AI = 1
  1020. gameState = "base"
  1021. end
  1022. end
  1023. function dangerChecker() --CHECK IF CONTROLS ARE DUPLICATING
  1024. if (p1control.up == p1control.down) then
  1025. danger = "1up"
  1026. danger2 = "1down"
  1027. elseif (p1control.up == p1control.super) then
  1028. danger = "1up"
  1029. danger2 = "1special"
  1030. elseif (p1control.up == p1control.counter) then
  1031. danger = "1up"
  1032. danger2 = "1ct"
  1033. elseif (p1control.down == p1control.super) then
  1034. danger = "1down"
  1035. danger2 = "1special"
  1036. elseif (p1control.down == p1control.counter) then
  1037. danger = "1ct"
  1038. danger2 = "1down"
  1039. elseif (p1control.super == p1control.counter) then
  1040. danger = "1special"
  1041. danger2 = "1ct"
  1042. elseif (p2control.down == p2control.up) then
  1043. danger = "2down"
  1044. danger2 = "2up"
  1045. elseif (p2control.down == p2control.super) then
  1046. danger = "2down"
  1047. danger2 = "2special"
  1048. elseif (p2control.down == p2control.counter) then
  1049. danger = "2down"
  1050. danger2 = "2ct"
  1051. elseif (p2control.up == p2control.super) then
  1052. danger = "2up"
  1053. danger2 = "2special"
  1054. elseif (p2control.up == p2control.counter) then
  1055. danger = "2ct"
  1056. danger2 = "2up"
  1057. elseif (p2control.super == p2control.counter) then
  1058. danger = "2special"
  1059. danger2 = "2ct"
  1060. else
  1061. danger = "none"
  1062. danger2 = "none"
  1063. end
  1064. end
  1065. function love.keypressed(key)
  1066. lastSentKey = key
  1067. if gameState == "chooseIP" then
  1068. if key == "backspace" then
  1069. -- get the byte offset to the last UTF-8 character in the string.
  1070. local byteoffset = utf8.offset(IP, -1)
  1071. if byteoffset then
  1072. -- remove the last UTF-8 character.
  1073. -- string.sub operates on bytes rather than UTF-8 characters, so we couldn't do string.sub(text, 1, -2).
  1074. IP = string.sub(IP, 1, byteoffset - 1)
  1075. end
  1076. end
  1077. end
  1078. if gameState == "assign" then
  1079. if (req == "p1up") then
  1080. p1control.up = key
  1081. currentKey = key
  1082. --love.window.setTitle(key)
  1083. gameState = "controlSettings"
  1084. end
  1085. if (req == "p2up") then
  1086. p2control.up = key
  1087. currentKey = key
  1088. --love.window.setTitle(key)
  1089. gameState = "controlSettings"
  1090. end
  1091. if (req == "p1down") then
  1092. p1control.down = key
  1093. currentKey = key
  1094. --love.window.setTitle(key)
  1095. gameState = "controlSettings"
  1096. end
  1097. if (req == "p2down") then
  1098. p2control.down = key
  1099. currentKey = key
  1100. -- love.window.setTitle(key)
  1101. gameState = "controlSettings"
  1102. end
  1103. if (req == "p1super") then
  1104. p1control.super = key
  1105. currentKey = key
  1106. -- love.window.setTitle(key)
  1107. gameState = "controlSettings"
  1108. end
  1109. if (req == "p2super") then
  1110. p2control.super = key
  1111. currentKey = key
  1112. -- love.window.setTitle(key)
  1113. gameState = "controlSettings"
  1114. end
  1115. if (req == "p1ct") then
  1116. p1control.counter = key
  1117. currentKey = key
  1118. -- love.window.setTitle(key)
  1119. gameState = "controlSettings"
  1120. end
  1121. if (req == "p2ct") then
  1122. p2control.counter = key
  1123. currentKey = key
  1124. --love.window.setTitle(key)
  1125. gameState = "controlSettings"
  1126. end
  1127. end
  1128. if key == "escape" then
  1129. TEXT = "Escape Key"
  1130. love.event.quit()
  1131. elseif key == "enter" or key == "return" then
  1132. if gameState == "start" then
  1133. resettinggenius()
  1134. gameState = "menu"
  1135. globalState = "menu"
  1136. hardmanager()
  1137. elseif (gameState == "done") then
  1138. if (player1score > player2score) then
  1139. gameState = "2serve"
  1140. potentialnuke1 = 0
  1141. potentialnuke2 = 0
  1142. striken = 0
  1143. if (nuckemodactive == 0) then
  1144. areanuclear = 0
  1145. nuclearanimation = 3
  1146. end
  1147. potentialstrike1 = 0
  1148. potentialstrike2 = 0
  1149. player1nukescore = 0
  1150. player2nukescore = 0
  1151. else
  1152. gameState = "1serve"
  1153. resettinggenius()
  1154. for i = 1, maxBalls do
  1155. ball[i]:reset(i, 1)
  1156. end
  1157. end
  1158. else
  1159. gameState = "menu"
  1160. globalState = "menu"
  1161. if (love.math.random(0, 10) == 1) then
  1162. TEXT = "Nuclear Ching Chong"
  1163. else
  1164. TEXT = "Nuclear Pong"
  1165. end
  1166. resettinggenius()
  1167. for i = 1, maxBalls do
  1168. ball[i]:reset(i)
  1169. end
  1170. end
  1171. end
  1172. end
  1173. function love.keyreleased(key)
  1174. currentKey = " "
  1175. if lastSentKey == key then
  1176. lastSentKey = "g"
  1177. end
  1178. end
  1179. function speedSetter(requesttype)
  1180. if (requesttype == "ball") then
  1181. if (ballSet > 550) then
  1182. ballSet = 0
  1183. paddle_SPEED = 0
  1184. else
  1185. ballSet = ballSet + 50
  1186. paddle_SPEED = paddle_SPEED + 5
  1187. end
  1188. ballSpeed = ballSet
  1189. end
  1190. if (requesttype == "snc") then
  1191. synctype = synctype + 1
  1192. if (synctype > 1) then
  1193. synctype = 0
  1194. end
  1195. if synctype == 0 then
  1196. synctext = "Independent"
  1197. end
  1198. if synctype == 1 then
  1199. synctext = "Synchronised"
  1200. end
  1201. end
  1202. if (requesttype == "nuclearmod") then
  1203. nuckemodactive = nuckemodactive + 1
  1204. if (nuckemodactive > 1) then
  1205. nuckemodactive = 0
  1206. end
  1207. if (nuckemodactive == 0) then
  1208. areanuclear = 0
  1209. nuclearanimation = 3
  1210. ballSet = 200
  1211. TEXT = "Nuclear Pong"
  1212. synctype = 0
  1213. maxspeed = 700
  1214. synctext = "Independent"
  1215. paddle_SPEED = ballSet
  1216. AI_SPEED = ballSet
  1217. end
  1218. if (nuckemodactive == 1) then
  1219. areanuclear = 1
  1220. ballSet = 2000
  1221. maxspeed = 2000
  1222. paddle_SPEED = ballSet
  1223. AI_SPEED = ballSet
  1224. synctext = "death is imminent"
  1225. end
  1226. ballSpeed = ballSet
  1227. end
  1228. if (requesttype == "practice") then
  1229. if (ballSpeed > 999) then
  1230. ballSpeed = 200
  1231. ballSet = 200
  1232. end
  1233. if (ballSpeed > 799) then
  1234. prtext = "Insane"
  1235. maxBalls = 5
  1236. elseif ballSpeed > 599 then
  1237. prtext = "Hard"
  1238. maxBalls = 4
  1239. elseif ballSpeed > 399 then
  1240. prtext = "Normal"
  1241. maxBalls = 3
  1242. elseif ballSpeed > 199 then
  1243. prtext = "Easy"
  1244. maxBalls = 3
  1245. end
  1246. ballSpeed = ballSpeed + 200
  1247. ballSet = ballSet + 200
  1248. end
  1249. if (requesttype == "reset") then
  1250. ballSpeed = 200
  1251. ballSet = 200
  1252. synctype = 0
  1253. prtext = "Easy"
  1254. maxBalls = 1
  1255. end
  1256. if (requesttype == "pc") then
  1257. if (playerCount == 2) then
  1258. playerCount = 1
  1259. playertext = "1v1"
  1260. elseif (playerCount == 1) then
  1261. playerCount = playerCount + 1
  1262. player3.x = player1.x + VIRTUAL_WIDTH / 2
  1263. player3.y = player3.y
  1264. playertext = "2v2"
  1265. end
  1266. end
  1267. if (requesttype == "ballz") then
  1268. if (maxBalls > 1) then
  1269. --love.window.setTitle("more than 4")
  1270. maxBalls = 1
  1271. else
  1272. maxBalls = maxBalls + 1
  1273. end
  1274. end
  1275. if requesttype == "ptw" then
  1276. if ptw == 10 then
  1277. ptw = 1
  1278. else
  1279. ptw = ptw + 1
  1280. end
  1281. end
  1282. end
  1283. function gameModeChanger()
  1284. if (gameState == "gameMode") then
  1285. local button_width = VIRTUAL_WIDTH * (1 / 3)
  1286. local BUTTON_HEIGHT = 50
  1287. local margin = 20
  1288. local hot = false
  1289. local cursor_y = 0
  1290. local total_height = (BUTTON_HEIGHT + margin) * #buttons
  1291. for i, button in ipairs(modeSelectorButtons) do
  1292. button.last = button.now
  1293. local bx = (VIRTUAL_WIDTH * 0.5) - (button_width * 0.5)
  1294. local by = (VIRTUAL_HEIGHT * 0.5) - (total_height * 0.5) + cursor_y
  1295. local color = {255, 255, 255, 255}
  1296. local mx, my = love.mouse.getPosition()
  1297. mx = mx * DIFFERENCE_X
  1298. my = my * DIFFERENCE_Y
  1299. hot = (mx > bx and mx < bx + button_width and my > by and my < by + BUTTON_HEIGHT) and i
  1300. if (hot == i) then
  1301. color = {10, 10, 0, 255}
  1302. end
  1303. button.now = love.mouse.isDown(1)
  1304. if button.now and not button.last and hot == i then
  1305. love.graphics.setColor(0, 0, 0, 1)
  1306. love.graphics.rectangle("fill", 0, 0, VIRTUAL_WIDTH, VIRTUAL_HEIGHT)
  1307. sounds["wallhit"]:play()
  1308. button.fn()
  1309. end
  1310. love.graphics.setColor(unpack(color))
  1311. love.graphics.rectangle("fill", bx, by, button_width, BUTTON_HEIGHT)
  1312. love.graphics.setColor(0, 0, 0, 255)
  1313. local textW = smallfont:getWidth(button.text)
  1314. local textH = smallfont:getHeight(button.text)
  1315. love.graphics.print(button.text, smallfont, VIRTUAL_WIDTH * 0.5 - textW * 0.5, by + textH * 0.5)
  1316. love.graphics.setColor(255, 255, 255, 255)
  1317. cursor_y = cursor_y + (BUTTON_HEIGHT + margin)
  1318. end
  1319. end
  1320. if (gameState == "multiMode") then
  1321. local button_width = VIRTUAL_WIDTH * (1 / 3)
  1322. local BUTTON_HEIGHT = 50
  1323. local margin = 20
  1324. local hot = false
  1325. local cursor_y = 0
  1326. local total_height = (BUTTON_HEIGHT + margin) * #buttons
  1327. for i, button in ipairs(playerCountButtons) do
  1328. button.last = button.now
  1329. local bx = (VIRTUAL_WIDTH * 0.5) - (button_width * 0.5)
  1330. local by = (VIRTUAL_HEIGHT * 0.3) - (total_height * 0.5) + cursor_y
  1331. if (button.text == "Play") then
  1332. by = by + by / 1.8
  1333. end
  1334. local color = {255, 255, 255, 255}
  1335. local mx, my = love.mouse.getPosition()
  1336. mx = mx * DIFFERENCE_X
  1337. my = my * DIFFERENCE_Y
  1338. hot = (mx > bx and mx < bx + button_width and my > by and my < by + BUTTON_HEIGHT) and i
  1339. if (hot == i) then
  1340. if (button.text == "Play") then
  1341. color = {0 / 255, 255 / 255, 0 / 255, 255}
  1342. else
  1343. color = {10, 10, 0, 255}
  1344. end
  1345. end
  1346. button.now = love.mouse.isDown(1)
  1347. if button.now and not button.last and hot == i then
  1348. love.graphics.setColor(0, 0, 0, 1)
  1349. love.graphics.rectangle("fill", 0, 0, VIRTUAL_WIDTH, VIRTUAL_HEIGHT)
  1350. sounds["wallhit"]:play()
  1351. if button.text == "Ball Speed: " and nuckemodactive == 1 then
  1352. else
  1353. button.fn()
  1354. end
  1355. end
  1356. love.graphics.setColor(unpack(color))
  1357. love.graphics.rectangle("fill", bx, by, button_width, BUTTON_HEIGHT)
  1358. love.graphics.setColor(0, 0, 0, 255)
  1359. local textW = smallfont:getWidth(button.text)
  1360. local textH = smallfont:getHeight(button.text)
  1361. if (button.text == "1v1") then
  1362. love.graphics.print(playertext, smallfont, VIRTUAL_WIDTH * 0.5 - textW * 0.5, by + textH * 0.5)
  1363. elseif button.text == "snc" then
  1364. if (nuckemodactive == 1) then
  1365. love.graphics.setColor(1, 0, 0, 1)
  1366. love.graphics.print(synctext, smallfont, VIRTUAL_WIDTH * 0.5 - textW * 0.5, by + textH * 0.5)
  1367. love.graphics.setColor(1, 1, 1, 1)
  1368. love.graphics.print(synctext, smallfont, VIRTUAL_WIDTH * 0.5 - textW * 0.5, by + textH * 0.5)
  1369. love.graphics.setColor(0, 0, 0, 1)
  1370. else
  1371. --
  1372. love.graphics.print(synctext, smallfont, VIRTUAL_WIDTH * 0.45 - textW * 0.5, by + textH * 0.5)
  1373. end
  1374. elseif (button.text == "ballCount") then
  1375. love.graphics.print(
  1376. "Ball Count: " .. maxBalls,
  1377. smallfont,
  1378. VIRTUAL_WIDTH * 0.5 - textW * 0.5,
  1379. by + textH * 0.5
  1380. )
  1381. elseif (button.text == "Ball Speed: ") then
  1382. if (nuckemodactive == 1) then
  1383. love.graphics.setColor(1, 0, 0, 1)
  1384. love.graphics.print(
  1385. "shaitan machina",
  1386. smallfont,
  1387. VIRTUAL_WIDTH * 0.5 - textW * 0.5,
  1388. by + textH * 0.5
  1389. )
  1390. love.graphics.setColor(1, 1, 1, 1)
  1391. love.graphics.print(
  1392. "shaitan machina",
  1393. smallfont,
  1394. VIRTUAL_WIDTH * 0.5 - textW * 0.5,
  1395. by + textH * 0.5
  1396. )
  1397. love.graphics.setColor(0, 0, 0, 1)
  1398. else
  1399. love.graphics.print(
  1400. button.text .. ballSet,
  1401. smallfont,
  1402. VIRTUAL_WIDTH * 0.5 - textW * 0.5,
  1403. by + textH * 0.5
  1404. )
  1405. end
  1406. elseif button.text == "ptw" then
  1407. love.graphics.print(
  1408. "Points to Win: " .. ptw,
  1409. smallfont,
  1410. VIRTUAL_WIDTH * 0.5 - textW * 1.5,
  1411. by + textH * 0.5
  1412. )
  1413. else
  1414. love.graphics.print(button.text, smallfont, VIRTUAL_WIDTH * 0.5 - textW * 0.5, by + textH * 0.5)
  1415. end
  1416. love.graphics.setColor(255, 255, 255, 255)
  1417. cursor_y = cursor_y + (BUTTON_HEIGHT + margin)
  1418. end
  1419. end
  1420. end
  1421. function love.draw(dt)
  1422. simpleScale.set()
  1423. baseDraw()
  1424. if (globalState == "nettest" or globalState == "clienttest" or globalState == "selfhost") and confirmation == "D" then
  1425. love.graphics.clear(50 / 255, 50 / 255, 50 / 255, 255)
  1426. love.graphics.printf("WAIT FOR OPPONENT", 0, VIRTUAL_HEIGHT / 2, VIRTUAL_WIDTH, "center")
  1427. end
  1428. if (globalState == "nettest" or globalState == "clienttest" or globalState == "selfhost") and confirmation == "U" then
  1429. love.graphics.clear(50 / 255, 50 / 255, 50 / 255, 255)
  1430. love.graphics.printf("LOBBY FULL OR WRONG MODE CHOSEN", 0, VIRTUAL_HEIGHT / 2, VIRTUAL_WIDTH, "center")
  1431. end
  1432. if (globalState == "nettest" or globalState == "clienttest" or globalState == "selfhost") and confirmation == "L" then
  1433. love.graphics.clear(50 / 255, 50 / 255, 50 / 255, 255)
  1434. love.graphics.printf("POOR CONNECTION TO SERVER", 0, VIRTUAL_HEIGHT / 2, VIRTUAL_WIDTH, "center")
  1435. end
  1436. if (globalState == "nettest" or globalState == "clienttest" or globalState == "selfhost") and confirmation == "S" then
  1437. love.graphics.clear(50 / 255, 50 / 255, 50 / 255, 255)
  1438. love.graphics.printf("INTERNAL SERVER WAITING", 0, VIRTUAL_HEIGHT / 2, VIRTUAL_WIDTH, "center")
  1439. end
  1440. simpleScale.unSet()
  1441. end
  1442. --Check if controls are duplicating
  1443. function controllerSer()
  1444. for i = 1, maxBalls do
  1445. if (ball[i].dy == 0) then
  1446. hitNum[i] = hitNum[i] + 1
  1447. if hitNum[i] >= 10 then
  1448. ball[i].dy = 1
  1449. hitNum[i] = 0
  1450. end
  1451. else
  1452. hitNum[i] = 0
  1453. end
  1454. end
  1455. end
  1456. function palleteController() --!!!!LEGACY CODE, MIGRATED TO Paddle.lua!!!!
  1457. if (areanuclear == 0) then
  1458. player1.RED = 1
  1459. player1.GREEN = 1
  1460. player1.BLUE = 1
  1461. end
  1462. if (areanuclear == 0) then
  1463. player2.RED = 1
  1464. player2.GREEN = 1
  1465. player2.BLUE = 1
  1466. end
  1467. if (areanuclear == 1) then
  1468. player1.RED = 0
  1469. player1.GREEN = 0
  1470. player1.BLUE = 0
  1471. end
  1472. if (areanuclear == 1) then
  1473. player2.RED = 0
  1474. player2.GREEN = 0
  1475. player2.BLUE = 0
  1476. end
  1477. end
  1478. function love.wheelmoved(x, y)
  1479. if (y < 0 and wall1width > 0) then
  1480. wall1width = wall1width - 5
  1481. elseif y > 0 and wall1width < 900 then
  1482. wall1width = wall1width + 5
  1483. end
  1484. end
  1485. function serveBot() --THIS IS USED TO CHANGE TEXT/BALL DIRECTION ON DIFFERENT SERVES
  1486. --print("servebot called")
  1487. if (gameState == "1serve") then
  1488. updateTEXT = ""
  1489. if (gameMode ~= "practice") then
  1490. TEXT = "PLAYER 1, serve!(q)"
  1491. end
  1492. if ((globalState ~= "clienttest" and love.keyboard.isDown("q")) or (globalState == "clienttest" and lastSentKeyP1 == "q")) then
  1493. TEXT = "Lets Begin!"
  1494. ball_DIR = 1
  1495. if maxBalls == 1 then
  1496. ball[1]:reset(1, 1)
  1497. else
  1498. for i = 1, maxBalls do
  1499. ball[i]:reset(i)
  1500. end
  1501. end
  1502. gameState = "play"
  1503. end
  1504. end
  1505. if (gameState == "2serve") then
  1506. TEXT = "PLAYER 2, serve!(p)"
  1507. if (AGAINST_AI == 1) then
  1508. TEXT = ""
  1509. ball_DIR = -1
  1510. if maxBalls == 1 then
  1511. ball[2]:reset(i, 2)
  1512. else
  1513. for i = 1, maxBalls do
  1514. ball[i]:reset(i)
  1515. end
  1516. end
  1517. gameState = "play"
  1518. end
  1519. if (((globalState == "nettest" and lastSentKeyClient == "p") or ((globalState ~= "nettest") and love.keyboard.isDown("p")))and AGAINST_AI == 0) then
  1520. TEXT = "Lets Begin"
  1521. ball_DIR = -1
  1522. if maxBalls == 1 then
  1523. ball[1]:reset(1, 2)
  1524. else
  1525. for i = 1, maxBalls do
  1526. ball[i]:reset(i)
  1527. end
  1528. end
  1529. --love.window.setTitle("An atttttttt")
  1530. gameState = "play"
  1531. end
  1532. end
  1533. end
  1534. function mapChanger()
  1535. if (gameState == "editor") then
  1536. MAP_TYPE = 2
  1537. end
  1538. if (MAP_TYPE > 2) then
  1539. MAP_TYPE = 0
  1540. end
  1541. end
  1542. function resolutionChanger()
  1543. if (RESOLUTION_SET > 1) then
  1544. RESOLUTION_SET = 0
  1545. end
  1546. if (RESOLUTION_SET == 0) then
  1547. if (isFullscreen == 1) then
  1548. DIFFERENCE_X = 1
  1549. DIFFERENCE_Y = 1
  1550. simpleScale.updateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, {fullscreen = false})
  1551. isFullscreen = 0
  1552. end
  1553. end
  1554. if (RESOLUTION_SET == 1) then
  1555. if (isFullscreen == 0) then
  1556. simpleScale.updateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, {fullscreen = true})
  1557. local newWidth = love.graphics.getWidth()
  1558. local newHeight = love.graphics.getHeight()
  1559. DIFFERENCE_X = VIRTUAL_WIDTH / newWidth
  1560. DIFFERENCE_Y = VIRTUAL_HEIGHT / newHeight
  1561. isFullscreen = 1
  1562. end
  1563. end
  1564. end
  1565. function resettinggenius()
  1566. maxBalls = 1
  1567. for i = 1, maxBalls do
  1568. ball[i]:reset(i)
  1569. end
  1570. paddle_SPEED = 200
  1571. nuclearanimation = 3
  1572. timeIsSlow = false
  1573. timeIsSlow2 = false
  1574. originalSpeed = 200
  1575. gameState = "menu"
  1576. globalState = "menu"
  1577. gameMode = "normal"
  1578. player1.height = 100
  1579. player2.height = 100
  1580. ballSet = 200
  1581. ballSpeed = ballSet
  1582. player2.GREEN = 255
  1583. player2.BLUE = 255
  1584. player1.GREEN = 255
  1585. player1.BLUE = 255
  1586. player1score = 0
  1587. player2score = 0
  1588. potentialnuke1 = 0
  1589. potentialnuke2 = 0
  1590. striken = 0
  1591. areanuclear = 0
  1592. potentialstrike1 = 0
  1593. potentialstrike2 = 0
  1594. player1nukescore = 0
  1595. player2nukescore = 0
  1596. player1reverbav = 0
  1597. player2reverbav = 0
  1598. selecting = 0
  1599. AGAINST_AI = 0
  1600. end
  1601. function love.mousereleased(x, y, button)
  1602. love.keyboard.mouseisReleased = true
  1603. if (gameState == "editor") then
  1604. if (#walls < 1000 and button == 1 and blockinput ~= true) then
  1605. table.insert(walls, newWall(x * DIFFERENCE_X, y * DIFFERENCE_Y, 10, wall1width))
  1606. end
  1607. end
  1608. end
  1609. function ballsAlive()
  1610. for i = 1, maxBalls do
  1611. if ball[i].disabled == false then
  1612. print("Ball " .. i .. " is not disabled")
  1613. return true
  1614. end
  1615. end
  1616. return false
  1617. end
  1618. function split(s, delimiter)
  1619. result = {}
  1620. for match in (s..delimiter):gmatch("(.-)"..delimiter) do
  1621. table.insert(result, match)
  1622. end
  1623. return result
  1624. end
  1625. address, port = IP, 12345
  1626. function checkCurrentServer(dt)
  1627. if dserverinit == false then
  1628. local socket = require "socket"
  1629. local address, port = IP, 12345
  1630. print(address)
  1631. udp = socket.udp()
  1632. udp:setpeername(address, port)
  1633. udp:settimeout(0)
  1634. dserverinit = true
  1635. end
  1636. if IP ~= address then dserverinit = false print(IP .. " " .. address)
  1637. end
  1638. ts = ts + dt
  1639. --print(ts)
  1640. if ts > checkrate then
  1641. status = "offline"
  1642. print("sent ping")
  1643. udp:send("HELLO")
  1644. local data
  1645. data = udp:receive()
  1646. if data then
  1647. print("got answer!")
  1648. local p = split(data, '|')
  1649. status = p[1]
  1650. print("answer is " .. status)
  1651. else
  1652. print("no response!")
  1653. end
  1654. ts = 0
  1655. end
  1656. end
  1657. actualP2DATA = nil
  1658. actualP1DATA = nil
  1659. running = false
  1660. local p1ping = 0
  1661. local p2ping = 0
  1662. local requesterip
  1663. local requresterport
  1664. local player1ip, player2ip, player1port, player2port = "127.0.0.1", "none", nil, nil
  1665. local gts = 0
  1666. function selfHost(dt)
  1667. ts = ts + dt
  1668. gts = gts + dt
  1669. if serverinit == false then
  1670. local socket = require('socket')
  1671. udp = socket.udp()
  1672. udp:setsockname('*', 12345)
  1673. udp:settimeout(0)
  1674. serverinit = true
  1675. end
  1676. if gts > 0.015 then
  1677. gts = 0
  1678. data, msg_or_ip, port_or_nil = udp:receivefrom()
  1679. if not running then
  1680. print("launching server")
  1681. running = true
  1682. local socket = require 'socket'
  1683. local udp = socket.udp()
  1684. udp:settimeout(0)
  1685. udp:setsockname('*', 12345)
  1686. end
  1687. print("Acting as server")
  1688. actualP2DATA = nil
  1689. local data, msg_or_ip, port_or_nil
  1690. local p1data, p2data
  1691. repeat
  1692. data, msg_or_ip, port_or_nil = udp:receivefrom()
  1693. if data then
  1694. if data == "HELLO" then
  1695. requesterip = msg_or_ip
  1696. requesterport = port_or_nil
  1697. else
  1698. print(string.sub(data,1,1) .. "Playerlist: " .. player1ip .. " " .. player2ip)
  1699. if player2ip == msg_or_ip then
  1700. p2data = data
  1701. p2ping = 0
  1702. else
  1703. if player2ip == "none" and msg_or_ip ~= player1ip then
  1704. player2ip = msg_or_ip
  1705. p2data = data
  1706. p2ping = 0
  1707. player2port = port_or_nil
  1708. print("CONNECTED: PLAYER 2 FROM: " .. player2ip)
  1709. elseif (player1ip ~= msg_or_ip and player2ip ~= msg_or_ip) then
  1710. print("Lobby Full!" .. player1ip .. player2ip)
  1711. end
  1712. end
  1713. end
  1714. end
  1715. until not data
  1716. if player2ip ~= "none" then
  1717. p2ping = p2ping + 1
  1718. if p2ping > 100 then
  1719. if p1data then
  1720. udp:sendto(p1data .. '|' .. p2ping, player2ip, player2port)
  1721. end
  1722. print("PLAYER 2 DISCONNECTED")
  1723. p2data = nil
  1724. player2ip = "none"
  1725. player2port = nil
  1726. end
  1727. end
  1728. if p1data and player2port then
  1729. udp:sendto(p1data .. '|' .. p2ping, player2ip, player2port)
  1730. print("SENT TO " .. player2ip .. ":" .. player2port .. " : " .. string.sub(p1data,1,1))
  1731. end
  1732. if p2data and player1port then
  1733. actualP2DATA = p2data
  1734. --print("SENT TO " .. player1ip .. ":" .. player1port .. " : " .. string.sub(p2data,1,1))
  1735. --print("1::" .. p1data)
  1736. --print("2::" .. p2data)
  1737. --print("SENT1: " .. player2ip .. " " .. player2port .. " " .. p1data)
  1738. --print("SENT2: " .. player1ip .. " " .. player1port .. " " .. p2data)
  1739. end
  1740. if requesterip then
  1741. print("getting pnged!")
  1742. if player2ip == "none" then
  1743. udp:sendto("clienttest", requesterip, requesterport)
  1744. print("clienttest av to: " .. requesterip)
  1745. else
  1746. udp:sendto("full", requesterip, requesterport)
  1747. print("full to: " .. msg_or_ip)
  1748. end
  1749. requesterip, requesterport = nil
  1750. end
  1751. end
  1752. print("Integrating nettest")
  1753. for i = 1, maxBalls do
  1754. if ts > updaterate then
  1755. ts = 0
  1756. actualP1DATA = tostring(lastSentKey) ..
  1757. '|' .. tostring(ball[1].dy) ..
  1758. '|' .. tostring(player2.y) ..
  1759. '|' .. tostring(player1.y) ..
  1760. '|' .. tostring(player1score) ..
  1761. '|' .. tostring(player2score) ..
  1762. '|' .. tostring(player1nukescore) ..
  1763. '|' .. tostring(player2nukescore) ..
  1764. '|' .. tostring(ball[1].x) ..
  1765. '|' .. tostring(ball[1].y) ..
  1766. '|' .. gameState ..
  1767. '|' .. tostring(ball[1].dx) ..
  1768. '|' .. tostring(ballSpeed) ..
  1769. '|' .. tostring(paddle_SPEED) ..
  1770. "|HOST"
  1771. end
  1772. end
  1773. local data
  1774. local datanumtest = 0
  1775. local datawaspassed = false
  1776. if actualP2DATA then
  1777. datawaspassed = true
  1778. print("ReceivedINFO: " .. actualP2data)
  1779. confirmation = "N"
  1780. local p = split(actualP2data, '|')
  1781. if p[15] then
  1782. if tonumber(p[16]) > 90 then
  1783. confirmation = "L"
  1784. end
  1785. if p[15] ~= "CLIENT" then
  1786. confirmation = "U"
  1787. end
  1788. elseif p[1] == "RESPONSE" then
  1789. else
  1790. confirmation = "U"
  1791. end
  1792. if ball[1].disabled and ball[1].x > 20 and ball[1].x < VIRTUAL_WIDTH - 20 then
  1793. ball[1].disabled = false
  1794. print("illegal disabling")
  1795. end
  1796. if (ball[1].x > VIRTUAL_WIDTH/2) then
  1797. if tonumber(p[9]) > VIRTUAL_WIDTH/2 then
  1798. die = tonumber(p[2])
  1799. lastSentKeyClient,
  1800. ball[1].dy,
  1801. player2.y,
  1802. player1score,
  1803. player2score,
  1804. player1nukescore,
  1805. player2nukescore,
  1806. ball[1].x,
  1807. ball[1].y,
  1808. gameState,
  1809. ball[1].dx,
  1810. ballSpeed,
  1811. 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])
  1812. print("ACCEPTED")
  1813. else
  1814. print("DECLINED")
  1815. end
  1816. else
  1817. if tonumber(p[9]) > VIRTUAL_WIDTH/2 then
  1818. die = tonumber(p[2])
  1819. lastSentKeyClient,
  1820. ball[1].dy,
  1821. player2.y,
  1822. player1score,
  1823. player2score,
  1824. player1nukescore,
  1825. player2nukescore,
  1826. ball[1].x,
  1827. ball[1].y,
  1828. gameState,
  1829. ball[1].dx,
  1830. ballSpeed,
  1831. 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])
  1832. print("ACCEPTED")
  1833. else
  1834. print("ENFORCED" .. ball[1].x .. " " .. ball[1].dx)
  1835. lastSentKeyClient = p[1]
  1836. player2.y = tonumber(p[4])
  1837. end
  1838. end
  1839. if not datawaspassed then
  1840. datawaspassedtimer = datawaspassedtimer + 1
  1841. if datawaspassedtimer > 5 then
  1842. confirmation = "D"
  1843. datawaspassedtimer = 0
  1844. end
  1845. else
  1846. datawaspassedtimer = 0
  1847. end
  1848. else
  1849. confirmation = "S"
  1850. end
  1851. end