SHARE
TWEET

Untitled

a guest Apr 2nd, 2014 29 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. int points = 0;
  3. int lives = 3;
  4.  
  5. int framesTillAnotherDrop = 200;
  6. float particlesPerFirework = 1;
  7.  
  8. float playerX = 200;
  9. float compX = 200;
  10.  
  11. float ballX = 200;
  12. float ballY = 250;
  13. float ballVX = -2.5;
  14. float ballVY = 2.5;
  15. float ballSize = 10;
  16.  
  17. //float ballD = DOWN; UP RIGHT LEFT
  18. int bDirection = DOWN;
  19.  
  20. float paddle_width = 80;
  21.  
  22. void keyPressed()
  23. {
  24.   if (keyCode == UP)
  25.     bDirection = UP;
  26.   if (keyCode == DOWN)
  27.     bDirection = DOWN;
  28.   if (keyCode == LEFT)
  29.     bDirection = LEFT;
  30.   if (keyCode == RIGHT)
  31.     bDirection = RIGHT;
  32. }
  33.  
  34. float bSpeed = 3;
  35. void moveBall()
  36. {
  37.   ballVX = 0;
  38.   ballVY = 0;
  39.   if (bDirection == DOWN)
  40.     ballVY = bSpeed;
  41.   if (bDirection == UP)
  42.     ballVY = -bSpeed;
  43.   if (bDirection == LEFT)
  44.     ballVX = -bSpeed;
  45.   if (bDirection == RIGHT)
  46.     ballVX = bSpeed;
  47.  
  48.  
  49.   ballX += ballVX;
  50.   ballY += ballVY;
  51.  
  52.   //side to side bounce
  53.   if (ballX < 0)
  54.   {
  55.     ballVX*=-1;
  56.   }
  57.   if (ballX > width)
  58.   {
  59.     ballVX*=-1;
  60.   }
  61.  
  62.   //Bounce for player paddle
  63.   if (ballY > (height-paddle_width*.5))
  64.   {
  65.     float paddleBegin = playerX-paddle_width/2;
  66.     float paddleEnd = playerX+paddle_width/2;
  67.     if (ballX > paddleBegin && ballX < paddleEnd)
  68.     {
  69.       ballVY*=-1;
  70.     }
  71.   }
  72.  
  73.   if (ballY < (paddle_width*.5))
  74.   {
  75.     float paddleBegin = compX-paddle_width/2;
  76.     float paddleEnd = compX+paddle_width/2;
  77.     if (ballX > paddleBegin && ballX < paddleEnd)
  78.     {
  79.       ballVY*=-1;
  80.     }
  81.   }
  82.  
  83.  
  84.   //Check for winning conditions
  85.   if (ballY > height-paddle_width*.5+5)
  86.   {
  87.     points -= 1;
  88.     //reset ball position
  89.     ballX = 200;
  90.     ballY = 250;
  91.   }
  92.  
  93.   if (ballY < paddle_width*.5 - 5)
  94.   {
  95.     points += 1;
  96.     //reset ball position
  97.     ballX = 200;
  98.     ballY = 250;
  99.   }
  100. }
  101.  
  102. void think()
  103. {
  104.   if (ballX > compX)
  105.   {
  106.     compX += 2;
  107.   }
  108.   if (ballX < compX)
  109.   {
  110.     compX -= 2;
  111.   }
  112. }
  113.  
  114.  
  115. void draw() {
  116.  
  117.   background(100);
  118.   stroke(0);
  119.   fill(0);
  120.  
  121.   //Points
  122.   textSize(32);
  123.   text("points "+points, 32, 25);
  124.  
  125.   //Draw paddles
  126.   rect(playerX - paddle_width/2, height-paddle_width*.5, paddle_width, paddle_width*.2);
  127.   rect(compX - paddle_width/2, paddle_width*.5, paddle_width, paddle_width*.2);
  128.  
  129.   //Draw ball
  130.   ellipse(ballX, ballY, ballSize, ballSize);
  131.  
  132.   playerX = mouseX;
  133.   //compX = width - mouseX;
  134.   think();
  135.  
  136.   moveBall();
  137. }
  138.  
  139. void mouseClicked()
  140. {
  141.   //background(0); // clear screen
  142.   //populateThings(); //start over
  143.   //mouseBomb();
  144. }
  145.  
  146. void setup() {
  147.   size(400, 500);
  148.   colorMode(HSB, 100);
  149.   //mono = loadFont("AndaleMono-32.vlw");
  150.   //populateThings();
  151.   //println(UP);
  152. }
RAW Paste Data
Top