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.

1517 lines
56 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 = 300
  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 = 300
  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
  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. --print("Available counter, " .. globalState .. tostring(love.keyboard.isDown(p2control.counter)))
  490. if (globalState ~= "nettest" and (love.keyboard.isDown(p2control.counter) or hold2)) or lastSentKeyClient == p2control.counter then
  491. sounds["time"]:play()
  492. player2reverbav = false
  493. timeIsSlow2 = true
  494. originalPaddle = paddle_SPEED
  495. originalSpeed = ballSpeed
  496. player2reverbav = 0
  497. potentialnuke2 = 0
  498. potentialstrike2 = 0
  499. end
  500. end
  501. if (player2nukescore >= 200) then
  502. potentialnuke2 = 1
  503. if (((globalState ~= "nettest" and (love.keyboard.isDown(p2control.super) or doubleclick2)) or lastSentKeyClient == p2control.super)) and AGAINST_AI == 0 then
  504. sounds["nuke"]:play()
  505. if areanuclear == 1 then
  506. maxspeed = maxspeed + 50
  507. end
  508. potentialstrike2 = 0
  509. areanuclear = 1
  510. player2reverbav = 0
  511. ballSpeed = ballSpeed * 2
  512. if (synctype == 0) then
  513. paddle_SPEED = paddle_SPEED * 2
  514. end
  515. if (synctype == 1) then
  516. paddle_SPEED = ballSpeed
  517. end
  518. if (synctype == 0) then
  519. AI_SPEED = AI_SPEED * 2.2
  520. end
  521. if (synctype == 1) then
  522. AI_SPEED = ballSpeed * 1.1 / 10
  523. end
  524. player2nukescore = 0
  525. potentialnuke2 = 0
  526. end
  527. end
  528. end
  529. function editor()
  530. if (gameState == "editor") then
  531. if debug then
  532. --print("Editor is active!")
  533. end
  534. local mx, my = love.mouse.getPosition()
  535. mx = mx * DIFFERENCE_X
  536. my = my * DIFFERENCE_Y
  537. if (love.mouse.isDown(2)) then
  538. wallbreaker(mx, my)
  539. end
  540. if (love.mouse.isDown(3)) then
  541. table.insert(walls, newWall(mx, my, 10, wall1width))
  542. end
  543. end
  544. end
  545. function nuclearDraw()
  546. love.graphics.setColor(1, 1, 1, 1)
  547. for i = 1, maxBalls do
  548. love.graphics.circle("fill", ball[i].x, ball[i].y, explosionRange * 100, 100)
  549. end
  550. player1.RED, player1.GREEN, player1.BLUE, player2.RED, player2.GREEN, player2.BLUE =
  551. nuclearanimation / 3,
  552. nuclearanimation / 3,
  553. nuclearanimation / 3,
  554. nuclearanimation / 3,
  555. nuclearanimation / 3,
  556. nuclearanimation / 3
  557. for i = 1, maxBalls do
  558. love.graphics.setColor(nuclearanimation / 3, nuclearanimation / 3, nuclearanimation / 3, 1)
  559. ball[i]:render("controlled")
  560. end
  561. player1:render()
  562. player2:render()
  563. end
  564. function normalDraw()
  565. if (areanuclear == 1) then
  566. love.graphics.clear(1, 1, 1, 1)
  567. else
  568. love.graphics.clear(40 / 255, 40 / 255, 40 / 255, 1)
  569. end
  570. staticanimator()
  571. if MAP_TYPE == 1 then
  572. love.graphics.setColor(1, 0, 0.20, 1)
  573. love.graphics.rectangle("fill", VIRTUAL_WIDTH * 0.5, 0, 10, VIRTUAL_HEIGHT * 0.3)
  574. love.graphics.rectangle("fill", VIRTUAL_WIDTH * 0.5, VIRTUAL_HEIGHT * 0.7, 10, VIRTUAL_HEIGHT * 0.3)
  575. love.graphics.setColor(1, 1, 1, 1)
  576. end
  577. if MAP_TYPE == 2 then
  578. for i, wall in ipairs(walls) do
  579. love.graphics.setColor(1, 1, 1, 1)
  580. love.graphics.rectangle("fill", wall.wallx, wall.wally, 10, wall.wallheight)
  581. end
  582. end
  583. pongDraw()
  584. love.graphics.setFont(smallfont)
  585. for i = 1, maxBalls do
  586. if areanuclear == 1 then
  587. --love.window.setTitle('rendering black')
  588. ball[i]:render("black")
  589. else
  590. --love.window.setTitle('rendering white')
  591. ball[i]:render(" ")
  592. end
  593. end
  594. end
  595. function pongDraw()
  596. --print("Drawing classic pong")
  597. love.graphics.setColor(1, 1, 1, 1)
  598. love.graphics.printf(TEXT, 0, 20, VIRTUAL_WIDTH, "center")
  599. love.graphics.setFont(smallfont)
  600. love.graphics.setFont(scorefont)
  601. if (areanuclear == 1) then
  602. love.graphics.setColor(0, 0, 0, 1)
  603. end
  604. love.graphics.print(tostring(math.floor(player1score)), VIRTUAL_WIDTH / 2 - 500, VIRTUAL_HEIGHT / 12)
  605. love.graphics.print(tostring(math.floor(player2score)), VIRTUAL_WIDTH / 2 + 400, VIRTUAL_HEIGHT / 12)
  606. love.graphics.setColor(1, 1, 1, 1)
  607. displayPoints()
  608. player1:render()
  609. player2:render()
  610. end
  611. function practiceDraw()
  612. player1:render()
  613. love.graphics.rectangle("fill", VIRTUAL_WIDTH-10, 0, 10, VIRTUAL_HEIGHT)
  614. love.graphics.setColor(1, 1, 1, 1)
  615. love.graphics.printf(TEXT, 0, 20, VIRTUAL_WIDTH, "center")
  616. love.graphics.setFont(smallfont)
  617. love.graphics.setFont(scorefont)
  618. love.graphics.print(tostring(math.floor(player1score)), VIRTUAL_WIDTH / 2 - 500, VIRTUAL_HEIGHT / 12)
  619. end
  620. function menuDraw()
  621. love.graphics.setColor(1, 1, 1, 1)
  622. love.graphics.printf(TEXT, 0, 20, VIRTUAL_WIDTH, "center")
  623. love.graphics.setFont(smallfont)
  624. love.graphics.printf(updateTEXT, 0, VIRTUAL_HEIGHT * 0.95, VIRTUAL_WIDTH, "left")
  625. if MAP_TYPE == 1 then
  626. love.graphics.setColor(1, 0, 0.20, 1)
  627. love.graphics.rectangle("fill", VIRTUAL_WIDTH * 0.5, 0, 10, VIRTUAL_HEIGHT * 0.3)
  628. love.graphics.rectangle("fill", VIRTUAL_WIDTH * 0.5, VIRTUAL_HEIGHT * 0.7, 10, VIRTUAL_HEIGHT * 0.3)
  629. love.graphics.setColor(1, 1, 1, 1)
  630. end
  631. if MAP_TYPE == 2 then
  632. for i, wall in ipairs(walls) do
  633. love.graphics.setColor(1, 1, 1, 1)
  634. love.graphics.rectangle("fill", wall.wallx, wall.wally, 10, wall.wallheight)
  635. end
  636. end
  637. player1:render()
  638. player2:render()
  639. ball[1]:render("controlled")
  640. if gameState == "touchcontrols" then
  641. if doubleclick1 or doubleclick2 then
  642. gameState = "menu"
  643. globalState = "menu"
  644. resettinggenius()
  645. end
  646. love.graphics.setFont(smallfont)
  647. 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")
  648. love.graphics.printf("Swipe from red to green for stopping time", 10, 450, VIRTUAL_WIDTH, "center")
  649. end
  650. if gameState == "windowsettings" then
  651. mymenu:butt(gameState, VIRTUAL_WIDTH, VIRTUAL_HEIGHT, settings, sounds, "right")
  652. love.keyboard.mouseisReleased = false
  653. end
  654. if gameState == "editor" then
  655. mymenu:butt(gameState, VIRTUAL_WIDTH, VIRTUAL_HEIGHT, editorpicks, sounds, "right")
  656. love.keyboard.mouseisReleased = false
  657. end
  658. if gameState == "speedSettings" then
  659. mymenu:butt(gameState, VIRTUAL_WIDTH, VIRTUAL_HEIGHT, speedParameters, sounds, "middle")
  660. love.keyboard.mouseisReleased = false
  661. end
  662. if gameState == "controlSettings" then
  663. mymenu:butt(gameState, VIRTUAL_WIDTH, VIRTUAL_HEIGHT, controlSettings, sounds, "control")
  664. love.keyboard.mouseisReleased = false
  665. end
  666. if gameState == "gameMode" then
  667. mymenu:butt(gameState, VIRTUAL_WIDTH, VIRTUAL_HEIGHT, modeSelectorButtons, sounds, "middle")
  668. love.keyboard.mouseisReleased = false
  669. end
  670. if gameState == "chooseIP" then
  671. IPselect = {}
  672. if isAndroid then
  673. table.insert(
  674. IPselect,
  675. newButton(
  676. IPnew,
  677. function()
  678. love.keyboard.setTextInput( true, 0, VIRTUAL_HEIGHT, VIRTUAL_WIDTH, VIRTUAL_HEIGHT/3)
  679. end
  680. )
  681. )
  682. end
  683. table.insert(
  684. IPselect,
  685. newButton(
  686. "LANHost",
  687. function()
  688. globalState = "selfhost"
  689. AGAINST_AI = 0
  690. gameState = "1serve"
  691. ball[1]:reset(1, 1)
  692. end
  693. )
  694. )
  695. table.insert(
  696. IPselect,
  697. newButton(
  698. "Check Server",
  699. function()
  700. IP = IPnew
  701. counter = 0
  702. end
  703. )
  704. )
  705. if status == "offline" then
  706. animateConnection()
  707. elseif status == "nettest" and IP == IPnew then
  708. table.insert(
  709. IPselect,
  710. newButton(
  711. "Connect as Host",
  712. function()
  713. globalState = "nettest"
  714. AGAINST_AI = 0
  715. gameState = "1serve"
  716. ball[1]:reset(1, 1)
  717. end
  718. )
  719. )
  720. elseif status == "clienttest" and IP == IPnew then
  721. table.insert(
  722. IPselect,
  723. newButton(
  724. "Connect as Guest",
  725. function()
  726. globalState = "clienttest"
  727. AGAINST_AI = 0
  728. gameState = "1serve"
  729. ball[1]:reset(1, 1)
  730. end
  731. )
  732. )
  733. elseif status == "full" then
  734. love.graphics.printf("SERVER FULL", 0, VIRTUAL_HEIGHT / 2, VIRTUAL_WIDTH, "center")
  735. end
  736. mymenu:butt(gameState, VIRTUAL_WIDTH, VIRTUAL_HEIGHT, IPselect, sounds, "middle")
  737. love.keyboard.mouseisReleased = false
  738. if not isAndroid then
  739. love.graphics.printf(IPnew, 0, VIRTUAL_HEIGHT / 4, VIRTUAL_WIDTH, "center")
  740. end
  741. love.keyboard.mouseisReleased = false
  742. end
  743. if gameState == "menu" then
  744. mymenu:butt(gameState, VIRTUAL_WIDTH, VIRTUAL_HEIGHT, buttons, sounds, "middle")
  745. love.keyboard.mouseisReleased = false
  746. end
  747. if gameState == "difficulty" then
  748. mymenu:butt(gameState, VIRTUAL_WIDTH, VIRTUAL_HEIGHT, difbuttons, sounds, "middle")
  749. love.keyboard.mouseisReleased = false
  750. end
  751. if gameState == "multiMode" then
  752. mymenu:butt(gameState, VIRTUAL_WIDTH, VIRTUAL_HEIGHT, playerCountButtons, sounds, "middle")
  753. love.keyboard.mouseisReleased = false
  754. end
  755. if gameState == "prdiff" then
  756. mymenu:butt(gameState, VIRTUAL_WIDTH, VIRTUAL_HEIGHT, pracdiff, sounds, "playercount")
  757. love.keyboard.mouseisReleased = false
  758. end
  759. if gameState == 'start' then
  760. love.graphics.push()
  761. love.graphics.translate(VIRTUAL_WIDTH * 0.4, VIRTUAL_HEIGHT * 0.5)
  762. love.graphics.rotate(rotation)
  763. love.graphics.setFont(smallfont)
  764. love.graphics.setColor(200/255, 200/255, 200/255, 1)
  765. if isAndroid then
  766. love.graphics.print("Tap to Start", WINDOW_WIDTH / -10, VIRTUAL_HEIGHT / 8)
  767. else
  768. love.graphics.print("Press Enter to Start", WINDOW_WIDTH / -10, VIRTUAL_HEIGHT / 8)
  769. end
  770. love.graphics.setColor(255, 255, 255, 255)
  771. love.graphics.pop()
  772. end
  773. end
  774. function baseDraw()
  775. love.graphics.clear(40 / 255, 40 / 255, 40 / 255, 1)
  776. if shakeDuration > t then
  777. local dx = love.math.random(-shakeMagnitude, shakeMagnitude)
  778. local dy = love.math.random(-shakeMagnitude, shakeMagnitude)
  779. love.graphics.translate(dx, dy)
  780. end
  781. if globalState == 'menu' then
  782. --print("Drawing menuDraw")
  783. if gameState == 'animation' then
  784. --print("Drawing animation")
  785. intro()
  786. end
  787. if gameState ~= 'animation' then
  788. --print("Drawing notanimtaion")
  789. love.graphics.setFont(scorefont)
  790. menuDraw()
  791. end
  792. end
  793. if globalState == 'base' or globalState == 'reverse' or globalState == 'nettest' or globalState == 'clienttest' then
  794. love.graphics.setFont(smallfont)
  795. if gameState == 'nuclearExplosion' then
  796. nuclearDraw()
  797. end
  798. if gameState == 'play' or gameState == '1serve' or gameState == '2serve' or gameState == 'done' then
  799. --print("Drawing normally")
  800. normalDraw()
  801. end
  802. end
  803. end
  804. function androidDraw()
  805. --HOME BUTTON HERE
  806. mymenu:butt(gameState, VIRTUAL_WIDTH, VIRTUAL_HEIGHT, androidButtons, sounds, "android")
  807. if showTouchControls then
  808. love.graphics.setColor(15/255, 255/255, 15/255, 0.5)
  809. love.graphics.rectangle("fill", 0, 0, 50, VIRTUAL_HEIGHT)
  810. love.graphics.setColor(15/255, 255/255, 15/255, 0.5)
  811. love.graphics.rectangle("fill", VIRTUAL_WIDTH-50, 0, 50, VIRTUAL_HEIGHT)
  812. love.graphics.setColor(255/255, 15/255, 15/255, 0.5)
  813. love.graphics.rectangle("fill", 50, 0, VIRTUAL_WIDTH/2-50, VIRTUAL_HEIGHT)
  814. love.graphics.rectangle("fill", VIRTUAL_WIDTH/2, 0, VIRTUAL_WIDTH/2-50, VIRTUAL_HEIGHT)
  815. love.graphics.setColor(0, 0, 0, 0.5)
  816. love.graphics.rectangle("fill", VIRTUAL_WIDTH/2-5, 0, 10, VIRTUAL_HEIGHT)
  817. end
  818. end
  819. function renderEditor()
  820. if not blockinput then
  821. love.graphics.setColor(1, 0, 0, 1)
  822. love.graphics.rectangle("fill", mx, my, 10, wall1width)
  823. love.graphics.setColor(1, 1, 1, 1)
  824. end
  825. for i, wall in ipairs(walls) do
  826. love.graphics.setColor(1, 1, 1, 1)
  827. love.graphics.rectangle("fill", wall.wallx, wall.wally, 10, wall.wallheight)
  828. end
  829. end
  830. function intro()
  831. love.graphics.setColor(255, 255, 255, light / 255)
  832. love.graphics.draw(image, 0, 0)
  833. end
  834. function displayPoints()
  835. love.graphics.setFont(smallfont)
  836. if areanuclear == 1 then
  837. love.graphics.setColor(0,0,0,1)
  838. end
  839. if (potentialstrike1 == 1 and potentialnuke1 == 0 and player1reverbav == 0) then --FLAG: AVAILABLE SUPER
  840. if (player1striken == 0) then
  841. love.graphics.print(
  842. tostring(math.floor(player1nukescore) .. "[" .. p1control.super .. "]"),
  843. VIRTUAL_WIDTH / 2 - 500,
  844. VIRTUAL_HEIGHT / 60
  845. )
  846. else
  847. love.graphics.print(tostring("READY"), VIRTUAL_WIDTH / 2 - 500, VIRTUAL_HEIGHT / 60)
  848. end
  849. elseif (player1reverbav == 1 and potentialnuke1 == 0 ) then
  850. love.graphics.print(
  851. tostring(
  852. math.floor(player1nukescore) .. "[" .. p1control.super .. "]" .. " [" .. p1control.counter .. "]"
  853. ),
  854. VIRTUAL_WIDTH / 2 - 500,
  855. VIRTUAL_HEIGHT / 60
  856. )
  857. elseif (potentialnuke1 == 1) then
  858. love.graphics.setColor(255, 0, 0, 255)
  859. love.graphics.print(
  860. tostring(
  861. math.floor(player1nukescore) .. "[" .. p1control.super .. "]" .. " [" .. p1control.counter .. "]"
  862. ),
  863. VIRTUAL_WIDTH / 2 - 500,
  864. VIRTUAL_HEIGHT / 60
  865. )
  866. love.graphics.setColor(255, 255, 255, 255)
  867. elseif (potentialnuke1 == 1) then
  868. love.graphics.setColor(255, 0, 0, 255)
  869. love.graphics.print(
  870. tostring(
  871. math.floor(player1nukescore) .. "[" .. p1control.super .. "]"
  872. ),
  873. VIRTUAL_WIDTH / 2 - 500,
  874. VIRTUAL_HEIGHT / 60
  875. )
  876. love.graphics.setColor(255, 255, 255, 255)
  877. else
  878. love.graphics.print(tostring(math.floor(player1nukescore)), VIRTUAL_WIDTH / 2 - 500, VIRTUAL_HEIGHT / 60)
  879. end
  880. if (potentialstrike2 == 1 and player2reverbav == 0) then
  881. if (player2striken == 0) then
  882. love.graphics.print(
  883. tostring(math.floor(player2nukescore) .. "[" .. p2control.super .. "]"),
  884. VIRTUAL_WIDTH / 2 + 430,
  885. VIRTUAL_HEIGHT / 60
  886. )
  887. else
  888. love.graphics.print(tostring("READY"), VIRTUAL_WIDTH / 2 + 430, VIRTUAL_HEIGHT / 60)
  889. end
  890. elseif (potentialnuke2 == 1) then
  891. love.graphics.setColor(255, 0, 0, 255)
  892. love.graphics.print(
  893. tostring(math.floor(player2nukescore) .. "[" .. p2control.super .. "] [" .. p2control.counter .. "]"),
  894. VIRTUAL_WIDTH / 2 + 400,
  895. VIRTUAL_HEIGHT / 60
  896. )
  897. love.graphics.setColor(255, 255, 255, 255)
  898. elseif (potentialnuke2 == 1 and maxBalls > 1) then
  899. love.graphics.setColor(255, 0, 0, 255)
  900. love.graphics.print(
  901. tostring(math.floor(player2nukescore) .. "[" .. p2control.super .. "]"),
  902. VIRTUAL_WIDTH / 2 + 430,
  903. VIRTUAL_HEIGHT / 60
  904. )
  905. love.graphics.setColor(255, 255, 255, 255)
  906. elseif (player2reverbav == 1 and potentialnuke2 == 0 ) then
  907. love.graphics.print(
  908. tostring(math.floor(player2nukescore) .. "[" .. p2control.super .. "] [" .. p2control.counter .. "]"),
  909. VIRTUAL_WIDTH / 2 + 400,
  910. VIRTUAL_HEIGHT / 60
  911. )
  912. else
  913. love.graphics.print(tostring(math.floor(player2nukescore)), VIRTUAL_WIDTH / 2 + 430, VIRTUAL_HEIGHT / 60)
  914. end
  915. end
  916. function hitIdentifier()
  917. if (gameMode == "practice") then
  918. MAP_TYPE = 0
  919. if ball[i].x > VIRTUAL_WIDTH * 0.99 then
  920. soundtype = love.math.random(1, 5)
  921. sounds["wallhit"]:setPitch(ballSpeed / 250)
  922. sounds["wallhit"]:play()
  923. if (ball[i].dx > 0) then
  924. ball[i].x = ball[i].x - 20
  925. else
  926. ball[i].x = ball[i].x + 20
  927. end
  928. ball[i].dx = -ball[i].dx
  929. end
  930. end
  931. if (MAP_TYPE == 1) then
  932. if
  933. ball[i].y < VIRTUAL_HEIGHT * 0.3 and ball[i].x > VIRTUAL_WIDTH * 0.5 and
  934. ball[i].x < VIRTUAL_WIDTH * 0.5 + 5
  935. then
  936. soundtype = love.math.random(1, 5)
  937. sounds["wallhit"]:setPitch(ballSpeed / 250)
  938. sounds["wallhit"]:play()
  939. if (ball[i].dx > 0) then
  940. ball[i].x = ball[i].x - 20
  941. else
  942. ball[i].x = ball[i].x + 20
  943. end
  944. ball[i].dx = -ball[i].dx
  945. end
  946. if
  947. ball[i].y > VIRTUAL_HEIGHT * 0.7 and ball[i].x > VIRTUAL_WIDTH * 0.5 and
  948. ball[i].x < VIRTUAL_WIDTH * 0.5 + 5
  949. then
  950. soundtype = love.math.random(1, 5)
  951. sounds["wallhit"]:setPitch(ballSpeed / 250)
  952. sounds["wallhit"]:play()
  953. if (ball[i].dx > 0) then
  954. ball[i].x = ball[i].x - 20
  955. else
  956. ball[i].x = ball[i].x + 20
  957. end
  958. ball[i].dx = -ball[i].dx
  959. end
  960. end
  961. if (MAP_TYPE == 2) then
  962. for i, wall in ipairs(walls) do
  963. if
  964. (ball[1].y > wall.wally and ball[1].y < wall.wally + wall.wallheight and
  965. ball[1].x > wall.wallx - ballSpeed / 200 and
  966. ball[1].x < wall.wallx + 10 + ballSpeed / 200)
  967. then
  968. controllerSer()
  969. soundtype = love.math.random(1, 5)
  970. sounds["wallhit"]:setPitch(ballSpeed / 250)
  971. sounds["wallhit"]:play()
  972. if (ball[1].dx > 0) then
  973. ball[1].x = ball[1].x - 1
  974. else
  975. ball[1].x = ball[1].x + 1
  976. end
  977. ball[1].dx = -ball[1].dx
  978. elseif
  979. (ball[1].y > wall.wally - 15 and ball[1].y < wall.wally + wall.wallheight + 10 and
  980. ball[1].x > wall.wallx and
  981. ball[1].x < wall.wallx + 10)
  982. then
  983. controllerSer()
  984. soundtype = love.math.random(1, 5)
  985. sounds["wallhit"]:setPitch(ballSpeed / 250)
  986. sounds["wallhit"]:play()
  987. if (ball[1].dy > 0) then
  988. ball[1].y = ball[1].y - 1
  989. else
  990. ball[1].y = ball[1].y + 1
  991. end
  992. ball[1].dy = -ball[1].dy
  993. end
  994. end
  995. end
  996. end
  997. function rules(query, i)
  998. if query == "p1hit" then
  999. if gameMode == "normal" then
  1000. return ball[i]:collides(player1)
  1001. elseif gameMode == "reversegame" then
  1002. return ball[i].x < 0 and ball[i].disabled == false
  1003. end
  1004. end
  1005. if query == "p2hit" then
  1006. if gameMode == "normal" then
  1007. return ball[i]:collides(player2)
  1008. elseif gameMode == "reversegame" then
  1009. return ball[i].x > VIRTUAL_WIDTH-10 and ball[i].disabled == false
  1010. end
  1011. end
  1012. if query == "p1miss" then
  1013. if gameMode == "reversegame" then
  1014. return ball[i]:collides(player1)
  1015. elseif gameMode == "normal" then
  1016. return ball[i].x < 0 and ball[i].disabled == false
  1017. end
  1018. end
  1019. if query == "p2miss" then
  1020. if gameMode == "reversegame" then
  1021. return ball[i]:collides(player2)
  1022. elseif gameMode == "normal" then
  1023. return ball[i].x > VIRTUAL_WIDTH-10 and ball[i].disabled == false
  1024. end
  1025. end
  1026. end
  1027. function clientsBaseGame(dt)
  1028. if gameMode == "reverse" then
  1029. reversegame(dt)
  1030. end
  1031. if player1nukescore > 300 then
  1032. player1nukescore = 300
  1033. end
  1034. if player2nukescore > 300 then
  1035. player2nukescore = 300
  1036. end
  1037. speedControl()
  1038. balancer()
  1039. if t < shakeDuration then
  1040. t = t + dt
  1041. end
  1042. if (lastSentKeyP1 == p1control.up) then
  1043. player1.dy = (paddle_SPEED + p2bonus) * -1
  1044. --print("moving player1 up")
  1045. elseif (lastSentKeyP1 == p1control.down) then
  1046. player1.dy = paddle_SPEED + p2bonus
  1047. --print("moving player1 down")
  1048. else
  1049. player1.dy = 0
  1050. ----print("stopping player")
  1051. end
  1052. if ((love.keyboard.isDown(p2control.up) or sectortouched(1))) then
  1053. player2.dy = (paddle_SPEED + p2bonus) * -1
  1054. elseif ((love.keyboard.isDown(p2control.down)) or sectortouched(4)) then
  1055. player2.dy = paddle_SPEED + p2bonus
  1056. else
  1057. player2.dy = 0
  1058. end
  1059. --print("T = " .. tostring(t))
  1060. serveBot()
  1061. if gameState == 'play' then
  1062. if (AGAINST_AI == 1) then
  1063. AI(player2, maxBalls, AI_LEVEL)
  1064. end
  1065. --print(areanuclear .. striken .. player1score .. player2score)
  1066. for i = 1, maxBalls do
  1067. if rules("p1hit", i) then
  1068. if (areanuclear == 0 and striken == 1 and (player1score > ptw-2 or player2score > ptw-2)) then
  1069. --print("Calling animation")
  1070. superanimator("tensehit", 1)
  1071. --print("AREA NUCLEAR?" .. areanuclear)
  1072. end
  1073. if gameMode == "practice" then
  1074. player1score = player1score + 1
  1075. end
  1076. t = 0
  1077. if (ballSpeed > 200) then
  1078. shakeMagnitude = ballSpeed / 200
  1079. else
  1080. shakeMagnitude = 0
  1081. end
  1082. shakeDuration = 1
  1083. randomtext = love.math.random(1, #textphrases)
  1084. TEXT = textphrases[randomtext]
  1085. soundtype = love.math.random(1, 1.2)
  1086. if (player1striken == 1) then
  1087. TEXT = "PLAYER 1 STRIKES"
  1088. ballSpeed = ballSpeed + player1nukescore
  1089. potentialnuke1 = 0
  1090. player1striken = 0
  1091. player1nukescore = 0
  1092. potentialstrike1 = 0
  1093. striken = 1
  1094. if areanuclear == 0 then
  1095. sounds["striking"]:setPitch(ballSpeed / 250)
  1096. sounds["striking"]:play()
  1097. else
  1098. sounds["nuclearhit"]:setPitch(1)
  1099. sounds["nuclearhit"]:play()
  1100. end
  1101. if areanuclear == 0 then
  1102. superanimator("tensehit", 1)
  1103. end
  1104. else
  1105. if areanuclear == 0 then
  1106. sounds["beep"]:setPitch(ballSpeed / 250)
  1107. sounds["beep"]:play()
  1108. else
  1109. sounds["nuclearhit"]:setPitch(1)
  1110. sounds["nuclearhit"]:play()
  1111. end
  1112. end
  1113. if (striken == 1) then
  1114. player1nukescore = player1nukescore * 1.5
  1115. if (synctype == 0) then
  1116. paddle_SPEED = paddle_SPEED * 1.10
  1117. elseif (synctype == 1) then
  1118. paddle_SPEED = ballSpeed
  1119. end
  1120. if (synctype == 0) then
  1121. AI_SPEED = AI_SPEED * 1.10
  1122. end
  1123. if (synctype == 1) then
  1124. AI_SPEED = ballSpeed * 1.1 / 10
  1125. end
  1126. ballSpeed = ballSpeed * 1.10
  1127. end
  1128. player1nukescore = player1nukescore + 10
  1129. ball[i].dx = -ball[i].dx
  1130. ball[i].x = player1.x + 30
  1131. end
  1132. if rules("p2hit", i) then
  1133. --ameState = 'quickanim'
  1134. t = 0
  1135. shakeDuration = 1
  1136. if
  1137. (areanuclear == 0 and
  1138. (striken == 1 and (player1score > ptw-2 or player2score > ptw-2)))
  1139. then
  1140. --print("AREA NUCLEAR?" .. areanuclear)
  1141. superanimator("tensehit", 2)
  1142. end
  1143. if (ballSpeed > 200) then
  1144. shakeMagnitude = ballSpeed / 200
  1145. else
  1146. shakeMagnitude = 0
  1147. end
  1148. randomtext = love.math.random(1, #textphrases)
  1149. TEXT = textphrases[randomtext]
  1150. soundtype = love.math.random(1, 1.2)
  1151. if (player2striken == 1) then
  1152. TEXT = "PLAYER 2 STRIKES"
  1153. ballSpeed = ballSpeed + player2nukescore
  1154. striken = 1
  1155. player2striken = 0
  1156. potentialnuke2 = 0
  1157. player2nukescore = 0
  1158. potentialstrike2 = 0
  1159. --print("AREA NUCLEAR?" .. areanuclear)
  1160. if areanuclear == 0 then
  1161. superanimator("tensehit", 2)
  1162. end
  1163. if areanuclear == 0 then
  1164. sounds["striking"]:setPitch(ballSpeed / 250)
  1165. sounds["striking"]:play()
  1166. else
  1167. sounds["nuclearhit"]:setPitch(1)
  1168. sounds["nuclearhit"]:play()
  1169. end
  1170. elseif (striken == 1) then
  1171. player2nukescore = player2nukescore * 1.5
  1172. if (synctype == 0) then
  1173. paddle_SPEED = paddle_SPEED * 1.10
  1174. end
  1175. if (synctype == 1) then
  1176. paddle_SPEED = ballSpeed
  1177. end
  1178. if (synctype == 0) then
  1179. AI_SPEED = AI_SPEED * 1.10
  1180. end
  1181. if (synctype == 1) then
  1182. AI_SPEED = ballSpeed * 1.1 / 10
  1183. end
  1184. ballSpeed = ballSpeed * 1.10
  1185. if areanuclear == 0 then
  1186. sounds["beep"]:setPitch(ballSpeed / 250)
  1187. sounds["beep"]:play()
  1188. else
  1189. sounds["nuclearhit"]:setPitch(1)
  1190. sounds["nuclearhit"]:play()
  1191. end
  1192. else
  1193. if areanuclear == 0 then
  1194. sounds["beep"]:setPitch(ballSpeed / 250)
  1195. sounds["beep"]:play()
  1196. else
  1197. sounds["nuclearhit"]:setPitch(1)
  1198. sounds["nuclearhit"]:play()
  1199. end
  1200. end
  1201. player2nukescore = player2nukescore + 10
  1202. ball[i].dx = -ball[i].dx
  1203. ball[i].x = player2.x - 30
  1204. if ((love.keyboard.isDown(p2control.up)) or sectortouched(1)) then
  1205. select = math.random(1, 5)
  1206. if select == 1 then
  1207. ball[i].dy = -1
  1208. elseif select == 2 then
  1209. ball[i].dy = -1.2
  1210. elseif select == 3 then
  1211. ball[i].dy = -1.5
  1212. elseif select == 4 then
  1213. ball[i].dy = -1.8
  1214. elseif select == 5 then
  1215. ball[i].dy = -2
  1216. end
  1217. elseif (love.keyboard.isDown(p2control.down) or sectortouched(4))then
  1218. select = math.random(1, 5)
  1219. if select == 1 then
  1220. ball[i].dy = 1
  1221. elseif select == 2 then
  1222. ball[i].dy = 1.2
  1223. elseif select == 3 then
  1224. ball[i].dy = 1.5
  1225. elseif select == 4 then
  1226. ball[i].dy = 1.8
  1227. elseif select == 5 then
  1228. ball[i].dy = 2
  1229. end
  1230. else
  1231. if ball[i].dy < 0 then
  1232. select = math.random(1, 5)
  1233. if select == 1 then
  1234. ball[i].dy = -1
  1235. elseif select == 2 then
  1236. ball[i].dy = -1.2
  1237. elseif select == 3 then
  1238. ball[i].dy = -1.5
  1239. elseif select == 4 then
  1240. ball[i].dy = -1.8
  1241. elseif select == 5 then
  1242. ball[i].dy = -2
  1243. end
  1244. else
  1245. select = math.random(1, 5)
  1246. if select == 1 then
  1247. ball[i].dy = 1
  1248. elseif select == 2 then
  1249. ball[i].dy = 1.2
  1250. elseif select == 3 then
  1251. ball[i].dy = 1.5
  1252. elseif select == 4 then
  1253. ball[i].dy = 1.8
  1254. elseif select == 5 then
  1255. ball[i].dy = 2
  1256. end
  1257. end
  1258. end
  1259. end
  1260. hitIdentifier()
  1261. if ball[i].y <= 0 then
  1262. soundtype = love.math.random(1, 5)
  1263. sounds["wallhit"]:setPitch(ballSpeed / 250)
  1264. sounds["wallhit"]:play()
  1265. ball[i].y = 0
  1266. ball[i].dy = -ball[i].dy
  1267. end
  1268. -- -4 to account for the ball's size
  1269. if ball[i].y >= VIRTUAL_HEIGHT - 40 then
  1270. soundtype = love.math.random(1, 5)
  1271. sounds["wallhit"]:setPitch(ballSpeed / 250)
  1272. sounds["wallhit"]:play()
  1273. ball[i].y = VIRTUAL_HEIGHT - 40
  1274. ball[i].dy = -ball[i].dy
  1275. end
  1276. --love.window.setTitle('Trying to update the ball')
  1277. if timeIsSlow then
  1278. if ballSpeed > originalSpeed / 3 then
  1279. paddle_SPEED = 300
  1280. ballSpeed = ballSpeed / (1 + (dt * 2))
  1281. end
  1282. player1nukescore = player1nukescore - (dt * 50)
  1283. if player1nukescore < 1 or ball[1].dx > 0 then
  1284. timeIsSlow = false
  1285. player1reverbav = false
  1286. ballSpeed = originalSpeed
  1287. sounds["time"]:stop()
  1288. paddle_SPEED = originalPaddle
  1289. end
  1290. end
  1291. if timeIsSlow2 then
  1292. if ballSpeed > originalSpeed / 3 then
  1293. ballSpeed = ballSpeed / (1 + (dt * 2))
  1294. end
  1295. player2nukescore = player2nukescore - (dt * 50)
  1296. if player2nukescore < 1 or ball[1].dx < 0 then
  1297. paddle_SPEED = 300
  1298. timeIsSlow2 = false
  1299. player2reverbav = false
  1300. ballSpeed = originalSpeed
  1301. sounds["time"]:stop()
  1302. paddle_SPEED = originalPaddle
  1303. end
  1304. end
  1305. ball[i]:update(dt)
  1306. end
  1307. end
  1308. goalManager()
  1309. powerAvailability()
  1310. player1:update(dt)
  1311. player2:update(dt)
  1312. end
  1313. function animateConnection()
  1314. if GetIPType(IP) ~= 1 then
  1315. love.graphics.printf("WRONG SYNTAX", 0, VIRTUAL_HEIGHT-80, VIRTUAL_WIDTH, "center")
  1316. else
  1317. counter = counter + 1 / love.timer.getFPS()
  1318. if counter < 0.8 then
  1319. love.graphics.printf("TRYING TO CONNECT.", 0, VIRTUAL_HEIGHT-80, VIRTUAL_WIDTH, "center")
  1320. elseif counter < 1.6 then
  1321. love.graphics.printf("TRYING TO CONNECT..", 0, VIRTUAL_HEIGHT-80, VIRTUAL_WIDTH, "center")
  1322. elseif counter < 2.4 then
  1323. love.graphics.printf("TRYING TO CONNECT...", 0, VIRTUAL_HEIGHT-80, VIRTUAL_WIDTH, "center")
  1324. else
  1325. love.graphics.printf("NO CONNECTION!", 0, VIRTUAL_HEIGHT-80, VIRTUAL_WIDTH, "center")
  1326. end
  1327. end
  1328. end
  1329. function GetIPType(ip)
  1330. -- must pass in a string value
  1331. if ip == nil or type(ip) ~= "string" then
  1332. return 0
  1333. end
  1334. -- check for format 1.11.111.111 for ipv4
  1335. local chunks = {ip:match("(%d+)%.(%d+)%.(%d+)%.(%d+)")}
  1336. if (#chunks == 4) then
  1337. for _,v in pairs(chunks) do
  1338. if (tonumber(v) < 0 or tonumber(v) > 255) then
  1339. return 0
  1340. end
  1341. end
  1342. return 1
  1343. else
  1344. return 0
  1345. end
  1346. -- check for ipv6 format, should be 8 'chunks' of numbers/letters
  1347. local _, chunks = ip:gsub("[%a%d]+%:?", "")
  1348. if chunks == 8 then
  1349. return 2
  1350. end
  1351. -- if we get here, assume we've been given a random string
  1352. return 3
  1353. end
  1354. function menuDemo(dt)
  1355. paddle_SPEED = 200
  1356. ballSpeed = 200
  1357. if ball[1].dx > 0 then
  1358. AI(player2, maxBalls, 1300)
  1359. player1.goal = 360
  1360. elseif ball[1].dx < 0 then
  1361. AI(player1, maxBalls, 1300)
  1362. player2.goal = 360
  1363. end
  1364. print(neededTarget, neededTarget1)
  1365. --print("menu demo active")
  1366. ball[1]:update(dt)
  1367. player1:update(dt)
  1368. player2:update(dt)
  1369. if ball[1].x < player1.x+15 then
  1370. player1.y = ball[1].y-player1.height
  1371. end
  1372. if ball[1].x > player2.x-15 then
  1373. player2.y = ball[1].y-player2.height
  1374. end
  1375. if ball[1].x >= player2.x-7 then
  1376. select = math.random(1, 2)
  1377. if ball[1].dy < 0 then
  1378. select = math.random(1, 5)
  1379. if select == 1 then
  1380. ball[1].dy = -1
  1381. elseif select == 2 then
  1382. ball[1].dy = -1.2
  1383. elseif select == 3 then
  1384. ball[1].dy = -1.5
  1385. elseif select == 4 then
  1386. ball[1].dy = -1.8
  1387. elseif select == 5 then
  1388. ball[1].dy = -2
  1389. end
  1390. else
  1391. select = math.random(1, 5)
  1392. if select == 1 then
  1393. ball[1].dy = 1
  1394. elseif select == 2 then
  1395. ball[1].dy = 1.2
  1396. elseif select == 3 then
  1397. ball[1].dy = 1.5
  1398. elseif select == 4 then
  1399. ball[1].dy = 1.8
  1400. elseif select == 5 then
  1401. ball[1].dy = 2
  1402. end
  1403. end
  1404. ball[1].x = player2.x-8
  1405. ball[1].dx = -ball[1].dx
  1406. ball[1].dy = -ball[1].dy
  1407. end
  1408. if ball[1].x <= player1.x+7 then
  1409. select = math.random(1, 2)
  1410. if ball[1].dy < 0 then
  1411. select = math.random(1, 5)
  1412. if select == 1 then
  1413. ball[1].dy = -1
  1414. elseif select == 2 then
  1415. ball[1].dy = -1.2
  1416. elseif select == 3 then
  1417. ball[1].dy = -1.5
  1418. elseif select == 4 then
  1419. ball[1].dy = -1.8
  1420. elseif select == 5 then
  1421. ball[1].dy = -2
  1422. end
  1423. else
  1424. select = math.random(1, 5)
  1425. if select == 1 then
  1426. ball[1].dy = 1
  1427. elseif select == 2 then
  1428. ball[1].dy = 1.2
  1429. elseif select == 3 then
  1430. ball[1].dy = 1.5
  1431. elseif select == 4 then
  1432. ball[1].dy = 1.8
  1433. elseif select == 5 then
  1434. ball[1].dy = 2
  1435. end
  1436. end
  1437. ball[1].x = player1.x+8
  1438. ball[1].dx = -ball[1].dx
  1439. ball[1].dy = -ball[1].dy
  1440. end
  1441. if ball[1].y <= 0 then
  1442. soundtype = love.math.random(1, 5)
  1443. sounds["wallhit"]:setPitch(ballSpeed / 250)
  1444. sounds["wallhit"]:play()
  1445. ball[1].y = 0
  1446. ball[1].dy = -ball[1].dy
  1447. end
  1448. -- -4 to account for the ball's size
  1449. if ball[1].y >= VIRTUAL_HEIGHT - 40 then
  1450. soundtype = love.math.random(1, 5)
  1451. sounds["wallhit"]:setPitch(ballSpeed / 250)
  1452. sounds["wallhit"]:play()
  1453. ball[1].y = VIRTUAL_HEIGHT - 40
  1454. ball[1].dy = -ball[1].dy
  1455. end
  1456. end