Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

1412 rader
53 KiB

  1. local counter = 0
  2. function basegame(dt)
  3. if gameMode == "reversegame" then
  4. reversegame(dt)
  5. end
  6. if player1nukescore > 300 then
  7. player1nukescore = 300
  8. end
  9. if player2nukescore > 300 then
  10. player2nukescore = 300
  11. end
  12. speedControl()
  13. balancer()
  14. if t < shakeDuration then
  15. t = t + dt
  16. end
  17. --print("T = " .. tostring(t))
  18. serveBot()
  19. if gameState == 'play' then
  20. if (AGAINST_AI == 1) then
  21. AI(player2, maxBalls, AI_LEVEL)
  22. end
  23. if (love.keyboard.isDown(p1control.up) or sectortouched(2)) then
  24. player1.dy = (paddle_SPEED + p1bonus) * -1
  25. elseif (love.keyboard.isDown(p1control.down) or sectortouched(3)) then
  26. player1.dy = paddle_SPEED + p1bonus
  27. else
  28. player1.dy = 0
  29. end
  30. if (AGAINST_AI == 0) then
  31. if ((globalState ~= "nettest" and (love.keyboard.isDown(p2control.up) or sectortouched(1))) ) then
  32. player2.dy = (paddle_SPEED + p2bonus) * -1
  33. elseif ((globalState ~= "nettest" and (love.keyboard.isDown(p2control.down) or sectortouched(4)))) then
  34. player2.dy = paddle_SPEED + p2bonus
  35. elseif (globalState ~= "nettest") then
  36. player2.dy = 0
  37. end
  38. end
  39. --print(areanuclear .. striken .. player1score .. player2score)
  40. for i = 1, maxBalls do
  41. if rules("p1hit", i) then
  42. if (areanuclear == 0 and striken == 1 and (player1score > ptw-2 or player2score > ptw-2)) then
  43. --print("Calling animation")
  44. print("AREA NUCLEAR?" .. areanuclear)
  45. superanimator("tensehit", 1)
  46. end
  47. if gameMode == "practice" then
  48. player1score = player1score + 1
  49. end
  50. t = 0
  51. if (ballSpeed > 200) then
  52. shakeMagnitude = ballSpeed / 200
  53. else
  54. shakeMagnitude = 0
  55. end
  56. shakeDuration = 1
  57. randomtext = love.math.random(1, #textphrases)
  58. TEXT = textphrases[randomtext]
  59. soundtype = love.math.random(1, 1.2)
  60. if (player1striken == 1) then
  61. TEXT = "PLAYER 1 STRIKES"
  62. ballSpeed = ballSpeed + player1nukescore
  63. potentialnuke1 = 0
  64. player1striken = 0
  65. player1nukescore = 0
  66. potentialstrike1 = 0
  67. striken = 1
  68. if areanuclear == 0 then
  69. sounds["striking"]:setPitch(ballSpeed / 250)
  70. sounds["striking"]:play()
  71. else
  72. sounds["nuclearhit"]:setPitch(1)
  73. sounds["nuclearhit"]:play()
  74. end
  75. print("AREA NUCLEAR?" .. areanuclear)
  76. if areanuclear == 0 then
  77. superanimator("tensehit", 1)
  78. end
  79. else
  80. if areanuclear == 0 then
  81. sounds["beep"]:setPitch(ballSpeed / 250)
  82. sounds["beep"]:play()
  83. else
  84. sounds["nuclearhit"]:setPitch(1)
  85. sounds["nuclearhit"]:play()
  86. end
  87. end
  88. if (striken == 1) then
  89. player1nukescore = player1nukescore * 1.5
  90. if (synctype == 0) then
  91. paddle_SPEED = paddle_SPEED * 1.10
  92. elseif (synctype == 1) then
  93. paddle_SPEED = ballSpeed
  94. end
  95. if (synctype == 0) then
  96. AI_SPEED = AI_SPEED * 1.10
  97. end
  98. if (synctype == 1) then
  99. AI_SPEED = ballSpeed * 1.1 / 10
  100. end
  101. ballSpeed = ballSpeed * 1.10
  102. end
  103. player1nukescore = player1nukescore + 10
  104. ball[i].dx = -ball[i].dx
  105. ball[i].x = player1.x + 30
  106. if (love.keyboard.isDown(p1control.up) or sectortouched(2)) then
  107. select = math.random(1, 5)
  108. if select == 1 then
  109. ball[i].dy = -1
  110. elseif select == 2 then
  111. ball[i].dy = -1.2
  112. elseif select == 3 then
  113. ball[i].dy = -1.5
  114. elseif select == 4 then
  115. ball[i].dy = -1.8
  116. elseif select == 5 then
  117. ball[i].dy = -2
  118. end
  119. elseif love.keyboard.isDown(p1control.down) or sectortouched(3) then
  120. select = math.random(1, 5)
  121. if select == 1 then
  122. ball[i].dy = 1
  123. elseif select == 2 then
  124. ball[i].dy = 1.2
  125. elseif select == 3 then
  126. ball[i].dy = 1.5
  127. elseif select == 4 then
  128. ball[i].dy = 1.8
  129. elseif select == 5 then
  130. ball[i].dy = 2
  131. end
  132. else
  133. if ball[i].dy < 0 then
  134. select = math.random(1, 5)
  135. if select == 1 then
  136. ball[i].dy = -1
  137. elseif select == 2 then
  138. ball[i].dy = -1.2
  139. elseif select == 3 then
  140. ball[i].dy = -1.5
  141. elseif select == 4 then
  142. ball[i].dy = -1.8
  143. elseif select == 5 then
  144. ball[i].dy = -2
  145. end
  146. else
  147. select = math.random(1, 5)
  148. if select == 1 then
  149. ball[i].dy = 1
  150. elseif select == 2 then
  151. ball[i].dy = 1.2
  152. elseif select == 3 then
  153. ball[i].dy = 1.5
  154. elseif select == 4 then
  155. ball[i].dy = 1.8
  156. elseif select == 5 then
  157. ball[i].dy = 2
  158. end
  159. end
  160. end
  161. end
  162. if rules("p2hit", i) then
  163. --ameState = 'quickanim'
  164. t = 0
  165. shakeDuration = 1
  166. if
  167. (areanuclear == 0 and
  168. (striken == 1 and (player1score > ptw-2 or player2score > ptw-2)))
  169. then
  170. print("AREA NUCLEAR?" .. areanuclear)
  171. superanimator("tensehit", 2)
  172. end
  173. if (ballSpeed > 200) then
  174. shakeMagnitude = ballSpeed / 200
  175. else
  176. shakeMagnitude = 0
  177. end
  178. randomtext = love.math.random(1, #textphrases)
  179. TEXT = textphrases[randomtext]
  180. soundtype = love.math.random(1, 1.2)
  181. if (player2striken == 1) then
  182. TEXT = "PLAYER 2 STRIKES"
  183. ballSpeed = ballSpeed + player2nukescore
  184. striken = 1
  185. player2striken = 0
  186. potentialnuke2 = 0
  187. player2nukescore = 0
  188. potentialstrike2 = 0
  189. print("AREA NUCLEAR?" .. areanuclear)
  190. if areanuclear == 0 then
  191. superanimator("tensehit", 2)
  192. end
  193. if areanuclear == 0 then
  194. sounds["striking"]:setPitch(ballSpeed / 250)
  195. sounds["striking"]:play()
  196. else
  197. sounds["nuclearhit"]:setPitch(1)
  198. sounds["nuclearhit"]:play()
  199. end
  200. elseif (striken == 1) then
  201. player2nukescore = player2nukescore * 1.5
  202. if (synctype == 0) then
  203. paddle_SPEED = paddle_SPEED * 1.10
  204. end
  205. if (synctype == 1) then
  206. paddle_SPEED = ballSpeed
  207. end
  208. if (synctype == 0) then
  209. AI_SPEED = AI_SPEED * 1.10
  210. end
  211. if (synctype == 1) then
  212. AI_SPEED = ballSpeed * 1.1 / 10
  213. end
  214. ballSpeed = ballSpeed * 1.10
  215. if areanuclear == 0 then
  216. sounds["beep"]:setPitch(ballSpeed / 250)
  217. sounds["beep"]:play()
  218. else
  219. sounds["nuclearhit"]:setPitch(1)
  220. sounds["nuclearhit"]:play()
  221. end
  222. else
  223. if areanuclear == 0 then
  224. sounds["beep"]:setPitch(ballSpeed / 250)
  225. sounds["beep"]:play()
  226. else
  227. sounds["nuclearhit"]:setPitch(1)
  228. sounds["nuclearhit"]:play()
  229. end
  230. end
  231. player2nukescore = player2nukescore + 10
  232. ball[i].dx = -ball[i].dx
  233. ball[i].x = player2.x - 30
  234. if ((globalState ~= "nettest" and (love.keyboard.isDown(p2control.up) or sectortouched(1)) ) or AI_SPEED < 0 or lastSentKeyClient == p2control.up) then
  235. select = math.random(1, 5)
  236. if select == 1 then
  237. ball[i].dy = -1
  238. elseif select == 2 then
  239. ball[i].dy = -1.2
  240. elseif select == 3 then
  241. ball[i].dy = -1.5
  242. elseif select == 4 then
  243. ball[i].dy = -1.8
  244. elseif select == 5 then
  245. ball[i].dy = -2
  246. end
  247. elseif (globalState ~= "nettest" and (love.keyboard.isDown(p2control.down)or sectortouched(4))) or AI_SPEED > 0 or lastSentKeyClient == p2control.down then
  248. select = math.random(1, 5)
  249. if select == 1 then
  250. ball[i].dy = 1
  251. elseif select == 2 then
  252. ball[i].dy = 1.2
  253. elseif select == 3 then
  254. ball[i].dy = 1.5
  255. elseif select == 4 then
  256. ball[i].dy = 1.8
  257. elseif select == 5 then
  258. ball[i].dy = 2
  259. end
  260. else
  261. if ball[i].dy < 0 then
  262. select = math.random(1, 5)
  263. if select == 1 then
  264. ball[i].dy = -1
  265. elseif select == 2 then
  266. ball[i].dy = -1.2
  267. elseif select == 3 then
  268. ball[i].dy = -1.5
  269. elseif select == 4 then
  270. ball[i].dy = -1.8
  271. elseif select == 5 then
  272. ball[i].dy = -2
  273. end
  274. else
  275. select = math.random(1, 5)
  276. if select == 1 then
  277. ball[i].dy = 1
  278. elseif select == 2 then
  279. ball[i].dy = 1.2
  280. elseif select == 3 then
  281. ball[i].dy = 1.5
  282. elseif select == 4 then
  283. ball[i].dy = 1.8
  284. elseif select == 5 then
  285. ball[i].dy = 2
  286. end
  287. end
  288. end
  289. end
  290. hitIdentifier()
  291. if ball[i].y <= 0 then
  292. soundtype = love.math.random(1, 5)
  293. sounds["wallhit"]:setPitch(ballSpeed / 250)
  294. sounds["wallhit"]:play()
  295. ball[i].y = 0
  296. ball[i].dy = -ball[i].dy
  297. end
  298. -- -4 to account for the ball's size
  299. if ball[i].y >= VIRTUAL_HEIGHT - 40 then
  300. soundtype = love.math.random(1, 5)
  301. sounds["wallhit"]:setPitch(ballSpeed / 250)
  302. sounds["wallhit"]:play()
  303. ball[i].y = VIRTUAL_HEIGHT - 40
  304. ball[i].dy = -ball[i].dy
  305. end
  306. --love.window.setTitle('Trying to update the ball')
  307. if timeIsSlow then
  308. if ballSpeed > originalSpeed / 3 then
  309. paddle_SPEED = 30
  310. ballSpeed = ballSpeed / (1 + (dt * 2))
  311. end
  312. player1nukescore = player1nukescore - (dt * 50)
  313. if player1nukescore < 1 or ball[1].dx > 0 then
  314. timeIsSlow = false
  315. player1reverbav = false
  316. ballSpeed = originalSpeed
  317. sounds["time"]:stop()
  318. paddle_SPEED = originalPaddle
  319. end
  320. end
  321. if timeIsSlow2 then
  322. if ballSpeed > originalSpeed / 3 then
  323. ballSpeed = ballSpeed / (1 + (dt * 2))
  324. end
  325. player2nukescore = player2nukescore - (dt * 50)
  326. if player2nukescore < 1 or ball[1].dx < 0 then
  327. paddle_SPEED = 30
  328. timeIsSlow2 = false
  329. player2reverbav = false
  330. ballSpeed = originalSpeed
  331. sounds["time"]:stop()
  332. paddle_SPEED = originalPaddle
  333. end
  334. end
  335. ball[i]:update(dt)
  336. end
  337. end
  338. goalManager()
  339. powerAvailability()
  340. player1:update(dt)
  341. player2:update(dt)
  342. end
  343. function debugCheck(dt)
  344. if (gameState == "menu") then
  345. updateTEXT = "0.7.7 Chalkboard Update"
  346. end
  347. dangerChecker()
  348. elapsed = elapsed + dt
  349. rotation = math.sin(elapsed * 2.5) * 0.7
  350. if gameState == "assign" then
  351. controlChanger()
  352. end
  353. editor()
  354. mapChanger()
  355. end
  356. function goalManager()
  357. for i = 1, maxBalls do
  358. if (rules("p1miss", i)) then
  359. ball[i].disabled = true
  360. ball[i].x = 2000
  361. if ballsAlive() == false then
  362. if (nuckemodactive == 0) then
  363. areanuclear = 0
  364. nuclearanimation = 3
  365. end
  366. striken = 0
  367. player1striken = 0
  368. player2striken = 0
  369. ballSpeed = ballSet
  370. if (synctype == 0) then
  371. paddle_SPEED = ballSet
  372. end
  373. if (synctype == 1) then
  374. paddle_SPEED = ballSpeed
  375. end
  376. AI_SPEED = difficultyl / 10
  377. for i = 1, maxBalls do
  378. ball[i]:reset(i, 2)
  379. end
  380. if (player2score == ptw and gameMode ~= "practice") then
  381. for i = 1, maxBalls do
  382. ball[i]:reset(i)
  383. end
  384. sounds["win"]:play()
  385. gameState = "done"
  386. TEXT = "Player 2 Won!"
  387. else
  388. if globalState ~= "clienttest" or (globalState == "clienttest" and gameState == "1serve") then
  389. gameState = "1serve"
  390. serveBot()
  391. ball[i]:reset(i, 1)
  392. end
  393. end
  394. end
  395. player2score = player2score + 1
  396. end
  397. if (rules("p2miss", i)) then
  398. ball[i].disabled = true
  399. ball[i].x = 2000
  400. if ballsAlive() == false then
  401. if (nuckemodactive == 0) then
  402. areanuclear = 0
  403. nuclearanimation = 3
  404. end
  405. striken = 0
  406. player1striken = 0
  407. player2striken = 0
  408. ballSpeed = ballSet
  409. if (synctype == 0) then
  410. paddle_SPEED = ballSet
  411. AI_SPEED = ballSet
  412. end
  413. if (synctype == 1) then
  414. paddle_SPEED = ballSpeed
  415. AI_SPEED = ballSpeed
  416. end
  417. AI_SPEED = difficultyl
  418. if (player1score == ptw) then
  419. ball[i]:reset(i)
  420. sounds["win"]:play()
  421. gameState = "done"
  422. TEXT = "Player 1 Won!"
  423. else
  424. if globalState ~= "nettest" or (globalState == "nettest" and gameState == "2serve") then
  425. gameState = "2serve"
  426. serveBot()
  427. ball[i]:reset(i, 2)
  428. end
  429. end
  430. end
  431. sounds["score"]:play()
  432. player1score = player1score + 1
  433. end
  434. end
  435. end
  436. function powerAvailability()
  437. if (player1nukescore >= 20 and player1nukescore < 140) then
  438. potentialstrike1 = 1
  439. if (((globalState ~= "clienttest" and (love.keyboard.isDown(p1control.super) or doubleclick1 == true)) or (globalState == "clienttest" and lastSentKeyP1 == p1control.super)) ) then
  440. player1striken = 1
  441. player1reverbav = 0
  442. end
  443. end
  444. if (player1nukescore >= 140) and timeIsSlow2 == false and timeIsSlow == false and (maxBalls > 1 or (ball[1].dx < 0 and ball[1].x < VIRTUAL_WIDTH/2))then
  445. player1reverbav = 1
  446. if ((globalState == "clienttest" and lastSentKeyP1 == p1control.counter) or (globalState ~= "clienttest" and (love.keyboard.isDown(p1control.counter) or hold1 == true))) then
  447. powerControl(1, "special")
  448. end
  449. end
  450. if (player1nukescore >= 200) then
  451. potentialnuke1 = 1
  452. if ((globalState == "clienttest" and (lastSentKeyP1 == p1control.super or doubleclick1 == true))or (globalState ~= "clienttest" and love.keyboard.isDown(p1control.super))) then
  453. sounds["nuke"]:play()
  454. if areanuclear == 1 then
  455. maxspeed = maxspeed + 50
  456. end
  457. areanuclear = 1
  458. potentialstrike1 = 0
  459. striken = 0
  460. ballSpeed = ballSpeed * 2
  461. if (synctype == 0) then
  462. paddle_SPEED = paddle_SPEED * 2
  463. end
  464. if (synctype == 1) then
  465. paddle_SPEED = ballSpeed
  466. end
  467. if (synctype == 0) then
  468. AI_SPEED = AI_SPEED * 2.2
  469. end
  470. if (synctype == 1) then
  471. AI_SPEED = ballSpeed * 1.1 / 10
  472. end
  473. player1nukescore = 0
  474. player1reverbav = 0
  475. potentialnuke1 = 0
  476. end
  477. end
  478. if (player2nukescore >= 20 and player2nukescore <= 140) then
  479. potentialstrike2 = 1
  480. if (AGAINST_AI == 0) then
  481. if ((globalState ~= "nettest" and (love.keyboard.isDown(p2control.super) or doubleclick2)) or lastSentKeyClient == p2control.super ) then
  482. player2striken = 1
  483. player2reverbav = 0
  484. end
  485. end
  486. end
  487. if (player2nukescore >= 140) and timeIsSlow == false and timeIsSlow2 == false and (maxBalls > 1 or (ball[1].dx > 0 and ball[1].x < VIRTUAL_WIDTH/2)) then
  488. player2reverbav = 1
  489. if (globalState ~= "nettest" and (love.keyboard.isDown(p2control.counter) or hold2)) or lastSentKeyClient == p2control.counter then
  490. sounds["time"]:play()
  491. player2reverbav = false
  492. timeIsSlow2 = true
  493. originalPaddle = paddle_SPEED
  494. originalSpeed = ballSpeed
  495. player2reverbav = 0
  496. potentialnuke2 = 0
  497. potentialstrike2 = 0
  498. end
  499. end
  500. if (player2nukescore >= 200) then
  501. potentialnuke2 = 1
  502. if (((globalState ~= "nettest" and (love.keyboard.isDown(p2control.super) or doubleclick2)) or lastSentKeyClient == p2control.super)) and AGAINST_AI == 0 then
  503. sounds["nuke"]:play()
  504. if areanuclear == 1 then
  505. maxspeed = maxspeed + 50
  506. end
  507. potentialstrike2 = 0
  508. areanuclear = 1
  509. player2reverbav = 0
  510. ballSpeed = ballSpeed * 2
  511. if (synctype == 0) then
  512. paddle_SPEED = paddle_SPEED * 2
  513. end
  514. if (synctype == 1) then
  515. paddle_SPEED = ballSpeed
  516. end
  517. if (synctype == 0) then
  518. AI_SPEED = AI_SPEED * 2.2
  519. end
  520. if (synctype == 1) then
  521. AI_SPEED = ballSpeed * 1.1 / 10
  522. end
  523. player2nukescore = 0
  524. potentialnuke2 = 0
  525. end
  526. end
  527. end
  528. function editor()
  529. if (gameState == "editor") then
  530. if debug then
  531. --print("Editor is active!")
  532. end
  533. local mx, my = love.mouse.getPosition()
  534. mx = mx * DIFFERENCE_X
  535. my = my * DIFFERENCE_Y
  536. if (love.mouse.isDown(2)) then
  537. wallbreaker(mx, my)
  538. end
  539. if (love.mouse.isDown(3)) then
  540. table.insert(walls, newWall(mx, my, 10, wall1width))
  541. end
  542. end
  543. end
  544. function nuclearDraw()
  545. love.graphics.setColor(1, 1, 1, 1)
  546. for i = 1, maxBalls do
  547. love.graphics.circle("fill", ball[i].x, ball[i].y, explosionRange * 100, 100)
  548. end
  549. player1.RED, player1.GREEN, player1.BLUE, player2.RED, player2.GREEN, player2.BLUE =
  550. nuclearanimation / 3,
  551. nuclearanimation / 3,
  552. nuclearanimation / 3,
  553. nuclearanimation / 3,
  554. nuclearanimation / 3,
  555. nuclearanimation / 3
  556. for i = 1, maxBalls do
  557. love.graphics.setColor(nuclearanimation / 3, nuclearanimation / 3, nuclearanimation / 3, 1)
  558. ball[i]:render("controlled")
  559. end
  560. player1:render()
  561. player2:render()
  562. end
  563. function normalDraw()
  564. if (areanuclear == 1) then
  565. love.graphics.clear(1, 1, 1, 1)
  566. else
  567. love.graphics.clear(40 / 255, 40 / 255, 40 / 255, 1)
  568. end
  569. staticanimator()
  570. if MAP_TYPE == 1 then
  571. love.graphics.setColor(1, 0, 0.20, 1)
  572. love.graphics.rectangle("fill", VIRTUAL_WIDTH * 0.5, 0, 10, VIRTUAL_HEIGHT * 0.3)
  573. love.graphics.rectangle("fill", VIRTUAL_WIDTH * 0.5, VIRTUAL_HEIGHT * 0.7, 10, VIRTUAL_HEIGHT * 0.3)
  574. love.graphics.setColor(1, 1, 1, 1)
  575. end
  576. if MAP_TYPE == 2 then
  577. for i, wall in ipairs(walls) do
  578. love.graphics.setColor(1, 1, 1, 1)
  579. love.graphics.rectangle("fill", wall.wallx, wall.wally, 10, wall.wallheight)
  580. end
  581. end
  582. pongDraw()
  583. love.graphics.setFont(smallfont)
  584. for i = 1, maxBalls do
  585. if areanuclear == 1 then
  586. --love.window.setTitle('rendering black')
  587. ball[i]:render("black")
  588. else
  589. --love.window.setTitle('rendering white')
  590. ball[i]:render(" ")
  591. end
  592. end
  593. end
  594. function pongDraw()
  595. --print("Drawing classic pong")
  596. love.graphics.setColor(1, 1, 1, 1)
  597. love.graphics.printf(TEXT, 0, 20, VIRTUAL_WIDTH, "center")
  598. love.graphics.setFont(smallfont)
  599. love.graphics.setFont(scorefont)
  600. if (areanuclear == 1) then
  601. love.graphics.setColor(0, 0, 0, 1)
  602. end
  603. love.graphics.print(tostring(math.floor(player1score)), VIRTUAL_WIDTH / 2 - 500, VIRTUAL_HEIGHT / 12)
  604. love.graphics.print(tostring(math.floor(player2score)), VIRTUAL_WIDTH / 2 + 400, VIRTUAL_HEIGHT / 12)
  605. love.graphics.setColor(1, 1, 1, 1)
  606. displayPoints()
  607. player1:render()
  608. player2:render()
  609. end
  610. function practiceDraw()
  611. player1:render()
  612. love.graphics.rectangle("fill", VIRTUAL_WIDTH-10, 0, 10, VIRTUAL_HEIGHT)
  613. love.graphics.setColor(1, 1, 1, 1)
  614. love.graphics.printf(TEXT, 0, 20, VIRTUAL_WIDTH, "center")
  615. love.graphics.setFont(smallfont)
  616. love.graphics.setFont(scorefont)
  617. love.graphics.print(tostring(math.floor(player1score)), VIRTUAL_WIDTH / 2 - 500, VIRTUAL_HEIGHT / 12)
  618. end
  619. function menuDraw()
  620. love.graphics.setColor(1, 1, 1, 1)
  621. love.graphics.printf(TEXT, 0, 20, VIRTUAL_WIDTH, "center")
  622. love.graphics.setFont(smallfont)
  623. love.graphics.printf(updateTEXT, 0, VIRTUAL_HEIGHT * 0.95, VIRTUAL_WIDTH, "left")
  624. if MAP_TYPE == 1 then
  625. love.graphics.setColor(1, 0, 0.20, 1)
  626. love.graphics.rectangle("fill", VIRTUAL_WIDTH * 0.5, 0, 10, VIRTUAL_HEIGHT * 0.3)
  627. love.graphics.rectangle("fill", VIRTUAL_WIDTH * 0.5, VIRTUAL_HEIGHT * 0.7, 10, VIRTUAL_HEIGHT * 0.3)
  628. love.graphics.setColor(1, 1, 1, 1)
  629. end
  630. if MAP_TYPE == 2 then
  631. for i, wall in ipairs(walls) do
  632. love.graphics.setColor(1, 1, 1, 1)
  633. love.graphics.rectangle("fill", wall.wallx, wall.wally, 10, wall.wallheight)
  634. end
  635. end
  636. if gameState == "touchcontrols" then
  637. if doubleclick1 or doubleclick2 then
  638. gameState = "menu"
  639. globalState = "menu"
  640. resettinggenius()
  641. end
  642. love.graphics.setFont(smallfont)
  643. love.graphics.printf("The green zones are for moving up and down, double tap the red zone for special attack or to start the serve.", 10, 150, VIRTUAL_WIDTH, "center")
  644. love.graphics.printf("Swipe from red to green for stopping time", 10, 450, VIRTUAL_WIDTH, "center")
  645. end
  646. if gameState == "windowsettings" then
  647. mymenu:butt(gameState, VIRTUAL_WIDTH, VIRTUAL_HEIGHT, settings, sounds, "right")
  648. love.keyboard.mouseisReleased = false
  649. end
  650. if gameState == "editor" then
  651. mymenu:butt(gameState, VIRTUAL_WIDTH, VIRTUAL_HEIGHT, editorpicks, sounds, "right")
  652. love.keyboard.mouseisReleased = false
  653. end
  654. if gameState == "speedSettings" then
  655. mymenu:butt(gameState, VIRTUAL_WIDTH, VIRTUAL_HEIGHT, speedParameters, sounds, "middle")
  656. love.keyboard.mouseisReleased = false
  657. end
  658. if gameState == "controlSettings" then
  659. mymenu:butt(gameState, VIRTUAL_WIDTH, VIRTUAL_HEIGHT, controlSettings, sounds, "control")
  660. love.keyboard.mouseisReleased = false
  661. end
  662. if gameState == "gameMode" then
  663. mymenu:butt(gameState, VIRTUAL_WIDTH, VIRTUAL_HEIGHT, modeSelectorButtons, sounds, "middle")
  664. love.keyboard.mouseisReleased = false
  665. end
  666. if gameState == "chooseIP" then
  667. IPselect = {}
  668. if isAndroid then
  669. table.insert(
  670. IPselect,
  671. newButton(
  672. IPnew,
  673. function()
  674. love.keyboard.setTextInput( true, 0, VIRTUAL_HEIGHT, VIRTUAL_WIDTH, VIRTUAL_HEIGHT/3)
  675. end
  676. )
  677. )
  678. end
  679. table.insert(
  680. IPselect,
  681. newButton(
  682. "LANHost",
  683. function()
  684. globalState = "selfhost"
  685. AGAINST_AI = 0
  686. gameState = "1serve"
  687. ball[1]:reset(1, 1)
  688. end
  689. )
  690. )
  691. table.insert(
  692. IPselect,
  693. newButton(
  694. "Check Server",
  695. function()
  696. IP = IPnew
  697. counter = 0
  698. end
  699. )
  700. )
  701. if status == "offline" then
  702. animateConnection()
  703. elseif status == "nettest" and IP == IPnew then
  704. table.insert(
  705. IPselect,
  706. newButton(
  707. "Connect as Host",
  708. function()
  709. globalState = "nettest"
  710. AGAINST_AI = 0
  711. gameState = "1serve"
  712. ball[1]:reset(1, 1)
  713. end
  714. )
  715. )
  716. elseif status == "clienttest" and IP == IPnew then
  717. table.insert(
  718. IPselect,
  719. newButton(
  720. "Connect as Guest",
  721. function()
  722. globalState = "clienttest"
  723. AGAINST_AI = 0
  724. gameState = "1serve"
  725. ball[1]:reset(1, 1)
  726. end
  727. )
  728. )
  729. elseif status == "full" then
  730. love.graphics.printf("SERVER FULL", 0, VIRTUAL_HEIGHT / 2, VIRTUAL_WIDTH, "center")
  731. end
  732. mymenu:butt(gameState, VIRTUAL_WIDTH, VIRTUAL_HEIGHT, IPselect, sounds, "middle")
  733. love.keyboard.mouseisReleased = false
  734. if not isAndroid then
  735. love.graphics.printf(IPnew, 0, VIRTUAL_HEIGHT / 4, VIRTUAL_WIDTH, "center")
  736. end
  737. love.keyboard.mouseisReleased = false
  738. end
  739. if gameState == "menu" then
  740. mymenu:butt(gameState, VIRTUAL_WIDTH, VIRTUAL_HEIGHT, buttons, sounds, "middle")
  741. love.keyboard.mouseisReleased = false
  742. end
  743. if gameState == "difficulty" then
  744. mymenu:butt(gameState, VIRTUAL_WIDTH, VIRTUAL_HEIGHT, difbuttons, sounds, "middle")
  745. love.keyboard.mouseisReleased = false
  746. end
  747. if gameState == "multiMode" then
  748. mymenu:butt(gameState, VIRTUAL_WIDTH, VIRTUAL_HEIGHT, playerCountButtons, sounds, "playercount")
  749. love.keyboard.mouseisReleased = false
  750. end
  751. if gameState == "prdiff" then
  752. mymenu:butt(gameState, VIRTUAL_WIDTH, VIRTUAL_HEIGHT, pracdiff, sounds, "playercount")
  753. love.keyboard.mouseisReleased = false
  754. end
  755. if gameState == 'start' then
  756. love.graphics.push()
  757. love.graphics.translate(VIRTUAL_WIDTH * 0.4, VIRTUAL_HEIGHT * 0.5)
  758. love.graphics.rotate(rotation)
  759. love.graphics.setFont(smallfont)
  760. if isAndroid then
  761. love.graphics.print("Tap to Start", WINDOW_WIDTH / -10, VIRTUAL_HEIGHT / 8)
  762. else
  763. love.graphics.print("Press Enter to Start", WINDOW_WIDTH / -10, VIRTUAL_HEIGHT / 8)
  764. end
  765. love.graphics.setColor(255, 255, 255, 255)
  766. love.graphics.pop()
  767. end
  768. end
  769. function baseDraw()
  770. love.graphics.clear(40 / 255, 40 / 255, 40 / 255, 1)
  771. if shakeDuration > t then
  772. local dx = love.math.random(-shakeMagnitude, shakeMagnitude)
  773. local dy = love.math.random(-shakeMagnitude, shakeMagnitude)
  774. love.graphics.translate(dx, dy)
  775. end
  776. if globalState == 'menu' then
  777. --print("Drawing menuDraw")
  778. if gameState == 'animation' then
  779. --print("Drawing animation")
  780. intro()
  781. end
  782. if gameState ~= 'animation' then
  783. --print("Drawing notanimtaion")
  784. love.graphics.setFont(scorefont)
  785. if isAndroid then
  786. androidDraw()
  787. end
  788. menuDraw()
  789. end
  790. end
  791. if globalState == 'base' or globalState == 'reverse' or globalState == 'nettest' or globalState == 'clienttest' then
  792. love.graphics.setFont(smallfont)
  793. if gameState == 'nuclearExplosion' then
  794. nuclearDraw()
  795. end
  796. if gameState == 'play' or gameState == '1serve' or gameState == '2serve' or gameState == 'done' then
  797. print("Drawing normally")
  798. normalDraw()
  799. end
  800. if isAndroid then
  801. androidDraw()
  802. love.keyboard.mouseisReleased = false
  803. end
  804. end
  805. end
  806. function androidDraw()
  807. --HOME BUTTON HERE
  808. mymenu:butt(gameState, VIRTUAL_WIDTH, VIRTUAL_HEIGHT, androidButtons, sounds, "android")
  809. if showTouchControls then
  810. love.graphics.setColor(15/255, 255/255, 15/255, 0.5)
  811. love.graphics.rectangle("fill", 0, 0, 50, VIRTUAL_HEIGHT)
  812. love.graphics.setColor(15/255, 255/255, 15/255, 0.5)
  813. love.graphics.rectangle("fill", VIRTUAL_WIDTH-50, 0, 50, VIRTUAL_HEIGHT)
  814. love.graphics.setColor(255/255, 15/255, 15/255, 0.5)
  815. love.graphics.rectangle("fill", 50, 0, VIRTUAL_WIDTH/2-50, VIRTUAL_HEIGHT)
  816. love.graphics.rectangle("fill", VIRTUAL_WIDTH/2, 0, VIRTUAL_WIDTH/2-50, VIRTUAL_HEIGHT)
  817. love.graphics.setColor(0, 0, 0, 0.5)
  818. love.graphics.rectangle("fill", VIRTUAL_WIDTH/2-5, 0, 10, VIRTUAL_HEIGHT)
  819. end
  820. end
  821. function renderEditor()
  822. if not blockinput then
  823. love.graphics.setColor(1, 0, 0, 1)
  824. love.graphics.rectangle("fill", mx, my, 10, wall1width)
  825. love.graphics.setColor(1, 1, 1, 1)
  826. end
  827. for i, wall in ipairs(walls) do
  828. love.graphics.setColor(1, 1, 1, 1)
  829. love.graphics.rectangle("fill", wall.wallx, wall.wally, 10, wall.wallheight)
  830. end
  831. end
  832. function intro()
  833. love.graphics.setColor(255, 255, 255, light / 255)
  834. love.graphics.draw(image, 0, 0)
  835. end
  836. function displayPoints()
  837. love.graphics.setFont(smallfont)
  838. if areanuclear == 1 then
  839. love.graphics.setColor(0,0,0,1)
  840. end
  841. if (potentialstrike1 == 1 and potentialnuke1 == 0 and player1reverbav == 0) then --FLAG: AVAILABLE SUPER
  842. if (player1striken == 0) then
  843. love.graphics.print(
  844. tostring(math.floor(player1nukescore) .. "[" .. p1control.super .. "]"),
  845. VIRTUAL_WIDTH / 2 - 500,
  846. VIRTUAL_HEIGHT / 60
  847. )
  848. else
  849. love.graphics.print(tostring("READY"), VIRTUAL_WIDTH / 2 - 500, VIRTUAL_HEIGHT / 60)
  850. end
  851. elseif (player1reverbav == 1 and potentialnuke1 == 0 ) then
  852. love.graphics.print(
  853. tostring(
  854. math.floor(player1nukescore) .. "[" .. p1control.super .. "]" .. " [" .. p1control.counter .. "]"
  855. ),
  856. VIRTUAL_WIDTH / 2 - 500,
  857. VIRTUAL_HEIGHT / 60
  858. )
  859. elseif (potentialnuke1 == 1) then
  860. love.graphics.setColor(255, 0, 0, 255)
  861. love.graphics.print(
  862. tostring(
  863. math.floor(player1nukescore) .. "[" .. p1control.super .. "]" .. " [" .. p1control.counter .. "]"
  864. ),
  865. VIRTUAL_WIDTH / 2 - 500,
  866. VIRTUAL_HEIGHT / 60
  867. )
  868. love.graphics.setColor(255, 255, 255, 255)
  869. elseif (potentialnuke1 == 1) then
  870. love.graphics.setColor(255, 0, 0, 255)
  871. love.graphics.print(
  872. tostring(
  873. math.floor(player1nukescore) .. "[" .. p1control.super .. "]"
  874. ),
  875. VIRTUAL_WIDTH / 2 - 500,
  876. VIRTUAL_HEIGHT / 60
  877. )
  878. love.graphics.setColor(255, 255, 255, 255)
  879. else
  880. love.graphics.print(tostring(math.floor(player1nukescore)), VIRTUAL_WIDTH / 2 - 500, VIRTUAL_HEIGHT / 60)
  881. end
  882. if (potentialstrike2 == 1 and player2reverbav == 0) then
  883. if (player2striken == 0) then
  884. love.graphics.print(
  885. tostring(math.floor(player2nukescore) .. "[" .. p2control.super .. "]"),
  886. VIRTUAL_WIDTH / 2 + 430,
  887. VIRTUAL_HEIGHT / 60
  888. )
  889. else
  890. love.graphics.print(tostring("READY"), VIRTUAL_WIDTH / 2 + 430, VIRTUAL_HEIGHT / 60)
  891. end
  892. elseif (potentialnuke2 == 1) then
  893. love.graphics.setColor(255, 0, 0, 255)
  894. love.graphics.print(
  895. tostring(math.floor(player2nukescore) .. "[" .. p2control.super .. "] [" .. p2control.counter .. "]"),
  896. VIRTUAL_WIDTH / 2 + 400,
  897. VIRTUAL_HEIGHT / 60
  898. )
  899. love.graphics.setColor(255, 255, 255, 255)
  900. elseif (potentialnuke2 == 1 and maxBalls > 1) then
  901. love.graphics.setColor(255, 0, 0, 255)
  902. love.graphics.print(
  903. tostring(math.floor(player2nukescore) .. "[" .. p2control.super .. "]"),
  904. VIRTUAL_WIDTH / 2 + 430,
  905. VIRTUAL_HEIGHT / 60
  906. )
  907. love.graphics.setColor(255, 255, 255, 255)
  908. elseif (player2reverbav == 1 and potentialnuke2 == 0 ) then
  909. love.graphics.print(
  910. tostring(math.floor(player2nukescore) .. "[" .. p2control.super .. "] [" .. p2control.counter .. "]"),
  911. VIRTUAL_WIDTH / 2 + 400,
  912. VIRTUAL_HEIGHT / 60
  913. )
  914. else
  915. love.graphics.print(tostring(math.floor(player2nukescore)), VIRTUAL_WIDTH / 2 + 430, VIRTUAL_HEIGHT / 60)
  916. end
  917. end
  918. function hitIdentifier()
  919. if (gameMode == "practice") then
  920. MAP_TYPE = 0
  921. if ball[i].x > VIRTUAL_WIDTH * 0.99 then
  922. soundtype = love.math.random(1, 5)
  923. sounds["wallhit"]:setPitch(ballSpeed / 250)
  924. sounds["wallhit"]:play()
  925. if (ball[i].dx > 0) then
  926. ball[i].x = ball[i].x - 20
  927. else
  928. ball[i].x = ball[i].x + 20
  929. end
  930. ball[i].dx = -ball[i].dx
  931. end
  932. end
  933. if (MAP_TYPE == 1) then
  934. if
  935. ball[i].y < VIRTUAL_HEIGHT * 0.3 and ball[i].x > VIRTUAL_WIDTH * 0.5 and
  936. ball[i].x < VIRTUAL_WIDTH * 0.5 + 5
  937. then
  938. soundtype = love.math.random(1, 5)
  939. sounds["wallhit"]:setPitch(ballSpeed / 250)
  940. sounds["wallhit"]:play()
  941. if (ball[i].dx > 0) then
  942. ball[i].x = ball[i].x - 20
  943. else
  944. ball[i].x = ball[i].x + 20
  945. end
  946. ball[i].dx = -ball[i].dx
  947. end
  948. if
  949. ball[i].y > VIRTUAL_HEIGHT * 0.7 and ball[i].x > VIRTUAL_WIDTH * 0.5 and
  950. ball[i].x < VIRTUAL_WIDTH * 0.5 + 5
  951. then
  952. soundtype = love.math.random(1, 5)
  953. sounds["wallhit"]:setPitch(ballSpeed / 250)
  954. sounds["wallhit"]:play()
  955. if (ball[i].dx > 0) then
  956. ball[i].x = ball[i].x - 20
  957. else
  958. ball[i].x = ball[i].x + 20
  959. end
  960. ball[i].dx = -ball[i].dx
  961. end
  962. end
  963. if (MAP_TYPE == 2) then
  964. for i, wall in ipairs(walls) do
  965. if
  966. (ball[1].y > wall.wally and ball[1].y < wall.wally + wall.wallheight and
  967. ball[1].x > wall.wallx - ballSpeed / 200 and
  968. ball[1].x < wall.wallx + 10 + ballSpeed / 200)
  969. then
  970. controllerSer()
  971. soundtype = love.math.random(1, 5)
  972. sounds["wallhit"]:setPitch(ballSpeed / 250)
  973. sounds["wallhit"]:play()
  974. if (ball[1].dx > 0) then
  975. ball[1].x = ball[1].x - 1
  976. else
  977. ball[1].x = ball[1].x + 1
  978. end
  979. ball[1].dx = -ball[1].dx
  980. elseif
  981. (ball[1].y > wall.wally - 15 and ball[1].y < wall.wally + wall.wallheight + 10 and
  982. ball[1].x > wall.wallx and
  983. ball[1].x < wall.wallx + 10)
  984. then
  985. controllerSer()
  986. soundtype = love.math.random(1, 5)
  987. sounds["wallhit"]:setPitch(ballSpeed / 250)
  988. sounds["wallhit"]:play()
  989. if (ball[1].dy > 0) then
  990. ball[1].y = ball[1].y - 1
  991. else
  992. ball[1].y = ball[1].y + 1
  993. end
  994. ball[1].dy = -ball[1].dy
  995. end
  996. end
  997. end
  998. end
  999. function rules(query, i)
  1000. if query == "p1hit" then
  1001. if gameMode == "normal" then
  1002. return ball[i]:collides(player1)
  1003. elseif gameMode == "reversegame" then
  1004. return ball[i].x < 0 and ball[i].disabled == false
  1005. end
  1006. end
  1007. if query == "p2hit" then
  1008. if gameMode == "normal" then
  1009. return ball[i]:collides(player2)
  1010. elseif gameMode == "reversegame" then
  1011. return ball[i].x > VIRTUAL_WIDTH-10 and ball[i].disabled == false
  1012. end
  1013. end
  1014. if query == "p1miss" then
  1015. if gameMode == "reversegame" then
  1016. return ball[i]:collides(player1)
  1017. elseif gameMode == "normal" then
  1018. return ball[i].x < 0 and ball[i].disabled == false
  1019. end
  1020. end
  1021. if query == "p2miss" then
  1022. if gameMode == "reversegame" then
  1023. return ball[i]:collides(player2)
  1024. elseif gameMode == "normal" then
  1025. return ball[i].x > VIRTUAL_WIDTH-10 and ball[i].disabled == false
  1026. end
  1027. end
  1028. end
  1029. function clientsBaseGame(dt)
  1030. if gameMode == "reverse" then
  1031. reversegame(dt)
  1032. end
  1033. if player1nukescore > 300 then
  1034. player1nukescore = 300
  1035. end
  1036. if player2nukescore > 300 then
  1037. player2nukescore = 300
  1038. end
  1039. speedControl()
  1040. balancer()
  1041. if t < shakeDuration then
  1042. t = t + dt
  1043. end
  1044. if (lastSentKeyP1 == p1control.up) then
  1045. player1.dy = (paddle_SPEED + p2bonus) * -1
  1046. print("moving player1 up")
  1047. elseif (lastSentKeyP1 == p1control.down) then
  1048. player1.dy = paddle_SPEED + p2bonus
  1049. print("moving player1 down")
  1050. else
  1051. player1.dy = 0
  1052. -- print("stopping player")
  1053. end
  1054. if ((love.keyboard.isDown(p2control.up) or sectortouched(1))) then
  1055. player2.dy = (paddle_SPEED + p2bonus) * -1
  1056. elseif ((love.keyboard.isDown(p2control.down)) or sectortouched(4)) then
  1057. player2.dy = paddle_SPEED + p2bonus
  1058. else
  1059. player2.dy = 0
  1060. end
  1061. --print("T = " .. tostring(t))
  1062. serveBot()
  1063. if gameState == 'play' then
  1064. if (AGAINST_AI == 1) then
  1065. AI(player2, maxBalls, AI_LEVEL)
  1066. end
  1067. --print(areanuclear .. striken .. player1score .. player2score)
  1068. for i = 1, maxBalls do
  1069. if rules("p1hit", i) then
  1070. if (areanuclear == 0 and striken == 1 and (player1score > ptw-2 or player2score > ptw-2)) then
  1071. --print("Calling animation")
  1072. superanimator("tensehit", 1)
  1073. print("AREA NUCLEAR?" .. areanuclear)
  1074. end
  1075. if gameMode == "practice" then
  1076. player1score = player1score + 1
  1077. end
  1078. t = 0
  1079. if (ballSpeed > 200) then
  1080. shakeMagnitude = ballSpeed / 200
  1081. else
  1082. shakeMagnitude = 0
  1083. end
  1084. shakeDuration = 1
  1085. randomtext = love.math.random(1, #textphrases)
  1086. TEXT = textphrases[randomtext]
  1087. soundtype = love.math.random(1, 1.2)
  1088. if (player1striken == 1) then
  1089. TEXT = "PLAYER 1 STRIKES"
  1090. ballSpeed = ballSpeed + player1nukescore
  1091. potentialnuke1 = 0
  1092. player1striken = 0
  1093. player1nukescore = 0
  1094. potentialstrike1 = 0
  1095. striken = 1
  1096. if areanuclear == 0 then
  1097. sounds["striking"]:setPitch(ballSpeed / 250)
  1098. sounds["striking"]:play()
  1099. else
  1100. sounds["nuclearhit"]:setPitch(1)
  1101. sounds["nuclearhit"]:play()
  1102. end
  1103. if areanuclear == 0 then
  1104. superanimator("tensehit", 1)
  1105. end
  1106. else
  1107. if areanuclear == 0 then
  1108. sounds["beep"]:setPitch(ballSpeed / 250)
  1109. sounds["beep"]:play()
  1110. else
  1111. sounds["nuclearhit"]:setPitch(1)
  1112. sounds["nuclearhit"]:play()
  1113. end
  1114. end
  1115. if (striken == 1) then
  1116. player1nukescore = player1nukescore * 1.5
  1117. if (synctype == 0) then
  1118. paddle_SPEED = paddle_SPEED * 1.10
  1119. elseif (synctype == 1) then
  1120. paddle_SPEED = ballSpeed
  1121. end
  1122. if (synctype == 0) then
  1123. AI_SPEED = AI_SPEED * 1.10
  1124. end
  1125. if (synctype == 1) then
  1126. AI_SPEED = ballSpeed * 1.1 / 10
  1127. end
  1128. ballSpeed = ballSpeed * 1.10
  1129. end
  1130. player1nukescore = player1nukescore + 10
  1131. ball[i].dx = -ball[i].dx
  1132. ball[i].x = player1.x + 30
  1133. end
  1134. if rules("p2hit", i) then
  1135. --ameState = 'quickanim'
  1136. t = 0
  1137. shakeDuration = 1
  1138. if
  1139. (areanuclear == 0 and
  1140. (striken == 1 and (player1score > ptw-2 or player2score > ptw-2)))
  1141. then
  1142. print("AREA NUCLEAR?" .. areanuclear)
  1143. superanimator("tensehit", 2)
  1144. end
  1145. if (ballSpeed > 200) then
  1146. shakeMagnitude = ballSpeed / 200
  1147. else
  1148. shakeMagnitude = 0
  1149. end
  1150. randomtext = love.math.random(1, #textphrases)
  1151. TEXT = textphrases[randomtext]
  1152. soundtype = love.math.random(1, 1.2)
  1153. if (player2striken == 1) then
  1154. TEXT = "PLAYER 2 STRIKES"
  1155. ballSpeed = ballSpeed + player2nukescore
  1156. striken = 1
  1157. player2striken = 0
  1158. potentialnuke2 = 0
  1159. player2nukescore = 0
  1160. potentialstrike2 = 0
  1161. print("AREA NUCLEAR?" .. areanuclear)
  1162. if areanuclear == 0 then
  1163. superanimator("tensehit", 2)
  1164. end
  1165. if areanuclear == 0 then
  1166. sounds["striking"]:setPitch(ballSpeed / 250)
  1167. sounds["striking"]:play()
  1168. else
  1169. sounds["nuclearhit"]:setPitch(1)
  1170. sounds["nuclearhit"]:play()
  1171. end
  1172. elseif (striken == 1) then
  1173. player2nukescore = player2nukescore * 1.5
  1174. if (synctype == 0) then
  1175. paddle_SPEED = paddle_SPEED * 1.10
  1176. end
  1177. if (synctype == 1) then
  1178. paddle_SPEED = ballSpeed
  1179. end
  1180. if (synctype == 0) then
  1181. AI_SPEED = AI_SPEED * 1.10
  1182. end
  1183. if (synctype == 1) then
  1184. AI_SPEED = ballSpeed * 1.1 / 10
  1185. end
  1186. ballSpeed = ballSpeed * 1.10
  1187. if areanuclear == 0 then
  1188. sounds["beep"]:setPitch(ballSpeed / 250)
  1189. sounds["beep"]:play()
  1190. else
  1191. sounds["nuclearhit"]:setPitch(1)
  1192. sounds["nuclearhit"]:play()
  1193. end
  1194. else
  1195. if areanuclear == 0 then
  1196. sounds["beep"]:setPitch(ballSpeed / 250)
  1197. sounds["beep"]:play()
  1198. else
  1199. sounds["nuclearhit"]:setPitch(1)
  1200. sounds["nuclearhit"]:play()
  1201. end
  1202. end
  1203. player2nukescore = player2nukescore + 10
  1204. ball[i].dx = -ball[i].dx
  1205. ball[i].x = player2.x - 30
  1206. if ((love.keyboard.isDown(p2control.up)) or sectortouched(1)) then
  1207. select = math.random(1, 5)
  1208. if select == 1 then
  1209. ball[i].dy = -1
  1210. elseif select == 2 then
  1211. ball[i].dy = -1.2
  1212. elseif select == 3 then
  1213. ball[i].dy = -1.5
  1214. elseif select == 4 then
  1215. ball[i].dy = -1.8
  1216. elseif select == 5 then
  1217. ball[i].dy = -2
  1218. end
  1219. elseif (love.keyboard.isDown(p2control.down) or sectortouched(4))then
  1220. select = math.random(1, 5)
  1221. if select == 1 then
  1222. ball[i].dy = 1
  1223. elseif select == 2 then
  1224. ball[i].dy = 1.2
  1225. elseif select == 3 then
  1226. ball[i].dy = 1.5
  1227. elseif select == 4 then
  1228. ball[i].dy = 1.8
  1229. elseif select == 5 then
  1230. ball[i].dy = 2
  1231. end
  1232. else
  1233. if ball[i].dy < 0 then
  1234. select = math.random(1, 5)
  1235. if select == 1 then
  1236. ball[i].dy = -1
  1237. elseif select == 2 then
  1238. ball[i].dy = -1.2
  1239. elseif select == 3 then
  1240. ball[i].dy = -1.5
  1241. elseif select == 4 then
  1242. ball[i].dy = -1.8
  1243. elseif select == 5 then
  1244. ball[i].dy = -2
  1245. end
  1246. else
  1247. select = math.random(1, 5)
  1248. if select == 1 then
  1249. ball[i].dy = 1
  1250. elseif select == 2 then
  1251. ball[i].dy = 1.2
  1252. elseif select == 3 then
  1253. ball[i].dy = 1.5
  1254. elseif select == 4 then
  1255. ball[i].dy = 1.8
  1256. elseif select == 5 then
  1257. ball[i].dy = 2
  1258. end
  1259. end
  1260. end
  1261. end
  1262. hitIdentifier()
  1263. if ball[i].y <= 0 then
  1264. soundtype = love.math.random(1, 5)
  1265. sounds["wallhit"]:setPitch(ballSpeed / 250)
  1266. sounds["wallhit"]:play()
  1267. ball[i].y = 0
  1268. ball[i].dy = -ball[i].dy
  1269. end
  1270. -- -4 to account for the ball's size
  1271. if ball[i].y >= VIRTUAL_HEIGHT - 40 then
  1272. soundtype = love.math.random(1, 5)
  1273. sounds["wallhit"]:setPitch(ballSpeed / 250)
  1274. sounds["wallhit"]:play()
  1275. ball[i].y = VIRTUAL_HEIGHT - 40
  1276. ball[i].dy = -ball[i].dy
  1277. end
  1278. --love.window.setTitle('Trying to update the ball')
  1279. if timeIsSlow then
  1280. if ballSpeed > originalSpeed / 3 then
  1281. paddle_SPEED = 300
  1282. ballSpeed = ballSpeed / (1 + (dt * 2))
  1283. end
  1284. player1nukescore = player1nukescore - (dt * 50)
  1285. if player1nukescore < 1 or ball[1].dx > 0 then
  1286. timeIsSlow = false
  1287. player1reverbav = false
  1288. ballSpeed = originalSpeed
  1289. sounds["time"]:stop()
  1290. paddle_SPEED = originalPaddle
  1291. end
  1292. end
  1293. if timeIsSlow2 then
  1294. if ballSpeed > originalSpeed / 3 then
  1295. ballSpeed = ballSpeed / (1 + (dt * 2))
  1296. end
  1297. player2nukescore = player2nukescore - (dt * 50)
  1298. if player2nukescore < 1 or ball[1].dx < 0 then
  1299. paddle_SPEED = 300
  1300. timeIsSlow2 = false
  1301. player2reverbav = false
  1302. ballSpeed = originalSpeed
  1303. sounds["time"]:stop()
  1304. paddle_SPEED = originalPaddle
  1305. end
  1306. end
  1307. ball[i]:update(dt)
  1308. end
  1309. end
  1310. goalManager()
  1311. powerAvailability()
  1312. player1:update(dt)
  1313. player2:update(dt)
  1314. end
  1315. function animateConnection()
  1316. if GetIPType(IP) ~= 1 then
  1317. love.graphics.printf("WRONG SYNTAX", 0, VIRTUAL_HEIGHT-80, VIRTUAL_WIDTH, "center")
  1318. else
  1319. counter = counter + 1 / love.timer.getFPS()
  1320. if counter < 0.8 then
  1321. love.graphics.printf("TRYING TO CONNECT.", 0, VIRTUAL_HEIGHT-80, VIRTUAL_WIDTH, "center")
  1322. elseif counter < 1.6 then
  1323. love.graphics.printf("TRYING TO CONNECT..", 0, VIRTUAL_HEIGHT-80, VIRTUAL_WIDTH, "center")
  1324. elseif counter < 2.4 then
  1325. love.graphics.printf("TRYING TO CONNECT...", 0, VIRTUAL_HEIGHT-80, VIRTUAL_WIDTH, "center")
  1326. else
  1327. love.graphics.printf("NO CONNECTION!", 0, VIRTUAL_HEIGHT-80, VIRTUAL_WIDTH, "center")
  1328. end
  1329. end
  1330. end
  1331. function GetIPType(ip)
  1332. -- must pass in a string value
  1333. if ip == nil or type(ip) ~= "string" then
  1334. return 0
  1335. end
  1336. -- check for format 1.11.111.111 for ipv4
  1337. local chunks = {ip:match("(%d+)%.(%d+)%.(%d+)%.(%d+)")}
  1338. if (#chunks == 4) then
  1339. for _,v in pairs(chunks) do
  1340. if (tonumber(v) < 0 or tonumber(v) > 255) then
  1341. return 0
  1342. end
  1343. end
  1344. return 1
  1345. else
  1346. return 0
  1347. end
  1348. -- check for ipv6 format, should be 8 'chunks' of numbers/letters
  1349. local _, chunks = ip:gsub("[%a%d]+%:?", "")
  1350. if chunks == 8 then
  1351. return 2
  1352. end
  1353. -- if we get here, assume we've been given a random string
  1354. return 3
  1355. end