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.

1654 lines
61 KiB

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