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.

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