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.

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