Advertisement
Guest User

test

a guest
Oct 17th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.59 KB | None | 0 0
  1. /*
  2. Library Used: https://github.com/ddf/Minim
  3. Base Sound Effects From: zapsplat.com, freesound.org - Edited by Christian Leona to Suit the Game
  4.  
  5. Individual Components
  6. (Sound Effects) - Justin Abellera [13044173] & Christian Leona [13044235] <--- search comments using our student number
  7.  
  8. */
  9.  
  10. ///////////13044173 - Justin Abellera//////////////////
  11. import ddf.minim.*;
  12. import ddf.minim.spi.*;
  13. import ddf.minim.ugens.*;
  14. Minim minim;
  15. FilePlayer filePlayer;
  16. AudioOutput out;
  17. Sampler collision0, collision1, collision2, goal, border, applause0, applause1, applause2;
  18. ///////////13044173 - Justin Abellera//////////////////
  19. String fileName = "sfx/sounds_back2_final.mp3";
  20. float board_theme = 0; //0 = vanilla / 1 = jungle / 2 = neon
  21. void setup(){
  22. size(1280,960);
  23. background(75,100,255);
  24. //fill(colourR,colourG,colourB); //custom colours
  25. fill(255,255,255);
  26.  
  27. ///////////13044173 - Justin Abellera//////////////////
  28.  
  29. minim = new Minim(this);
  30. out = minim.getLineOut();
  31.  
  32. filePlayer = new FilePlayer( minim.loadFileStream("sfx/sounds_back2_final.mp3") );
  33. filePlayer.loop();
  34. filePlayer.patch(out);
  35.  
  36.  
  37.  
  38. border = new Sampler( "sfx/border.mp3", 1, minim ); //SFX Edited/Provided by Justin Abellera - 13044173 (Source: YouTube)
  39. border.patch(out);
  40. goal = new Sampler( "sfx/goal.mp3", 1, minim ); //SFX Edited/Provided by Christian Leona - 13044235 (Source: FreeSound.org)
  41. goal.patch(out);
  42. collision0 = new Sampler( "sfx/vanilla_collision.mp3", 1, minim ); //SFX Edited/Provided by Justin Abellera - 13044173 (Source: YouTube)
  43. collision0.patch(out);
  44. applause0 = new Sampler( "sfx/vanilla_applause.mp3", 1, minim ); //SFX Edited/Provided by Justin Abellera - 13044173 (Source: YouTube)
  45. applause0.patch(out);
  46.  
  47.  
  48. }
  49.  
  50. //##### INITIALISE VARIABLES #####//
  51. float width = 1280; //manual declaration to enable usage of width and height here
  52. float height = 960;
  53.  
  54. float ballX = width/2; //Ball is placed in the middle, for now
  55. float ballY = height/2;
  56. float friction = 2; //rate for the Ball to slow down over time
  57. float bounceFriction = 0.8; //multiplier for the Ball to lose speed when hit, 1 for no effect, speed loss increases as this decreases to 0 [can be higher than 1 to gain speed instead] [can split this for both players, potentially]
  58. float ballRadius = 2; //allows Ball radius to be modified live, potentially
  59. float ballSpeedX = 0; //placeholder because speed is calculated by coordinates elsewhere
  60. float ballSpeedY = 0;
  61. float hitDelay = 0; //prevent multiple micro-collisions with a paddle
  62.  
  63. float paddle_X1 = 0; //Paddle coordinate for player One. placeholder x and y, because they are mapped to hands
  64. float paddle_Y1 = 0;
  65. //float paddle_X2 = 0; //Paddle coordinate for player Two
  66. //float paddle_Y2 = 0;
  67. float paddle_X2 = width-2*(width/10); //placeholder coordinates for player Two
  68. float paddle_Y2 = height/2;
  69. int p2direction = 0; //placeholder for paddle movement for player Two
  70.  
  71. float prev_X1 = 0; //store the coordinate in the previous frame, to calculate speed
  72. float prev_Y1 = 0;
  73. float prev_X2 = 0; //player Two
  74. float prev_Y2 = 0;
  75. float prevTick = 0; //placeholder used in the process of storing previous X and Y
  76. float Xspeed1 = 0; //placeholder variable for speed calculation
  77. float Yspeed1 = 0;
  78. float Xspeed2 = 0; //player Two
  79. float Yspeed2 = 0;
  80.  
  81. float paddleSize_1 = 1; //allows the paddle size to be modified live, potentially
  82. float paddleSize_2 = 1; //allows one specific player's size to be modified, instead of only both
  83. //float paddlePower_1 = 1; //how fast the Ball bounces off the paddle, potentially [can be used alongside bounceFriction]
  84. //float paddlePower_2 = 1;
  85. //boolean punchOne = false; //potential feature, player can press a button to hit harder
  86. //boolean punchTwo = false;
  87.  
  88. float goal_X1 = width/10; //coordinate of goal for player One. allows the goal to move, potentially
  89. float goal_Y1 = height/2;
  90. float goal_X2 = 9*(width/10); //coordinate of goal for player Two
  91. float goal_Y2 = height/2;
  92. float goalSize_1 = 1; //allows the goal size to be modified live, potentially
  93. float goalSize_2 = 1;
  94. //float goal1_Height = 0;
  95. int goalState = 0; //0 for no goal, 1 for player 1 goal, 2 for player 2 goal, reset to 0 after the timer
  96. int goalScores_1 = 0; //score tracker for player 1
  97. int goalScores_2 = 0;
  98. float goalDelay = 0; //goal score animation timer
  99.  
  100.  
  101. //float modifier_windy = 0; //potential feature
  102. //boolean noFrictionMode = false;
  103.  
  104. //float colourR = random(70,255); //custom colours
  105. //float colourG = random(70,255);
  106. //float colourB = random(70,255);
  107.  
  108. //variable = int(variable); //convert to integer
  109.  
  110. float placeholderAnimationY = 0; //placeholder for goal animation
  111.  
  112.  
  113. void draw(){
  114. //ambience.trigger();
  115. frameRate(60);
  116. background(75,100,200);
  117.  
  118. countHitDelay();
  119. countGoalDelay();
  120.  
  121. draw_theme0(); //note: order matters for the Ball to be drawn on top of the background
  122. draw_paddle_1();
  123. draw_paddle_2();
  124. draw_goal_1();
  125. draw_goal_2();
  126. draw_ball();
  127.  
  128. applyFriction();
  129. speedCap();
  130. borderPrevention(); //prevent origin from leaving the border
  131.  
  132. debugText(); //debug note: display variable values to check functionality
  133. p2move(); //debug note: placeholder for player 2 paddle
  134.  
  135. paddleSpeed_1();
  136. paddleSpeed_2();
  137. checkHitboxes();
  138.  
  139. updateBallPosition();
  140.  
  141. checkGoals();
  142.  
  143. //put this AFTER paddleSpeed_One(), so that prev_X1 is not the same as paddleX_One
  144. prevCoordinateStorage();
  145.  
  146. //debug note: does the order of these methods matter?
  147. }
  148.  
  149.  
  150. //##### DRAW METHODS #####//
  151. void draw_paddle_1(){ //draw the paddle for player One
  152. pushMatrix();
  153. translate(paddle_X1,paddle_Y1);
  154. fill(255,0,0); //chosen colour, fixed for now
  155. //paddle_X1 = map(mouseX, 0, width, 0, width); //the paddle can follow the mouse, mapped to a specific area
  156. //paddle_Y1 = map(mouseY, 0, height, 0, height);
  157. paddle_X1 = mouseX; //placeholder updating paddle position
  158. paddle_Y1 = mouseY;
  159. ellipse(0,0,20*paddleSize_1,20*paddleSize_1); //the drawn paddle
  160. fill(255,255,255); //reset colour
  161. popMatrix();
  162. }
  163. void draw_paddle_2(){ //draw the paddle for player Two
  164. pushMatrix();
  165. translate(paddle_X2,paddle_Y2);
  166. fill(200,0,200);
  167. ellipse(0,0,20*paddleSize_2,20*paddleSize_2);
  168. fill(255,255,255); //reset colour
  169. popMatrix();
  170. }
  171. void draw_ball(){
  172. pushMatrix();
  173. translate(ballX,ballY);
  174. fill(0,255,0);
  175. ellipse(0,0,40*ballRadius,40*ballRadius);
  176. ellipse(-2,-2,4,4); //debug midpoint
  177. fill(255,255,255); //reset colour
  178. popMatrix();
  179. }
  180. void draw_goal_1(){
  181. pushMatrix();
  182. translate(goal_X1,goal_Y1);
  183. rect(-15*goalSize_1,-60*goalSize_1,30*goalSize_1,120*goalSize_1);
  184. ellipse(-2,-2,4,4); //debug midpoint
  185. popMatrix();
  186. }
  187. void draw_goal_2(){
  188. pushMatrix();
  189. translate(goal_X2,goal_Y2);
  190. rect(-15*goalSize_2,-60*goalSize_2,30*goalSize_2,120*goalSize_2);
  191. ellipse(-2,-2,4,4); //debug midpoint
  192. popMatrix();
  193. }
  194.  
  195. //##### AESTHETIC THEMES #####//
  196. void draw_theme0(){ //pong theme
  197. pushMatrix();
  198. //middle line (20 squares down the middle) ['20' value or rect value can be changed, because the Y values are scaled to height]
  199. noStroke();
  200. pushMatrix();
  201. translate(width/2,height/23);
  202. pushMatrix();
  203. for (int i = 0; i < 20; i++) {
  204. translate(0,height/28);
  205. rect(-8,-8,16,16); //raw pixel values
  206. }
  207. popMatrix();
  208. popMatrix();
  209. //goal rings
  210. pushMatrix(); //player One
  211. translate(goal_X1+width/128,goal_Y1);
  212. noFill();
  213. stroke(255,255,255,127);
  214. strokeWeight(4);
  215. arc(0, 0, width/8, width/8, radians(270), radians(450)); //inner ring
  216. strokeWeight(8);
  217. arc(0, 0, width/4, width/4, radians(270), radians(450)); //outer ring
  218. popMatrix();
  219. pushMatrix(); //player Two
  220. translate(goal_X2-width/128,goal_Y2);
  221. noFill(); //redundant line of code
  222. stroke(255,255,255,127);
  223. strokeWeight(4);
  224. arc(0, 0, width/8, width/8, radians(90), radians(270)); //inner ring
  225. strokeWeight(8);
  226. arc(0, 0, width/4, width/4, radians(90), radians(270)); //outer ring
  227. stroke(255,255,255); //reset
  228. popMatrix();
  229. //boundary lines
  230. line(width/10, height/20, width/10*9, height/20); //top line
  231. line(width/10, height/20*19, width/10*9, height/20*19); //bottom line
  232. line(width/10, height/20, width/10, height/20*7); //left, up line
  233. line(width/10, height/20*13, width/10, height/20*19); //left, down line
  234. line(width/10*9, height/20, width/10*9, height/20*7); //right, up line
  235. line(width/10*9, height/20*13, width/10*9, height/20*19); //right, down line
  236. //
  237. stroke(0,0,0); //reset
  238. strokeWeight(1);
  239. fill(0,0,0);
  240.  
  241. popMatrix();
  242. }
  243.  
  244.  
  245.  
  246. //##### FUNCTIONAL METHODS #####//
  247. void borderPrevention(){
  248. //prevent the Ball from leaving the border
  249. if (ballX > width/10 * 9 -40){ //horizontal speed [moving right]
  250. ballSpeedX = abs(ballSpeedX) * -1;
  251. border.trigger(); ///////////13044173 - Justin Abellera//////////////////
  252. } //force move away from border
  253. if (ballX < width/10 + 40){ //horizontal speed [moving left]
  254. ballSpeedX = abs(ballSpeedX);
  255. border.trigger(); ///////////13044173 - Justin Abellera//////////////////
  256. }
  257. if (ballY > height/20 * 19 -40){ //vertical speed [moving down]
  258. ballSpeedY = abs(ballSpeedY) * -1;
  259. border.trigger(); ///////////13044173 - Justin Abellera//////////////////
  260. }
  261. if (ballY < height/20 + 40){ //vertical speed [moving up]
  262. ballSpeedY = abs(ballSpeedY);
  263. border.trigger(); ///////////13044173 - Justin Abellera//////////////////
  264. }
  265. }
  266. void countHitDelay(){
  267. //if the Ball is hit, it cannot be hit again until some time later
  268. if (hitDelay > 0 && hitDelay < 17){ //Ball cannot be hit until 15 frames [17 because it starts at 1 and is immediately incremented to 2, probably]
  269. hitDelay++;
  270. }
  271. if (hitDelay > 15){ //reset
  272. hitDelay = 0;
  273. } //debug note: can this be improved using >= and <= ??? check frame by frame
  274. }
  275. void countGoalDelay(){ //can be merged with countHitDelay() [and every other method that is used on every frame]
  276. //if a goal has been scored, goal animation plays and the Ball is removed until some time later
  277.  
  278. if (goalDelay > 0 && goalDelay < 241){ //goal animation ends after 239 frames
  279.  
  280. goalDelay++;
  281. ballX = width/2; //move the Ball off the screen while the goal animation plays
  282. ballY = height/2;
  283. fill(0,255,0); //begin placeholder goal animation
  284. pushMatrix();
  285. translate(width/2-24,height/8);
  286. text("G O A L !",0,placeholderAnimationY);
  287. //placeholder goal animation
  288. popMatrix();
  289. fill(255,255,255);
  290. placeholderAnimationY = placeholderAnimationY + 3; //placeholder goal animation
  291. }
  292. if (goalDelay > 239){ //reset
  293. goalDelay = 0;
  294. goalState = 0; //allow goal to be scored again
  295. ballSpeedX = 0; //reset Ball speed for when it is moved back to the middle
  296. ballSpeedY = 0;
  297. ballX = width/2; //move the Ball back to the middle
  298. ballY = height/2;
  299. placeholderAnimationY = 0; //placeholder goal animation
  300. }
  301. }
  302. void checkHitboxes(){
  303. //check if the paddle is overlapping the Ball, by using radial distance
  304. if (dist(paddle_X1, paddle_Y1, ballX, ballY) < (25*ballRadius)) {
  305. //check if Ball is not affected by hitDelay
  306. if (hitDelay == 0){ //this can be problematic if the player reaches over the middle and prevents the other player from hitting the Ball [DEBUG NOTE: prevent player from hitting the Ball while they are over the middle boundary]
  307. hitDelay = 1;
  308. if(board_theme == 0) //Vanilla Theme
  309. {
  310. collision0.trigger();
  311. }
  312. else if(board_theme == 1) //Jungle Theme
  313. {
  314. collision1.trigger();
  315. }
  316. else if(board_theme == 2) //Neon Theme
  317. {
  318. collision2.trigger();
  319. }
  320. //if the Ball is moving fast, bounce off the paddle to simulate realistic ricochet/deflection
  321. if (ballSpeedX >= 10 || ballSpeedX <= -10 || ballSpeedY >= 10 || ballSpeedY <= -10){
  322. if (ballX > paddle_X1 && ballY < paddle_Y1){ //approximate deflection based on quadrant, top right
  323. ballSpeedX = abs(ballSpeedX)*bounceFriction; //force move to the right [and also lose some speed]
  324. ballSpeedY = (abs(ballSpeedY)*-1)*bounceFriction; } //force move up
  325. if (ballX > paddle_X1 && ballY > paddle_Y1){ //quadrant, bottom right
  326. ballSpeedX = abs(ballSpeedX)*bounceFriction; //force move right
  327. ballSpeedY = abs(ballSpeedY)*bounceFriction; } //force move down
  328. if (ballX < paddle_X1 && ballY > paddle_Y1){ //quadrant, bottom left
  329. ballSpeedX = (abs(ballSpeedX)*-1)*bounceFriction; //force move left
  330. ballSpeedY = abs(ballSpeedY)*bounceFriction; } //force move down
  331. if (ballX < paddle_X1 && ballY < paddle_Y1){ //quadrant, bottom right
  332. ballSpeedX = (abs(ballSpeedX)*-1)*bounceFriction; //force move left
  333. ballSpeedY = (abs(ballSpeedY)*-1)*bounceFriction; } //force move up
  334. }
  335. //if the Ball is moving VERY fast, bounce away from the paddle regardless of quadrant [due to large differences in pixels distances for each frame, the Ball can skip over the paddle and be placed in the wrong quadrant, resulting in an unexpected ricochet (in most cases, the Ball would be forced in the same direction after teleporting to the opposite side of the paddle)]
  336. if (ballSpeedX >= 25 || ballSpeedX <= -25 || ballSpeedY >= 25 || ballSpeedY <= -25){ //25 can be changed to scale with ballRadius and paddleSize, to increase the range of speeds that maintain the realistic ricochet
  337. ballSpeedX = (abs(ballSpeedX)*-1)*bounceFriction; //force flip X direction
  338. ballSpeedY = (abs(ballSpeedY)*-1)*bounceFriction; //force flip Y direction
  339. }
  340. //otherwise if the Ball is slow, it will copy the speed and direction of the paddle instead
  341. if (ballSpeedX < 10 && ballSpeedX > -10 && ballSpeedY < 10 && ballSpeedY > -10){
  342. ballSpeedX = Xspeed1;
  343. ballSpeedY = Yspeed1;
  344. }
  345. }
  346. //hitDelay = 1; //uncomment this if you want the delay to reset UNTIL the paddle is not on the Ball [potential issues if the player tracks the Ball with the paddle]
  347. }
  348. //for player Two
  349. if (dist(paddle_X2, paddle_Y2, ballX, ballY) < (25*ballRadius)) {
  350. if (hitDelay == 0){
  351. hitDelay = 1;
  352. if(board_theme == 0) //Vanilla Theme
  353. {
  354. collision0.trigger();
  355. }
  356. else if(board_theme == 1) //Jungle Theme
  357. {
  358. collision1.trigger();
  359. }
  360. else if(board_theme == 2) //Neon Theme
  361. {
  362. collision2.trigger();
  363. }
  364. //Ball is moving fast
  365. if (ballSpeedX >= 10 || ballSpeedX <= -10 || ballSpeedY >= 10 || ballSpeedY <= -10){
  366. if (ballX > paddle_X2 && ballY < paddle_Y2){ //quadrant, top right
  367. ballSpeedX = abs(ballSpeedX)*bounceFriction; ballSpeedY = (abs(ballSpeedY)*-1)*bounceFriction; }
  368. if (ballX > paddle_X2 && ballY > paddle_Y2){ //quadrant, bottom right
  369. ballSpeedX = abs(ballSpeedX)*bounceFriction; ballSpeedY = abs(ballSpeedY)*bounceFriction; }
  370. if (ballX < paddle_X2 && ballY > paddle_Y2){ //quadrant, bottom left
  371. ballSpeedX = (abs(ballSpeedX)*-1)*bounceFriction; ballSpeedY = abs(ballSpeedY)*bounceFriction; }
  372. if (ballX < paddle_X2 && ballY < paddle_Y2){ //quadrant, bottom right
  373. ballSpeedX = (abs(ballSpeedX)*-1)*bounceFriction; ballSpeedY = (abs(ballSpeedY)*-1)*bounceFriction; } }
  374. //Ball is moving VERY fast
  375. if (ballSpeedX >= 25 || ballSpeedX <= -25 || ballSpeedY >= 25 || ballSpeedY <= -25){
  376. ballSpeedX = (abs(ballSpeedX)*-1)*bounceFriction; ballSpeedY = (abs(ballSpeedY)*-1)*bounceFriction; }
  377. //Ball is slow
  378. if (ballSpeedX < 10 && ballSpeedX > -10 && ballSpeedY < 10 && ballSpeedY > -10){
  379.  
  380. ballSpeedX = Xspeed2; ballSpeedY = Yspeed2; }
  381. }
  382. }
  383. }
  384. void checkGoals(){ //check if the Ball is within a goal
  385. if (goalState == 0){
  386. if (ballX > goal_X1-(15*goalSize_1)-20*ballRadius && ballX < goal_X1+(15*goalSize_1)+20*ballRadius ){ //Ball is within goal 1
  387. if (ballY > goal_Y1-(60*goalSize_1)-18*ballRadius && ballY < goal_Y1+(60*goalSize_1)+18*ballRadius ){ //the hitbox is slightly generous around the corners because the Ball is a circle and dist() is not used
  388. //taken from draw_goal_1(): rect(-15*goalSize_1,-60*goalSize_1,30*goalSize_1,120*goalSize_1)
  389. goalState = 2; //goal has been scored for player 2
  390. goalScores_2 = goalScores_2 + 1; //increase score for player 2
  391. goalDelay = 1; //begin goal animation timer
  392. goal.trigger();
  393. if(board_theme == 0) //Vanilla Theme
  394. {
  395. applause0.trigger();
  396. }
  397. else if(board_theme == 1) //Jungle Theme
  398. {
  399. applause1.trigger();
  400. }
  401. else if(board_theme == 2) //Neon Theme
  402. {
  403. applause2.trigger();
  404. }
  405. }
  406. }
  407. if (ballX > goal_X2-(15*goalSize_2)-20*ballRadius && ballX < goal_X2+(15*goalSize_2)+20*ballRadius ){ //Ball is within goal 2
  408. if (ballY > goal_Y2-(60*goalSize_2)-18*ballRadius && ballY < goal_Y2+(60*goalSize_2)+18*ballRadius ){
  409. goalState = 1; //goal has been scored for player 1
  410. goalScores_1 = goalScores_1 + 1; //increase score for player 1
  411. goalDelay = 1; //begin goal animation timer
  412. goal.trigger();
  413. if(board_theme == 0) //Vanilla Theme
  414. {
  415. applause0.trigger();
  416. }
  417. else if(board_theme == 1) //Jungle Theme
  418. {
  419. applause1.trigger();
  420. }
  421. else if(board_theme == 2) //Neon Theme
  422. {
  423. applause2.trigger();
  424. }
  425. }
  426. }
  427. //debug note: how wide does the goal need to be to prevent a player from camping?
  428. }
  429. }
  430. void applyFriction(){
  431. //reduce the speed of the Ball while friction is active
  432. //DEBUG NOTE: the '4' here must be changed if friction is greater than 8 [applyFriction() -> 0.1*friction cannot exceed the range of 8 from 4>x>-4 because the stopping range will be skipped]
  433. if (ballSpeedX > 4){ //the Ball is moving RIGHT
  434. //ballspeed.trigger();
  435. ballSpeedX = ballSpeedX - (0.1*friction); }
  436. if (ballSpeedX < -4){ //the Ball is moving LEFT
  437. ballSpeedX = ballSpeedX + (0.1*friction); }
  438. if (ballSpeedY > 4){ //the Ball is moving DOWN
  439. //ballspeed.trigger();
  440. ballSpeedY = ballSpeedY - (0.1*friction); }
  441. if (ballSpeedY < -4){ //the Ball is moving UP
  442. ballSpeedY = ballSpeedY + (0.1*friction); }
  443. }
  444. void speedCap(){
  445. if (ballSpeedX > 80){ ballSpeedX = 80; }
  446. if (ballSpeedX < -80){ ballSpeedX = 80; }
  447. if (ballSpeedY > 80){ ballSpeedY = 80; }
  448. if (ballSpeedY < -80){ ballSpeedY = 80; }
  449. }
  450. void updateBallPosition(){
  451. ballX = ballX + ballSpeedX;
  452. ballY = ballY + ballSpeedY;
  453. }
  454.  
  455. void paddleSpeed_1(){
  456. //compare coordinates of the paddle to calculate the speed
  457. Xspeed1 = paddle_X1 - prev_X1; //if moved to the right, speed is positive
  458. Yspeed1 = paddle_Y1 - prev_Y1; //if moved down, speed is positive
  459. }
  460. void paddleSpeed_2(){ //can be merged with paddleSpeed_1()
  461. //compare coordinates of the paddle to calculate the speed
  462. Xspeed2 = paddle_X2 - prev_X2; //if moved to the right, speed is positive
  463. Yspeed2 = paddle_Y2 - prev_Y2; //if moved down, speed is positive
  464. }
  465. void prevCoordinateStorage(){ //functions similarly to pmouseX, but can be used for more than just one frame, potentially
  466. prevTick++;
  467. if (prevTick > 0){ //delayed by one frame
  468. prevTick = 0;
  469. prev_X1 = paddle_X1;
  470. prev_Y1 = paddle_Y1;
  471. prev_X2 = paddle_X2;
  472. prev_Y2 = paddle_Y2;
  473. }
  474. }
  475. void testTheme(){
  476.  
  477. if(board_theme == 0) //Vanilla Theme
  478. {
  479. collision0 = new Sampler( "sfx/vanilla_collision.mp3", 1, minim ); //SFX Edited/Provided by Justin Abellera - 13044173 (Source: YouTube)
  480. collision0.patch(out);
  481. applause0 = new Sampler( "sfx/vanilla_applause.mp3", 1, minim ); //SFX Edited/Provided by Justin Abellera - 13044173 (Source: YouTube)
  482. applause0.patch(out);
  483. }
  484. else if(board_theme == 1) //Jungle Theme
  485. {
  486. collision1 = new Sampler( "sfx/jungle_collision.mp3", 1, minim ); //SFX Edited/Provided by Christian Leona - 13044235 (Source: FreeSound.org)
  487. collision1.patch(out);
  488. applause1 = new Sampler( "sfx/jungle_applause.mp3", 1, minim ); //SFX Edited/Provided by Christian Leona - 13044235 (Source: FreeSound.org)
  489. applause1.patch(out);
  490. }
  491. else if(board_theme == 2) //Neon Theme
  492. {
  493. collision2 = new Sampler( "sfx/neon_collision.mp3", 1, minim ); //SFX Edited/Provided by Justin Abellera - 13044173 (Source: YouTube)
  494. collision2.patch(out);
  495. applause2 = new Sampler( "sfx/vanilla_applause.mp3", 1, minim ); //SFX Edited/Provided by Christian Leona - 13044235 (Source: YouTube)
  496. applause2.patch(out);
  497. }
  498.  
  499. }
  500. //##### debug methods for testing purposes #####//
  501. void debugText(){
  502. pushMatrix();
  503. fill(0,255,0);
  504. text(Xspeed1+" Xspeed1",20,20);
  505. text(Yspeed1+" Yspeed1",20,20+20);
  506. text(hitDelay+" hitDelay",20,20+40);
  507. text(paddle_X1+" paddle_X1",20,20+60);
  508. text(prev_X1+" prev_X1",20,20+80);
  509. text(ballSpeedX+" ballSpeedX",20,20+100);
  510. text(ballX+" ballX",20,20+120);
  511. text("goalState "+goalState,20,20+160);
  512. text("goalScores_1 "+goalScores_1,20,20+180);
  513. text("goalScores_2 "+goalScores_2,20,20+200);
  514. text("theme "+board_theme,20,20+500);
  515.  
  516. text(goalDelay+" goalDelay",20,20+240);
  517. text(Xspeed2+" Xspeed2",1160,20);
  518. text(Yspeed2+" Yspeed2",1160,40);
  519. //text(var+" var",20,20+);
  520. fill(255,255,255);
  521. popMatrix();
  522. }
  523. void mousePressed() { //debug note: teleport the ball to the mouse
  524. if (mouseButton == LEFT) {
  525. ballX=mouseX;
  526. ballY=mouseY;
  527. board_theme++;
  528. if (board_theme>4){board_theme=0;};
  529. testTheme();
  530. }
  531. }
  532. void keyPressed() { //debug note: placeholder for player 2 paddle movement
  533. if (key == CODED) {
  534. if (keyCode == UP) {
  535. p2direction = 4;
  536. } else if (keyCode == DOWN) {
  537. p2direction = 2;
  538. } else if (keyCode == LEFT) {
  539. p2direction = 3;
  540. } else if (keyCode == RIGHT) {
  541. p2direction = 1;
  542. }
  543. }
  544. }
  545. void keyReleased() { //debug note: placeholder for player 2 paddle movement, stops movement after releasing ANY key
  546. p2direction = 0;
  547. }
  548. void p2move(){ //debug note: placeholder for player 2 paddle movement, forces movement until a different direction is pressed
  549. if (p2direction != 0){ //this line is redundant
  550. if (p2direction == 4){
  551. paddle_Y2 = paddle_Y2 - 6; //up
  552. } else if (p2direction == 2){
  553. paddle_Y2 = paddle_Y2 + 6; //down
  554. } else if (p2direction == 3){
  555. paddle_X2 = paddle_X2 - 6; //left
  556. } else if (p2direction == 1){
  557. paddle_X2 = paddle_X2 + 6; //right
  558. }
  559. }
  560. }
  561.  
  562. //debug issue: a paddle can move through the Ball without triggering the hitbox, if the paddle is moving very fast and cannot keep up with the movement within 1 frame (e.g. paddle moves 160 pixels within 1 frame, skipping over the Ball hitbox) [partially solved using speed cap]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement