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

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