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.

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