A pong clone, but with a twist!
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.

1211 line
45 KiB

  1. function basegame(dt)
  2. if gameMode == "reverse" then
  3. reversegame(dt)
  4. end
  5. if player1nukescore > 300 then
  6. player1nukescore = 300
  7. end
  8. if player2nukescore > 300 then
  9. player2nukescore = 300
  10. end
  11. speedControl()
  12. balancer()
  13. if t < shakeDuration then
  14. t = t + dt
  15. end
  16. --print("T = " .. tostring(t))
  17. serveBot()
  18. if gameState == 'play' then
  19. if (AGAINST_AI == 1) then
  20. AI(player2, maxBalls, AI_LEVEL)
  21. end
  22. if (love.keyboard.isDown(p1control.up)) then
  23. player1.dy = (paddle_SPEED + p1bonus) * -1
  24. elseif (love.keyboard.isDown(p1control.down)) then
  25. player1.dy = paddle_SPEED + p1bonus
  26. else
  27. player1.dy = 0
  28. end
  29. if (AGAINST_AI == 0) then
  30. if ((globalState ~= "nettest" and love.keyboard.isDown(p2control.up)) ) then
  31. player2.dy = (paddle_SPEED + p2bonus) * -1
  32. elseif ((globalState ~= "nettest" and love.keyboard.isDown(p2control.down))) then
  33. player2.dy = paddle_SPEED + p2bonus
  34. elseif (globalState ~= "nettest") then
  35. player2.dy = 0
  36. end
  37. end
  38. --print(areanuclear .. striken .. player1score .. player2score)
  39. for i = 1, maxBalls do
  40. if rules("p1hit", i) then
  41. if (areanuclear == 0 and striken == 1 and (player1score > ptw-2 or player2score > ptw-2)) then
  42. --print("Calling animation")
  43. print("AREA NUCLEAR?" .. areanuclear)
  44. superanimator("tensehit", 1)
  45. end
  46. if gameMode == "practice" then
  47. player1score = player1score + 1
  48. end
  49. t = 0
  50. if (ballSpeed > 200) then
  51. shakeMagnitude = ballSpeed / 200
  52. else
  53. shakeMagnitude = 0
  54. end
  55. shakeDuration = 1
  56. randomtext = love.math.random(1, #textphrases)
  57. TEXT = textphrases[randomtext]
  58. soundtype = love.math.random(1, 1.2)
  59. if (player1striken == 1) then
  60. TEXT = "PLAYER 1 STRIKES"
  61. ballSpeed = ballSpeed + player1nukescore
  62. potentialnuke1 = 0
  63. player1striken = 0
  64. player1nukescore = 0
  65. potentialstrike1 = 0
  66. striken = 1
  67. if areanuclear == 0 then
  68. sounds["striking"]:setPitch(ballSpeed / 250)
  69. sounds["striking"]:play()
  70. else
  71. sounds["nuclearhit"]:setPitch(1)
  72. sounds["nuclearhit"]:play()
  73. end
  74. print("AREA NUCLEAR?" .. areanuclear)
  75. if areanuclear == 0 then
  76. superanimator("tensehit", 1)
  77. end
  78. else
  79. if areanuclear == 0 then
  80. sounds["beep"]:setPitch(ballSpeed / 250)
  81. sounds["beep"]:play()
  82. else
  83. sounds["nuclearhit"]:setPitch(1)
  84. sounds["nuclearhit"]:play()
  85. end
  86. end
  87. if (striken == 1) then
  88. player1nukescore = player1nukescore * 1.2
  89. if (synctype == 0) then
  90. paddle_SPEED = paddle_SPEED * 1.10
  91. elseif (synctype == 1) then
  92. paddle_SPEED = ballSpeed / 10
  93. end
  94. if (synctype == 0) then
  95. AI_SPEED = AI_SPEED * 1.10
  96. end
  97. if (synctype == 1) then
  98. AI_SPEED = ballSpeed * 1.1 / 10
  99. end
  100. ballSpeed = ballSpeed * 1.10
  101. end
  102. player1nukescore = player1nukescore + 10
  103. ball[i].dx = -ball[i].dx
  104. ball[i].x = player1.x + 30
  105. if (love.keyboard.isDown(p1control.up)) then
  106. select = math.random(1, 5)
  107. if select == 1 then
  108. ball[i].dy = -1
  109. elseif select == 2 then
  110. ball[i].dy = -1.2
  111. elseif select == 3 then
  112. ball[i].dy = -1.5
  113. elseif select == 4 then
  114. ball[i].dy = -1.8
  115. elseif select == 5 then
  116. ball[i].dy = -2
  117. end
  118. elseif love.keyboard.isDown(p1control.down) then
  119. select = math.random(1, 5)
  120. if select == 1 then
  121. ball[i].dy = 1
  122. elseif select == 2 then
  123. ball[i].dy = 1.2
  124. elseif select == 3 then
  125. ball[i].dy = 1.5
  126. elseif select == 4 then
  127. ball[i].dy = 1.8
  128. elseif select == 5 then
  129. ball[i].dy = 2
  130. end
  131. else
  132. if ball[i].dy < 0 then
  133. select = math.random(1, 5)
  134. if select == 1 then
  135. ball[i].dy = -1
  136. elseif select == 2 then
  137. ball[i].dy = -1.2
  138. elseif select == 3 then
  139. ball[i].dy = -1.5
  140. elseif select == 4 then
  141. ball[i].dy = -1.8
  142. elseif select == 5 then
  143. ball[i].dy = -2
  144. end
  145. else
  146. select = math.random(1, 5)
  147. if select == 1 then
  148. ball[i].dy = 1
  149. elseif select == 2 then
  150. ball[i].dy = 1.2
  151. elseif select == 3 then
  152. ball[i].dy = 1.5
  153. elseif select == 4 then
  154. ball[i].dy = 1.8
  155. elseif select == 5 then
  156. ball[i].dy = 2
  157. end
  158. end
  159. end
  160. end
  161. if rules("p2hit", i) then
  162. --ameState = 'quickanim'
  163. t = 0
  164. shakeDuration = 1
  165. if
  166. (areanuclear == 0 and
  167. (striken == 1 and (player1score > ptw-2 or player2score > ptw-2)))
  168. then
  169. print("AREA NUCLEAR?" .. areanuclear)
  170. superanimator("tensehit", 2)
  171. end
  172. if (ballSpeed > 200) then
  173. shakeMagnitude = ballSpeed / 200
  174. else
  175. shakeMagnitude = 0
  176. end
  177. randomtext = love.math.random(1, #textphrases)
  178. TEXT = textphrases[randomtext]
  179. soundtype = love.math.random(1, 1.2)
  180. if (player2striken == 1) then
  181. TEXT = "PLAYER 2 STRIKES"
  182. ballSpeed = ballSpeed + player2nukescore
  183. striken = 1
  184. player2striken = 0
  185. potentialnuke2 = 0
  186. player2nukescore = 0
  187. potentialstrike2 = 0
  188. print("AREA NUCLEAR?" .. areanuclear)
  189. if areanuclear == 0 then
  190. superanimator("tensehit", 2)
  191. end
  192. if areanuclear == 0 then
  193. sounds["striking"]:setPitch(ballSpeed / 250)
  194. sounds["striking"]:play()
  195. else
  196. sounds["nuclearhit"]:setPitch(1)
  197. sounds["nuclearhit"]:play()
  198. end
  199. elseif (striken == 1) then
  200. player2nukescore = player2nukescore * 1.5
  201. if (synctype == 0) then
  202. paddle_SPEED = paddle_SPEED * 1.10
  203. end
  204. if (synctype == 1) then
  205. paddle_SPEED = ballSpeed / 10
  206. end
  207. if (synctype == 0) then
  208. AI_SPEED = AI_SPEED * 1.10
  209. end
  210. if (synctype == 1) then
  211. AI_SPEED = ballSpeed * 1.1 / 10
  212. end
  213. ballSpeed = ballSpeed * 1.10
  214. if areanuclear == 0 then
  215. sounds["beep"]:setPitch(ballSpeed / 250)
  216. sounds["beep"]:play()
  217. else
  218. sounds["nuclearhit"]:setPitch(1)
  219. sounds["nuclearhit"]:play()
  220. end
  221. else
  222. if areanuclear == 0 then
  223. sounds["beep"]:setPitch(ballSpeed / 250)
  224. sounds["beep"]:play()
  225. else
  226. sounds["nuclearhit"]:setPitch(1)
  227. sounds["nuclearhit"]:play()
  228. end
  229. end
  230. player2nukescore = player2nukescore + 10
  231. ball[i].dx = -ball[i].dx
  232. ball[i].x = player2.x - 30
  233. if ((globalState ~= "nettest" and love.keyboard.isDown(p2control.up) ) or AI_SPEED < 0 or lastSentKeyClient == p2control.up) then
  234. select = math.random(1, 5)
  235. if select == 1 then
  236. ball[i].dy = -1
  237. elseif select == 2 then
  238. ball[i].dy = -1.2
  239. elseif select == 3 then
  240. ball[i].dy = -1.5
  241. elseif select == 4 then
  242. ball[i].dy = -1.8
  243. elseif select == 5 then
  244. ball[i].dy = -2
  245. end
  246. elseif (globalState ~= "nettest" and love.keyboard.isDown(p2control.down)) or AI_SPEED > 0 or lastSentKeyClient == p2control.down then
  247. select = math.random(1, 5)
  248. if select == 1 then
  249. ball[i].dy = 1
  250. elseif select == 2 then
  251. ball[i].dy = 1.2
  252. elseif select == 3 then
  253. ball[i].dy = 1.5
  254. elseif select == 4 then
  255. ball[i].dy = 1.8
  256. elseif select == 5 then
  257. ball[i].dy = 2
  258. end
  259. else
  260. if ball[i].dy < 0 then
  261. select = math.random(1, 5)
  262. if select == 1 then
  263. ball[i].dy = -1
  264. elseif select == 2 then
  265. ball[i].dy = -1.2
  266. elseif select == 3 then
  267. ball[i].dy = -1.5
  268. elseif select == 4 then
  269. ball[i].dy = -1.8
  270. elseif select == 5 then
  271. ball[i].dy = -2
  272. end
  273. else
  274. select = math.random(1, 5)
  275. if select == 1 then
  276. ball[i].dy = 1
  277. elseif select == 2 then
  278. ball[i].dy = 1.2
  279. elseif select == 3 then
  280. ball[i].dy = 1.5
  281. elseif select == 4 then
  282. ball[i].dy = 1.8
  283. elseif select == 5 then
  284. ball[i].dy = 2
  285. end
  286. end
  287. end
  288. end
  289. hitIdentifier()
  290. if ball[i].y <= 0 then
  291. soundtype = love.math.random(1, 5)
  292. sounds["wallhit"]:setPitch(ballSpeed / 250)
  293. sounds["wallhit"]:play()
  294. ball[i].y = 0
  295. ball[i].dy = -ball[i].dy
  296. end
  297. -- -4 to account for the ball's size
  298. if ball[i].y >= VIRTUAL_HEIGHT - 40 then
  299. soundtype = love.math.random(1, 5)
  300. sounds["wallhit"]:setPitch(ballSpeed / 250)
  301. sounds["wallhit"]:play()
  302. ball[i].y = VIRTUAL_HEIGHT - 40
  303. ball[i].dy = -ball[i].dy
  304. end
  305. --love.window.setTitle('Trying to update the ball')
  306. if timeIsSlow then
  307. if ballSpeed > originalSpeed / 3 then
  308. paddle_SPEED = 30
  309. ballSpeed = ballSpeed / (1 + (dt * 2))
  310. end
  311. player1nukescore = player1nukescore - (dt * 50)
  312. if player1nukescore < 1 or ball[1].dx > 0 then
  313. timeIsSlow = false
  314. player1reverbav = false
  315. ballSpeed = originalSpeed
  316. sounds["time"]:stop()
  317. paddle_SPEED = originalPaddle
  318. end
  319. end
  320. if timeIsSlow2 then
  321. if ballSpeed > originalSpeed / 3 then
  322. ballSpeed = ballSpeed / (1 + (dt * 2))
  323. end
  324. player2nukescore = player2nukescore - (dt * 50)
  325. if player2nukescore < 1 or ball[1].dx < 0 then
  326. paddle_SPEED = 30
  327. timeIsSlow2 = false
  328. player2reverbav = false
  329. ballSpeed = originalSpeed
  330. sounds["time"]:stop()
  331. paddle_SPEED = originalPaddle
  332. end
  333. end
  334. ball[i]:update(dt)
  335. end
  336. end
  337. goalManager()
  338. powerAvailability()
  339. player1:update(dt)
  340. player2:update(dt)
  341. end
  342. function debugCheck(dt)
  343. if (gameState == "menu") then
  344. updateTEXT = "0.7.6 Chalkboard Update"
  345. end
  346. dangerChecker()
  347. elapsed = elapsed + dt
  348. rotation = math.sin(elapsed * 2.5) * 0.7
  349. if gameState == "assign" then
  350. controlChanger()
  351. end
  352. editor()
  353. mapChanger()
  354. end
  355. function goalManager()
  356. for i = 1, maxBalls do
  357. if (rules("p1miss", i)) then
  358. ball[i].disabled = true
  359. ball[i].x = 2000
  360. if ballsAlive() == false then
  361. if (nuckemodactive == 0) then
  362. areanuclear = 0
  363. nuclearanimation = 3
  364. end
  365. striken = 0
  366. player1striken = 0
  367. player2striken = 0
  368. ballSpeed = ballSet
  369. if (synctype == 0) then
  370. paddle_SPEED = ballSet / 10
  371. end
  372. if (synctype == 1) then
  373. paddle_SPEED = ballSpeed / 10
  374. end
  375. AI_SPEED = difficultyl / 10
  376. for i = 1, maxBalls do
  377. ball[i]:reset(i)
  378. end
  379. if (player2score == ptw and gameMode ~= "practice") then
  380. for i = 1, maxBalls do
  381. ball[i]:reset(i)
  382. end
  383. sounds["win"]:play()
  384. gameState = "done"
  385. TEXT = "Player 2 Won!"
  386. else
  387. gameState = "1serve"
  388. serveBot()
  389. end
  390. end
  391. player2score = player2score + 1
  392. end
  393. if (rules("p2miss", i)) then
  394. ball[i].disabled = true
  395. ball[i].x = 2000
  396. if ballsAlive() == false then
  397. if (nuckemodactive == 0) then
  398. areanuclear = 0
  399. nuclearanimation = 3
  400. end
  401. striken = 0
  402. player1striken = 0
  403. player2striken = 0
  404. ballSpeed = ballSet
  405. if (synctype == 0) then
  406. paddle_SPEED = ballSet / 10
  407. AI_SPEED = ballSet / 10
  408. end
  409. if (synctype == 1) then
  410. paddle_SPEED = ballSpeed / 10
  411. AI_SPEED = ballSpeed / 10
  412. end
  413. AI_SPEED = difficultyl / 10
  414. if (player1score == ptw) then
  415. ball[i]:reset(i)
  416. sounds["win"]:play()
  417. gameState = "done"
  418. TEXT = "Player 1 Won!"
  419. else
  420. gameState = "2serve"
  421. serveBot()
  422. ball[i]:reset(i)
  423. end
  424. end
  425. sounds["score"]:play()
  426. player1score = player1score + 1
  427. end
  428. end
  429. end
  430. function powerAvailability()
  431. if (player1nukescore >= 20 and player1nukescore < 140) then
  432. potentialstrike1 = 1
  433. if (((globalState ~= "clienttest" and love.keyboard.isDown(p1control.super)) or (confirmation == "confirmed" and lastSentKeyP1 == p1control.super)) ) then
  434. player1striken = 1
  435. player1reverbav = 0
  436. end
  437. end
  438. if (player1nukescore >= 140) and timeIsSlow2 == false and timeIsSlow == false then
  439. player1reverbav = 1
  440. if ((confirmation == "confirmed" and lastSentKeyP1 == p1control.counter) or (globalState ~= "clienttest" and love.keyboard.isDown(p1control.counter))) then
  441. powerControl(1, "special")
  442. end
  443. end
  444. if (player1nukescore >= 200) then
  445. potentialnuke1 = 1
  446. if ((confirmation == "confirmed" and lastSentKeyP1 == p1control.super)or (globalState ~= "clienttest" and love.keyboard.isDown(p1control.super))) then
  447. sounds["nuke"]:play()
  448. if areanuclear == 1 then
  449. maxspeed = maxspeed + 50
  450. end
  451. areanuclear = 1
  452. potentialstrike1 = 0
  453. striken = 0
  454. ballSpeed = ballSpeed * 2
  455. if (synctype == 0) then
  456. paddle_SPEED = paddle_SPEED * 2
  457. end
  458. if (synctype == 1) then
  459. paddle_SPEED = ballSpeed / 10
  460. end
  461. if (synctype == 0) then
  462. AI_SPEED = AI_SPEED * 2.2
  463. end
  464. if (synctype == 1) then
  465. AI_SPEED = ballSpeed * 1.1 / 10
  466. end
  467. player1nukescore = 0
  468. player1reverbav = 0
  469. potentialnuke1 = 0
  470. end
  471. end
  472. if (player2nukescore >= 20 and player2nukescore <= 140) then
  473. potentialstrike2 = 1
  474. if (AGAINST_AI == 0) then
  475. if ((globalState ~= "nettest" and love.keyboard.isDown(p2control.super)) or lastSentKeyClient == p2control.super ) then
  476. player2striken = 1
  477. player2reverbav = 0
  478. end
  479. end
  480. end
  481. if (player2nukescore >= 140) and timeIsSlow == false and timeIsSlow2 == false then
  482. player2reverbav = 1
  483. if (globalState ~= "nettest" and love.keyboard.isDown(p2control.counter)) or lastSentKeyClient == p2control.counter then
  484. sounds["time"]:play()
  485. player2reverbav = false
  486. timeIsSlow2 = true
  487. originalPaddle = paddle_SPEED
  488. originalSpeed = ballSpeed
  489. player2reverbav = 0
  490. potentialnuke2 = 0
  491. potentialstrike2 = 0
  492. end
  493. end
  494. if (player2nukescore >= 200) then
  495. potentialnuke2 = 1
  496. if (((globalState ~= "nettest" and love.keyboard.isDown(p2control.super)) or lastSentKeyClient == p2control.super)) and AGAINST_AI == 0 then
  497. sounds["nuke"]:play()
  498. if areanuclear == 1 then
  499. maxspeed = maxspeed + 50
  500. end
  501. potentialstrike2 = 0
  502. areanuclear = 1
  503. player2reverbav = 0
  504. ballSpeed = ballSpeed * 2
  505. if (synctype == 0) then
  506. paddle_SPEED = paddle_SPEED * 2
  507. end
  508. if (synctype == 1) then
  509. paddle_SPEED = ballSpeed / 10
  510. end
  511. if (synctype == 0) then
  512. AI_SPEED = AI_SPEED * 2.2
  513. end
  514. if (synctype == 1) then
  515. AI_SPEED = ballSpeed * 1.1 / 10
  516. end
  517. player2nukescore = 0
  518. potentialnuke2 = 0
  519. end
  520. end
  521. end
  522. function editor()
  523. if (gameState == "editor") then
  524. if debug then
  525. --print("Editor is active!")
  526. end
  527. local mx, my = love.mouse.getPosition()
  528. mx = mx * DIFFERENCE_X
  529. my = my * DIFFERENCE_Y
  530. if (love.mouse.isDown(2)) then
  531. wallbreaker(mx, my)
  532. end
  533. if (love.mouse.isDown(3)) then
  534. table.insert(walls, newWall(mx, my, 10, wall1width))
  535. end
  536. end
  537. end
  538. function nuclearDraw()
  539. love.graphics.setColor(1, 1, 1, 1)
  540. for i = 1, maxBalls do
  541. love.graphics.circle("fill", ball[i].x, ball[i].y, explosionRange * 100, 100)
  542. end
  543. player1.RED, player1.GREEN, player1.BLUE, player2.RED, player2.GREEN, player2.BLUE =
  544. nuclearanimation / 3,
  545. nuclearanimation / 3,
  546. nuclearanimation / 3,
  547. nuclearanimation / 3,
  548. nuclearanimation / 3,
  549. nuclearanimation / 3
  550. for i = 1, maxBalls do
  551. love.graphics.setColor(nuclearanimation / 3, nuclearanimation / 3, nuclearanimation / 3, 1)
  552. ball[i]:render("controlled")
  553. end
  554. player1:render()
  555. player2:render()
  556. end
  557. function normalDraw()
  558. if (areanuclear == 1) then
  559. love.graphics.clear(1, 1, 1, 1)
  560. else
  561. love.graphics.clear(40 / 255, 40 / 255, 40 / 255, 1)
  562. end
  563. staticanimator()
  564. if MAP_TYPE == 1 then
  565. love.graphics.setColor(1, 0, 0.20, 1)
  566. love.graphics.rectangle("fill", VIRTUAL_WIDTH * 0.5, 0, 10, VIRTUAL_HEIGHT * 0.3)
  567. love.graphics.rectangle("fill", VIRTUAL_WIDTH * 0.5, VIRTUAL_HEIGHT * 0.7, 10, VIRTUAL_HEIGHT * 0.3)
  568. love.graphics.setColor(1, 1, 1, 1)
  569. end
  570. if MAP_TYPE == 2 then
  571. for i, wall in ipairs(walls) do
  572. love.graphics.setColor(1, 1, 1, 1)
  573. love.graphics.rectangle("fill", wall.wallx, wall.wally, 10, wall.wallheight)
  574. end
  575. end
  576. if gameMode == 'practice' then
  577. practiceDraw()
  578. end
  579. if gameMode == 'normal' then
  580. pongDraw()
  581. end
  582. love.graphics.setFont(smallfont)
  583. for i = 1, maxBalls do
  584. if areanuclear == 1 then
  585. --love.window.setTitle('rendering black')
  586. ball[i]:render("black")
  587. else
  588. --love.window.setTitle('rendering white')
  589. ball[i]:render(" ")
  590. end
  591. end
  592. end
  593. function pongDraw()
  594. --print("Drawing classic pong")
  595. love.graphics.setColor(1, 1, 1, 1)
  596. love.graphics.printf(TEXT, 0, 20, VIRTUAL_WIDTH, "center")
  597. love.graphics.setFont(smallfont)
  598. love.graphics.setFont(scorefont)
  599. if (areanuclear == 1) then
  600. love.graphics.setColor(0, 0, 0, 1)
  601. end
  602. love.graphics.print(tostring(math.floor(player1score)), VIRTUAL_WIDTH / 2 - 500, VIRTUAL_HEIGHT / 12)
  603. love.graphics.print(tostring(math.floor(player2score)), VIRTUAL_WIDTH / 2 + 400, VIRTUAL_HEIGHT / 12)
  604. love.graphics.setColor(1, 1, 1, 1)
  605. displayPoints()
  606. player1:render()
  607. player2:render()
  608. end
  609. function practiceDraw()
  610. player1:render()
  611. love.graphics.rectangle("fill", VIRTUAL_WIDTH-10, 0, 10, VIRTUAL_HEIGHT)
  612. love.graphics.setColor(1, 1, 1, 1)
  613. love.graphics.printf(TEXT, 0, 20, VIRTUAL_WIDTH, "center")
  614. love.graphics.setFont(smallfont)
  615. love.graphics.setFont(scorefont)
  616. love.graphics.print(tostring(math.floor(player1score)), VIRTUAL_WIDTH / 2 - 500, VIRTUAL_HEIGHT / 12)
  617. end
  618. function menuDraw()
  619. love.graphics.setColor(1, 1, 1, 1)
  620. love.graphics.printf(TEXT, 0, 20, VIRTUAL_WIDTH, "center")
  621. love.graphics.setFont(smallfont)
  622. love.graphics.printf(updateTEXT, 0, VIRTUAL_HEIGHT * 0.95, VIRTUAL_WIDTH, "left")
  623. if MAP_TYPE == 1 then
  624. love.graphics.setColor(1, 0, 0.20, 1)
  625. love.graphics.rectangle("fill", VIRTUAL_WIDTH * 0.5, 0, 10, VIRTUAL_HEIGHT * 0.3)
  626. love.graphics.rectangle("fill", VIRTUAL_WIDTH * 0.5, VIRTUAL_HEIGHT * 0.7, 10, VIRTUAL_HEIGHT * 0.3)
  627. love.graphics.setColor(1, 1, 1, 1)
  628. end
  629. if MAP_TYPE == 2 then
  630. for i, wall in ipairs(walls) do
  631. love.graphics.setColor(1, 1, 1, 1)
  632. love.graphics.rectangle("fill", wall.wallx, wall.wally, 10, wall.wallheight)
  633. end
  634. end
  635. if gameState == "windowsettings" then
  636. mymenu:butt(gameState, VIRTUAL_WIDTH, VIRTUAL_HEIGHT, settings, sounds, "right")
  637. love.keyboard.mouseisReleased = false
  638. end
  639. if gameState == "editor" then
  640. mymenu:butt(gameState, VIRTUAL_WIDTH, VIRTUAL_HEIGHT, editorpicks, sounds, "right")
  641. love.keyboard.mouseisReleased = false
  642. end
  643. if gameState == "speedSettings" then
  644. mymenu:butt(gameState, VIRTUAL_WIDTH, VIRTUAL_HEIGHT, speedParameters, sounds, "middle")
  645. love.keyboard.mouseisReleased = false
  646. end
  647. if gameState == "controlSettings" then
  648. mymenu:butt(gameState, VIRTUAL_WIDTH, VIRTUAL_HEIGHT, controlSettings, sounds, "control")
  649. love.keyboard.mouseisReleased = false
  650. end
  651. if gameState == "gameMode" then
  652. mymenu:butt(gameState, VIRTUAL_WIDTH, VIRTUAL_HEIGHT, modeSelectorButtons, sounds, "middle")
  653. love.keyboard.mouseisReleased = false
  654. end
  655. if gameState == "chooseIP" then
  656. mymenu:butt(gameState, VIRTUAL_WIDTH, VIRTUAL_HEIGHT, IPselect, sounds, "middle")
  657. love.graphics.printf(IP, 0, VIRTUAL_HEIGHT / 4, VIRTUAL_WIDTH, "center")
  658. love.keyboard.mouseisReleased = false
  659. end
  660. if gameState == "menu" then
  661. mymenu:butt(gameState, VIRTUAL_WIDTH, VIRTUAL_HEIGHT, buttons, sounds, "middle")
  662. love.keyboard.mouseisReleased = false
  663. end
  664. if gameState == "difficulty" then
  665. mymenu:butt(gameState, VIRTUAL_WIDTH, VIRTUAL_HEIGHT, difbuttons, sounds, "middle")
  666. love.keyboard.mouseisReleased = false
  667. end
  668. if gameState == "multiMode" then
  669. mymenu:butt(gameState, VIRTUAL_WIDTH, VIRTUAL_HEIGHT, playerCountButtons, sounds, "playercount")
  670. love.keyboard.mouseisReleased = false
  671. end
  672. if gameState == "prdiff" then
  673. mymenu:butt(gameState, VIRTUAL_WIDTH, VIRTUAL_HEIGHT, pracdiff, sounds, "playercount")
  674. love.keyboard.mouseisReleased = false
  675. end
  676. if gameState == 'start' then
  677. love.graphics.push()
  678. love.graphics.translate(VIRTUAL_WIDTH * 0.4, VIRTUAL_HEIGHT * 0.5)
  679. love.graphics.rotate(rotation)
  680. love.graphics.setFont(smallfont)
  681. love.graphics.print("Press Enter to Start", WINDOW_WIDTH / -10, VIRTUAL_HEIGHT / 8)
  682. love.graphics.setColor(255, 255, 255, 255)
  683. love.graphics.pop()
  684. end
  685. end
  686. function baseDraw()
  687. love.graphics.clear(40 / 255, 40 / 255, 40 / 255, 1)
  688. if shakeDuration > t then
  689. local dx = love.math.random(-shakeMagnitude, shakeMagnitude)
  690. local dy = love.math.random(-shakeMagnitude, shakeMagnitude)
  691. love.graphics.translate(dx, dy)
  692. end
  693. if globalState == 'menu' then
  694. --print("Drawing menuDraw")
  695. if gameState == 'animation' then
  696. --print("Drawing animation")
  697. intro()
  698. end
  699. if gameState ~= 'animation' then
  700. --print("Drawing notanimtaion")
  701. love.graphics.setFont(scorefont)
  702. menuDraw()
  703. end
  704. end
  705. if globalState == 'base' or globalState == 'reverse' or globalState == 'nettest' or globalState == 'clienttest' then
  706. love.graphics.setFont(smallfont)
  707. if gameState == 'nuclearExplosion' then
  708. nuclearDraw()
  709. end
  710. if gameState == 'play' or gameState == '1serve' or gameState == '2serve' or gameState == 'done' then
  711. --print("Drawing normally")
  712. normalDraw()
  713. end
  714. end
  715. end
  716. function renderEditor()
  717. if not blockinput then
  718. love.graphics.setColor(1, 0, 0, 1)
  719. love.graphics.rectangle("fill", mx, my, 10, wall1width)
  720. love.graphics.setColor(1, 1, 1, 1)
  721. end
  722. for i, wall in ipairs(walls) do
  723. love.graphics.setColor(1, 1, 1, 1)
  724. love.graphics.rectangle("fill", wall.wallx, wall.wally, 10, wall.wallheight)
  725. end
  726. end
  727. function intro()
  728. love.graphics.setColor(255, 255, 255, light / 255)
  729. love.graphics.draw(image, 0, 0)
  730. end
  731. function displayPoints()
  732. love.graphics.setFont(smallfont)
  733. if areanuclear == 1 then
  734. love.graphics.setColor(0,0,0,1)
  735. end
  736. if (potentialstrike1 == 1 and potentialnuke1 == 0 and player1reverbav == 0) then --FLAG: AVAILABLE SUPER
  737. if (player1striken == 0) then
  738. love.graphics.print(
  739. tostring(math.floor(player1nukescore) .. "[" .. p1control.super .. "]"),
  740. VIRTUAL_WIDTH / 2 - 500,
  741. VIRTUAL_HEIGHT / 60
  742. )
  743. else
  744. love.graphics.print(tostring("READY"), VIRTUAL_WIDTH / 2 - 500, VIRTUAL_HEIGHT / 60)
  745. end
  746. elseif (player1reverbav == 1 and potentialnuke1 == 0 ) then
  747. love.graphics.print(
  748. tostring(
  749. math.floor(player1nukescore) .. "[" .. p1control.super .. "]" .. " [" .. p1control.counter .. "]"
  750. ),
  751. VIRTUAL_WIDTH / 2 - 500,
  752. VIRTUAL_HEIGHT / 60
  753. )
  754. elseif (potentialnuke1 == 1) then
  755. love.graphics.setColor(255, 0, 0, 255)
  756. love.graphics.print(
  757. tostring(
  758. math.floor(player1nukescore) .. "[" .. p1control.super .. "]" .. " [" .. p1control.counter .. "]"
  759. ),
  760. VIRTUAL_WIDTH / 2 - 500,
  761. VIRTUAL_HEIGHT / 60
  762. )
  763. love.graphics.setColor(255, 255, 255, 255)
  764. elseif (potentialnuke1 == 1) then
  765. love.graphics.setColor(255, 0, 0, 255)
  766. love.graphics.print(
  767. tostring(
  768. math.floor(player1nukescore) .. "[" .. p1control.super .. "]"
  769. ),
  770. VIRTUAL_WIDTH / 2 - 500,
  771. VIRTUAL_HEIGHT / 60
  772. )
  773. love.graphics.setColor(255, 255, 255, 255)
  774. else
  775. love.graphics.print(tostring(math.floor(player1nukescore)), VIRTUAL_WIDTH / 2 - 500, VIRTUAL_HEIGHT / 60)
  776. end
  777. if (potentialstrike2 == 1 and player2reverbav == 0) then
  778. if (player2striken == 0) then
  779. love.graphics.print(
  780. tostring(math.floor(player2nukescore) .. "[" .. p2control.super .. "]"),
  781. VIRTUAL_WIDTH / 2 + 430,
  782. VIRTUAL_HEIGHT / 60
  783. )
  784. else
  785. love.graphics.print(tostring("READY"), VIRTUAL_WIDTH / 2 + 430, VIRTUAL_HEIGHT / 60)
  786. end
  787. elseif (potentialnuke2 == 1) then
  788. love.graphics.setColor(255, 0, 0, 255)
  789. love.graphics.print(
  790. tostring(math.floor(player2nukescore) .. "[" .. p2control.super .. "] [" .. p2control.counter .. "]"),
  791. VIRTUAL_WIDTH / 2 + 400,
  792. VIRTUAL_HEIGHT / 60
  793. )
  794. love.graphics.setColor(255, 255, 255, 255)
  795. elseif (potentialnuke2 == 1 and maxBalls > 1) then
  796. love.graphics.setColor(255, 0, 0, 255)
  797. love.graphics.print(
  798. tostring(math.floor(player2nukescore) .. "[" .. p2control.super .. "]"),
  799. VIRTUAL_WIDTH / 2 + 430,
  800. VIRTUAL_HEIGHT / 60
  801. )
  802. love.graphics.setColor(255, 255, 255, 255)
  803. elseif (player2reverbav == 1 and potentialnuke2 == 0 ) then
  804. love.graphics.print(
  805. tostring(math.floor(player2nukescore) .. "[" .. p2control.super .. "] [" .. p2control.counter .. "]"),
  806. VIRTUAL_WIDTH / 2 + 400,
  807. VIRTUAL_HEIGHT / 60
  808. )
  809. else
  810. love.graphics.print(tostring(math.floor(player2nukescore)), VIRTUAL_WIDTH / 2 + 430, VIRTUAL_HEIGHT / 60)
  811. end
  812. end
  813. function hitIdentifier()
  814. if (gameMode == "practice") then
  815. MAP_TYPE = 0
  816. if ball[i].x > VIRTUAL_WIDTH * 0.99 then
  817. soundtype = love.math.random(1, 5)
  818. sounds["wallhit"]:setPitch(ballSpeed / 250)
  819. sounds["wallhit"]:play()
  820. if (ball[i].dx > 0) then
  821. ball[i].x = ball[i].x - 20
  822. else
  823. ball[i].x = ball[i].x + 20
  824. end
  825. ball[i].dx = -ball[i].dx
  826. end
  827. end
  828. if (MAP_TYPE == 1) then
  829. if
  830. ball[i].y < VIRTUAL_HEIGHT * 0.3 and ball[i].x > VIRTUAL_WIDTH * 0.5 and
  831. ball[i].x < VIRTUAL_WIDTH * 0.5 + 5
  832. then
  833. soundtype = love.math.random(1, 5)
  834. sounds["wallhit"]:setPitch(ballSpeed / 250)
  835. sounds["wallhit"]:play()
  836. if (ball[i].dx > 0) then
  837. ball[i].x = ball[i].x - 20
  838. else
  839. ball[i].x = ball[i].x + 20
  840. end
  841. ball[i].dx = -ball[i].dx
  842. end
  843. if
  844. ball[i].y > VIRTUAL_HEIGHT * 0.7 and ball[i].x > VIRTUAL_WIDTH * 0.5 and
  845. ball[i].x < VIRTUAL_WIDTH * 0.5 + 5
  846. then
  847. soundtype = love.math.random(1, 5)
  848. sounds["wallhit"]:setPitch(ballSpeed / 250)
  849. sounds["wallhit"]:play()
  850. if (ball[i].dx > 0) then
  851. ball[i].x = ball[i].x - 20
  852. else
  853. ball[i].x = ball[i].x + 20
  854. end
  855. ball[i].dx = -ball[i].dx
  856. end
  857. end
  858. if (MAP_TYPE == 2) then
  859. for i, wall in ipairs(walls) do
  860. if
  861. (ball[1].y > wall.wally and ball[1].y < wall.wally + wall.wallheight and
  862. ball[1].x > wall.wallx - ballSpeed / 200 and
  863. ball[1].x < wall.wallx + 10 + ballSpeed / 200)
  864. then
  865. controllerSer()
  866. soundtype = love.math.random(1, 5)
  867. sounds["wallhit"]:setPitch(ballSpeed / 250)
  868. sounds["wallhit"]:play()
  869. if (ball[1].dx > 0) then
  870. ball[1].x = ball[1].x - 1
  871. else
  872. ball[1].x = ball[1].x + 1
  873. end
  874. ball[1].dx = -ball[1].dx
  875. elseif
  876. (ball[1].y > wall.wally - 15 and ball[1].y < wall.wally + wall.wallheight + 10 and
  877. ball[1].x > wall.wallx and
  878. ball[1].x < wall.wallx + 10)
  879. then
  880. controllerSer()
  881. soundtype = love.math.random(1, 5)
  882. sounds["wallhit"]:setPitch(ballSpeed / 250)
  883. sounds["wallhit"]:play()
  884. if (ball[1].dy > 0) then
  885. ball[1].y = ball[1].y - 1
  886. else
  887. ball[1].y = ball[1].y + 1
  888. end
  889. ball[1].dy = -ball[1].dy
  890. end
  891. end
  892. end
  893. end
  894. function rules(query, i)
  895. if query == "p1hit" then
  896. if gameMode == "normal" then
  897. return ball[i]:collides(player1)
  898. elseif gameMode == "reversegame" then
  899. return ball[i].x < 0 and ball[i].disabled == false
  900. end
  901. end
  902. if query == "p2hit" then
  903. if gameMode == "normal" then
  904. return ball[i]:collides(player2)
  905. elseif gameMode == "reversegame" then
  906. return ball[i].x > VIRTUAL_WIDTH-10 and ball[i].disabled == false
  907. end
  908. end
  909. if query == "p1miss" then
  910. if gameMode == "reversegame" then
  911. return ball[i]:collides(player1)
  912. elseif gameMode == "normal" then
  913. return ball[i].x < 0 and ball[i].disabled == false
  914. end
  915. end
  916. if query == "p2miss" then
  917. if gameMode == "reversegame" then
  918. return ball[i]:collides(player2)
  919. elseif gameMode == "normal" then
  920. return ball[i].x > VIRTUAL_WIDTH-10 and ball[i].disabled == false
  921. end
  922. end
  923. end
  924. function clientsBaseGame(dt)
  925. if confirmation == "confirmed" then
  926. player2.RED = 0
  927. print("KEYS ARE: " .. confirmation .. " " .. lastSentKeyP1)
  928. else
  929. TEXT = "DISCONNECTED"
  930. end
  931. if gameMode == "reverse" then
  932. reversegame(dt)
  933. end
  934. if player1nukescore > 300 then
  935. player1nukescore = 300
  936. end
  937. if player2nukescore > 300 then
  938. player2nukescore = 300
  939. end
  940. speedControl()
  941. balancer()
  942. if t < shakeDuration then
  943. t = t + dt
  944. end
  945. if (lastSentKeyP1 == p1control.up) then
  946. player1.dy = (paddle_SPEED + p2bonus) * -1
  947. print("moving player1 up")
  948. elseif (lastSentKeyP1 == p1control.down) then
  949. player1.dy = paddle_SPEED + p2bonus
  950. print("moving player1 down")
  951. else
  952. player1.dy = 0
  953. -- print("stopping player")
  954. end
  955. if ((love.keyboard.isDown(p2control.up))) then
  956. player2.dy = (paddle_SPEED + p2bonus) * -1
  957. elseif ((love.keyboard.isDown(p2control.down))) then
  958. player2.dy = paddle_SPEED + p2bonus
  959. else
  960. player2.dy = 0
  961. end
  962. --print("T = " .. tostring(t))
  963. serveBot()
  964. if gameState == 'play' then
  965. if (AGAINST_AI == 1) then
  966. AI(player2, maxBalls, AI_LEVEL)
  967. end
  968. --print(areanuclear .. striken .. player1score .. player2score)
  969. for i = 1, maxBalls do
  970. if rules("p1hit", i) then
  971. if (areanuclear == 0 and striken == 1 and (player1score > ptw-2 or player2score > ptw-2)) then
  972. --print("Calling animation")
  973. superanimator("tensehit", 1)
  974. print("AREA NUCLEAR?" .. areanuclear)
  975. end
  976. if gameMode == "practice" then
  977. player1score = player1score + 1
  978. end
  979. t = 0
  980. if (ballSpeed > 200) then
  981. shakeMagnitude = ballSpeed / 200
  982. else
  983. shakeMagnitude = 0
  984. end
  985. shakeDuration = 1
  986. randomtext = love.math.random(1, #textphrases)
  987. TEXT = textphrases[randomtext]
  988. soundtype = love.math.random(1, 1.2)
  989. if (player1striken == 1) then
  990. TEXT = "PLAYER 1 STRIKES"
  991. ballSpeed = ballSpeed + player1nukescore
  992. potentialnuke1 = 0
  993. player1striken = 0
  994. player1nukescore = 0
  995. potentialstrike1 = 0
  996. striken = 1
  997. if areanuclear == 0 then
  998. sounds["striking"]:setPitch(ballSpeed / 250)
  999. sounds["striking"]:play()
  1000. else
  1001. sounds["nuclearhit"]:setPitch(1)
  1002. sounds["nuclearhit"]:play()
  1003. end
  1004. if areanuclear == 0 then
  1005. superanimator("tensehit", 1)
  1006. end
  1007. else
  1008. if areanuclear == 0 then
  1009. sounds["beep"]:setPitch(ballSpeed / 250)
  1010. sounds["beep"]:play()
  1011. else
  1012. sounds["nuclearhit"]:setPitch(1)
  1013. sounds["nuclearhit"]:play()
  1014. end
  1015. end
  1016. if (striken == 1) then
  1017. player1nukescore = player1nukescore * 1.2
  1018. if (synctype == 0) then
  1019. paddle_SPEED = paddle_SPEED * 1.10
  1020. elseif (synctype == 1) then
  1021. paddle_SPEED = ballSpeed / 10
  1022. end
  1023. if (synctype == 0) then
  1024. AI_SPEED = AI_SPEED * 1.10
  1025. end
  1026. if (synctype == 1) then
  1027. AI_SPEED = ballSpeed * 1.1 / 10
  1028. end
  1029. ballSpeed = ballSpeed * 1.10
  1030. end
  1031. player1nukescore = player1nukescore + 10
  1032. ball[i].dx = -ball[i].dx
  1033. ball[i].x = player1.x + 30
  1034. end
  1035. if rules("p2hit", i) then
  1036. --ameState = 'quickanim'
  1037. t = 0
  1038. shakeDuration = 1
  1039. if
  1040. (areanuclear == 0 and
  1041. (striken == 1 and (player1score > ptw-2 or player2score > ptw-2)))
  1042. then
  1043. print("AREA NUCLEAR?" .. areanuclear)
  1044. superanimator("tensehit", 2)
  1045. end
  1046. if (ballSpeed > 200) then
  1047. shakeMagnitude = ballSpeed / 200
  1048. else
  1049. shakeMagnitude = 0
  1050. end
  1051. randomtext = love.math.random(1, #textphrases)
  1052. TEXT = textphrases[randomtext]
  1053. soundtype = love.math.random(1, 1.2)
  1054. if (player2striken == 1) then
  1055. TEXT = "PLAYER 2 STRIKES"
  1056. ballSpeed = ballSpeed + player2nukescore
  1057. striken = 1
  1058. player2striken = 0
  1059. potentialnuke2 = 0
  1060. player2nukescore = 0
  1061. potentialstrike2 = 0
  1062. print("AREA NUCLEAR?" .. areanuclear)
  1063. if areanuclear == 0 then
  1064. superanimator("tensehit", 2)
  1065. end
  1066. if areanuclear == 0 then
  1067. sounds["striking"]:setPitch(ballSpeed / 250)
  1068. sounds["striking"]:play()
  1069. else
  1070. sounds["nuclearhit"]:setPitch(1)
  1071. sounds["nuclearhit"]:play()
  1072. end
  1073. elseif (striken == 1) then
  1074. player2nukescore = player2nukescore * 1.5
  1075. if (synctype == 0) then
  1076. paddle_SPEED = paddle_SPEED * 1.10
  1077. end
  1078. if (synctype == 1) then
  1079. paddle_SPEED = ballSpeed / 10
  1080. end
  1081. if (synctype == 0) then
  1082. AI_SPEED = AI_SPEED * 1.10
  1083. end
  1084. if (synctype == 1) then
  1085. AI_SPEED = ballSpeed * 1.1 / 10
  1086. end
  1087. ballSpeed = ballSpeed * 1.10
  1088. if areanuclear == 0 then
  1089. sounds["beep"]:setPitch(ballSpeed / 250)
  1090. sounds["beep"]:play()
  1091. else
  1092. sounds["nuclearhit"]:setPitch(1)
  1093. sounds["nuclearhit"]:play()
  1094. end
  1095. else
  1096. if areanuclear == 0 then
  1097. sounds["beep"]:setPitch(ballSpeed / 250)
  1098. sounds["beep"]:play()
  1099. else
  1100. sounds["nuclearhit"]:setPitch(1)
  1101. sounds["nuclearhit"]:play()
  1102. end
  1103. end
  1104. player2nukescore = player2nukescore + 10
  1105. ball[i].dx = -ball[i].dx
  1106. ball[i].x = player2.x - 30
  1107. end
  1108. hitIdentifier()
  1109. if ball[i].y <= 0 then
  1110. soundtype = love.math.random(1, 5)
  1111. sounds["wallhit"]:setPitch(ballSpeed / 250)
  1112. sounds["wallhit"]:play()
  1113. ball[i].y = 0
  1114. end
  1115. -- -4 to account for the ball's size
  1116. if ball[i].y >= VIRTUAL_HEIGHT - 40 then
  1117. soundtype = love.math.random(1, 5)
  1118. sounds["wallhit"]:setPitch(ballSpeed / 250)
  1119. sounds["wallhit"]:play()
  1120. ball[i].y = VIRTUAL_HEIGHT - 40
  1121. end
  1122. --love.window.setTitle('Trying to update the ball')
  1123. if timeIsSlow then
  1124. if ballSpeed > originalSpeed / 3 then
  1125. paddle_SPEED = 30
  1126. ballSpeed = ballSpeed / (1 + (dt * 2))
  1127. end
  1128. player1nukescore = player1nukescore - (dt * 50)
  1129. if player1nukescore < 1 or ball[1].dx > 0 then
  1130. timeIsSlow = false
  1131. player1reverbav = false
  1132. ballSpeed = originalSpeed
  1133. sounds["time"]:stop()
  1134. paddle_SPEED = originalPaddle
  1135. end
  1136. end
  1137. if timeIsSlow2 then
  1138. if ballSpeed > originalSpeed / 3 then
  1139. ballSpeed = ballSpeed / (1 + (dt * 2))
  1140. end
  1141. player2nukescore = player2nukescore - (dt * 50)
  1142. if player2nukescore < 1 or ball[1].dx < 0 then
  1143. paddle_SPEED = 30
  1144. timeIsSlow2 = false
  1145. player2reverbav = false
  1146. ballSpeed = originalSpeed
  1147. sounds["time"]:stop()
  1148. paddle_SPEED = originalPaddle
  1149. end
  1150. end
  1151. ball[i]:update(dt)
  1152. end
  1153. end
  1154. goalManager()
  1155. powerAvailability()
  1156. player1:update(dt)
  1157. player2:update(dt)
  1158. end