A pong clone, but with a twist!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

main.lua 65 KiB

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