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.

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