Advertisement
Guest User

Untitled

a guest
Dec 9th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.14 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Solo Pong</title>
  5. <meta charset="UTF-8">
  6. <script src="processing.min.js"></script>
  7. </head>
  8. <body>
  9. <h1><P ALIGN=Center>Colorful Pong</h1><br>
  10. <h2><P ALIGN=Center>Pong is a fun, 2 player game that bounces a ball around. Your goal is to not let that ball get past you.</h2>
  11. <P ALIGN=Center><canvas id="canvas"></canvas>
  12. <br>
  13.  
  14.  
  15. <script>
  16. var canvas = document.getElementById("canvas");
  17. var canvasWidth = 1000;
  18. var canvasHeight = 550;
  19. var processing = new Processing(canvas, function(processing)
  20. {
  21. processing.size(canvasWidth, canvasHeight);
  22. processing.background(0xFFF);
  23.  
  24.  
  25. with (processing)
  26. {
  27.  
  28. var red = random(1,255);
  29. var green = random(1,255);
  30. var blue = random (1,255);
  31. var redIncrease = 1;
  32. var greenIncrease = 1;
  33. var blueIncrease = 1;
  34. var ballX=500;
  35. var ballY=275;
  36. var speedX = 5; //speed of ball
  37. var speedY = 5; //speed of ball
  38. var barHeight = 100;
  39. var barY = 12.5;
  40. var barX = 5;
  41. var scoreR = 0;
  42. var scoreL =0;
  43. var bar2Y = 12.5;
  44. var bar2X = 5;
  45.  
  46. draw = function ()
  47. {
  48. background(0,191,255);
  49. var x = 50;
  50. var x2 = 50;
  51. var m = millis();
  52.  
  53. if (m<0){ //not needed in this project
  54. background (0,191,255); //Extremely important to put this after vars and before anything else in draw function
  55. }
  56.  
  57. else { //the { will last until the end of everything in the draw = function(), this is important
  58.  
  59. //987.5 and 537.5 are canvas width and height - the radius of the ball
  60. if (ballX > 987.5) {
  61. speedX=-10; //changing speed X or Y will change angle in which ball goes at (unless they're the same)
  62. }
  63. if (ballX < 12.5) {
  64. speedX=10;
  65. }
  66.  
  67. if (ballY > 537.5) {
  68. speedY = -10;
  69. }
  70. if (ballY < 12.5) {
  71. speedY = 10;
  72. }
  73.  
  74.  
  75. ballY = ballY + speedY; //moves the ball up and down
  76. ballX = ballX + speedX; // moves the ball left and right
  77.  
  78.  
  79. if (mouseY + 100 > canvasHeight) //deals with bar that moves on bottom
  80.  
  81. if (red > 255) {
  82. redIncrease = 0; //all of these deal with the color of objects
  83. }
  84. if (red < 1) {
  85. redIncrease = 1;
  86. }
  87. if (green > 255) {
  88. greenIncrease = 0;
  89. }
  90. if (green < 1) {
  91. greenIncrease = 1;
  92. }
  93. if (blue > 255) {
  94. blueIncrease = 0;
  95. }
  96. if (red < 1) {
  97. blueIncrease = 1;
  98. }
  99. if (redIncrease === 1) {
  100. red += 1;
  101. } else red -= 1;
  102. if (greenIncrease === 1) {
  103. green += 1;
  104. } else green -= 1;
  105. if (blueIncrease === 1) {
  106. blue += 1;
  107. } else blue -= 1;
  108.  
  109. stroke(1, 1, 1);
  110. strokeWeight(1);
  111. fill(red, green, blue); //color of bar
  112. barY = mouseY - x;
  113. bar2Y = mouseY -x2;
  114. if (hitTheBar()) {
  115. speedY = -5;
  116. scoreL += 1
  117. }
  118.  
  119. if (hitTheBar2())
  120. {
  121. speedY = -5;
  122. scoreR += 1
  123. }
  124. fill(0, 0, 0);
  125. textSize(30);
  126. text("Score: " + scoreL, 20, 50);
  127. text("Score: " +scoreR, 870,50);
  128.  
  129. fill(red, green, blue);
  130. rect(barX, barY, 10, barHeight);
  131. rect(bar2X + 980, bar2Y, 10, barHeight);
  132.  
  133.  
  134. //middle circles/lines
  135. fill (0,0,0);
  136. rect (500,0,10,549);
  137. fill (0,0,0);
  138. ellipse(505,275,400,400);
  139. fill (230,230,230);
  140. ellipse (505,275,380,380);
  141.  
  142. fill(red, 255 - green, 255 - blue); //color of ball
  143. ellipse(ballX, ballY, 25, 25); //ball
  144.  
  145. }
  146.  
  147.  
  148.  
  149. };
  150. hitTheBar = function()
  151. {
  152. //ballX= 0/ball x position
  153. //ballY = 0/ball y position
  154. //barX = 5
  155. //barY = 12.5
  156. //bar locations = 5/985
  157. //barY location = 12.5
  158. if (ballX +10 < barX ) return false;
  159. if (ballX -10 > barX ) return false;
  160. if (ballY +25.5 < barY) return false;
  161. if (ballY -125.5 > barY) return false;
  162. return true;
  163. };
  164.  
  165. hitTheBar2 = function()
  166. {
  167. if (ballX +900 > bar2X + 980) return false;
  168. if (ballX -900 < bar2X + 980) return false;
  169. if (ballY +25.5 > bar2Y) return false;
  170. if (ballY -125.5 < bar2Y) return false;
  171. return true;
  172. };
  173. //================ END OF MODIFY CODE BLOCK =====================
  174. }
  175. if (typeof draw !== 'undefined') processing.draw = draw;
  176. });
  177. </script>
  178. <h2><P ALIGN=Center>The difficulty goes up to 10, each difficulty making the bar smaller. Its tougher then it looks.</h2>
  179. <h3><P ALIGN=Center>Author : Nolan Di Greco</h3>
  180. </body>
  181. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement