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.

1556 lines
57 KiB

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