Advertisement
BetinaUKTC

Air Hockey

Mar 31st, 2019
2,937
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.35 KB | None | 0 0
  1. float l = 435;
  2. float r = 460;
  3. float xLeft=200;
  4. float yLeft=250;
  5. float xRight=700;
  6. float yRight=250;
  7. float speedX = 25;
  8. float speedY = 25;
  9. float x = 450;
  10. float y = 250;
  11. int diam = 25;
  12. int speed =35;
  13. int elr = 50;
  14. int elr2 = 30;
  15. int scoreRed = 0;
  16. int scoreBlue = 0;
  17. int wonBlueRounds=0;
  18. int wonRedRounds=0;
  19. String round_One_Blue = " Blue Player Wins The Match ";
  20. String round_One_Red = " Red Player Wins The Match ";
  21. String reset = "Press the mouse to reset";
  22.  
  23. void setup() {
  24. size(900, 500);
  25. background(0);
  26. reset();
  27. }
  28.  
  29. void draw() {
  30. chertichki();
  31. top4etata();
  32. krug4e();
  33. granici();
  34. bounce();
  35. score();
  36. rounds();
  37. }
  38.  
  39. void chertichki() {
  40.  
  41. strokeWeight(20);
  42. stroke(#FEFF0F);
  43. line(65, 50, l, 50); //1 yellow
  44. line(50, 65, 50, 200); //v1 yellow
  45.  
  46. stroke(#05E302);
  47. line(r, 50, 835, 50); //2 green
  48. line(850, 65, 850, 200);//v2 green
  49.  
  50. stroke(#F5301E);
  51. line(65, 450, l, 450); //3 red
  52. line(50, 300, 50, 435);//v3 red
  53.  
  54. stroke(#16DDED);
  55. line(r, 450, 835, 450); //4 blue
  56. line(850, 300, 850, 435);//v4 blue
  57.  
  58. strokeWeight(15);
  59.  
  60. stroke(#FAE123);
  61. line(65, 50, l, 50); //1
  62. line(50, 65, 50, 200); //v1
  63.  
  64. stroke(#05E302);
  65. line(r, 50, 835, 50); //2
  66. line(850, 65, 850, 200);//v2
  67.  
  68. stroke(#F5301E);
  69. line(65, 450, l, 450); //3
  70. line(50, 300, 50, 435);//v3
  71.  
  72. stroke(#16DDED);
  73. line(r, 450, 835, 450); //4
  74. line(850, 300, 850, 435);//v4
  75.  
  76. strokeWeight(10);
  77.  
  78. stroke(#FCFFA7);
  79. line(65, 50, l, 50); //1
  80. line(50, 65, 50, 200); //v1
  81.  
  82. stroke(#9FFC9E);
  83. line(r, 50, 835, 50); //2
  84. line(850, 65, 850, 200);//v2
  85.  
  86. stroke(#FFC9CA);
  87. line(65, 450, l, 450); //3
  88. line(50, 300, 50, 435);//v3
  89.  
  90. stroke(#C9FFFA);
  91. line(r, 450, 835, 450); //4
  92. line(850, 300, 850, 435);//v4
  93.  
  94. noFill();
  95. stroke(#76724B);
  96. arc(850, 250, 80, 80, radians(90), radians(270));
  97. arc(50, 250, 80, 80, radians(-90), radians(90));
  98. strokeWeight(4);
  99. stroke(0);
  100. arc(850, 250, 80, 80, radians(90), radians(270));
  101. arc(50, 250, 80, 80, radians(-90), radians(90));
  102.  
  103.  
  104. strokeWeight(6);
  105. stroke(#76724B);
  106. noFill();
  107. ellipse(450, 250, 150, 150);
  108. line(448, 64, 448, 445);
  109. fill(0);
  110. line(448, 65, 448, 445);
  111. filter(ERODE);
  112. filter(BLUR, 1.5);
  113. }
  114.  
  115. void top4etata() {
  116.  
  117. noFill();
  118. stroke(255, 0, 0);
  119. ellipse(xLeft, yLeft, elr, elr);
  120. ellipse(xLeft, yLeft, elr2, elr2);
  121.  
  122. noFill();
  123. stroke(0, 0, 255);
  124. ellipse(xRight, yRight, elr, elr);
  125. ellipse(xRight, yRight, elr2, elr2);
  126.  
  127. if (keyPressed && key=='s') {
  128. yLeft =yLeft + speed;
  129. }
  130.  
  131. if (keyPressed && key=='w') {
  132. yLeft =yLeft - speed;
  133. }
  134. if (keyPressed && key=='a') {
  135. xLeft =xLeft - speed;
  136. }
  137. if (keyPressed && key=='d') {
  138. xLeft =xLeft + speed;
  139. }
  140.  
  141. if (keyPressed && keyCode==DOWN) {
  142. yRight = yRight+speed;
  143. }
  144. if (keyPressed && keyCode==UP) {
  145. yRight = yRight-speed;
  146. }
  147. if (keyPressed && keyCode==LEFT) {
  148. xRight = xRight-speed;
  149. }
  150. if (keyPressed && keyCode==RIGHT) {
  151. xRight = xRight+speed;
  152. }
  153. if (yRight <= 60 ) {
  154. yRight=80;
  155. }
  156.  
  157. if (yRight>=440) {
  158. yRight=430;
  159. }
  160.  
  161. if (xRight >=840) {
  162. xRight=830;
  163. }
  164. if (xRight <=448) {
  165. xRight=448+elr;
  166. }
  167.  
  168. if (yLeft <= 60 ) {
  169. yLeft=80;
  170. }
  171.  
  172. if (yLeft>=440) {
  173. yLeft=430;
  174. }
  175.  
  176. if (xLeft <=50) {
  177. xLeft=70;
  178. }
  179.  
  180. if (xLeft >=448) {
  181. xLeft=448-elr;
  182. }
  183. }
  184.  
  185. void krug4e() {
  186. fill(#EDEDED);
  187. strokeWeight(3);
  188. stroke(255);
  189. ellipse(x, y, diam, diam);
  190. y +=-speedY;
  191. x-=-speedX;
  192. }
  193.  
  194.  
  195. void granici() {
  196.  
  197. if (y<50+diam ) {//горна част
  198. speedY-=15;
  199. speedY=-10;
  200. }
  201. if (x<50+diam) {//лява част
  202. speedX+=15;
  203. speedX=10;
  204. } else if ( y<200 && y>300) {//лява част
  205. speedX-=15;
  206. speedX=-10;
  207. }
  208. if (y>450-diam ) {//долна част
  209. speedY+=15;
  210. speedY=10;
  211. }
  212. if (y>200 && y<300 && x<51+diam) {//гол(син)
  213. speedX=10;
  214. x=450;
  215. y=250;
  216. scoreBlue++;
  217. }
  218. if (x>850-diam) {//дясна част
  219. speedX-=15;
  220. speedX-=10;
  221. }
  222. if (y>200 && y<300 && x>851-diam) {//гол(червен)
  223. speedX=10;
  224. x=450;
  225. y=250;
  226. scoreRed++;
  227. }
  228. }
  229.  
  230. void bounce() {
  231. if (dist(x, y, xRight, yRight)<elr) {
  232. speedX-=-25;
  233. speedY=random(-20, 20);
  234. speedX=-20;
  235. speedY=random(-20, 20);
  236. }
  237. if (dist(x, y, xLeft, yLeft)<elr) {
  238. speedX=+20;
  239. speedY-=random(-20, +20);
  240. speedX=+20;
  241. speedY=random(-20, 20);
  242. }
  243. }
  244. void score() {
  245. textSize(40);
  246. fill(255, 0, 0);
  247. text(scoreRed, 400, 40);
  248. fill(255);
  249. text(":", 443, 40);
  250. fill(0, 0, 255);
  251. text(scoreBlue, 463, 40);
  252. }
  253. void rounds() {
  254. if (scoreRed==5) {
  255. background(0);
  256. fill(255, 0, 0);
  257. textSize(40);
  258. text(round_One_Red, 150, 260);
  259. text(reset, 190, 320);
  260. if (mousePressed) {
  261. reset();
  262. }
  263. }
  264. if (scoreBlue==5 ) {
  265. background(0);
  266. fill(0, 0, 255);
  267. textSize(40);
  268. text(round_One_Blue, 130, 260);
  269. reset();
  270. if (mousePressed) {
  271. reset();
  272. }
  273. }
  274. }
  275.  
  276. void reset() {
  277. x=450;
  278. y=250;
  279. scoreRed=0;
  280. scoreBlue=0;
  281. speed=35;
  282. xRight=700;
  283. yRight=250;
  284. xLeft=200;
  285. yLeft=250;
  286. speedX=10;
  287. speedY=10;
  288. diam=25;
  289. }
  290.  
  291. void mousePressed() {
  292. reset();
  293. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement