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.

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