Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. float ballX;
  2. float ballY;
  3. int pos1;
  4. int pos2;
  5. int d;
  6. float Gravity;
  7.  
  8. void setup() {
  9. //size of screen
  10. size ( 1080, 720);
  11.  
  12. // where ball starts
  13. ballX = width/2;
  14. ballY = height/2;
  15.  
  16. // ball width and height or better known as diamater
  17. d = 25;
  18. }
  19.  
  20. void draw() {
  21. background (0);
  22. ellipse (ballX, ballY, d, d);
  23. stroke (255);
  24. fill (255, 0, 0);
  25. if (keyPressed){
  26. fill (0, 255, 0);
  27. }
  28.  
  29.  
  30. // if the ball goes off the screen to the left it will appear on the right and vice versa
  31. if (ballX<=0-d) {
  32. ballX = width;
  33. } else if (ballX>=width+d){
  34. ballX=0;
  35. }
  36. // if the ball goes off the top of the screen it will appear on the bottom and vice versa
  37. if (ballY<=0-d) {
  38. ballY = height;
  39. } else if (ballY>=height+d){
  40. ballY=0;
  41. }
  42. println("ballX:" + ballX);
  43. println("ballY:" + ballY);
  44.  
  45. }
  46.  
  47. // ball movement and "speed" when "key" is pressed
  48. void keyPressed() {
  49. if (key == CODED) {
  50. if (keyCode == UP) {
  51. ballY -=15;
  52. } else if (keyCode==DOWN) {
  53. ballY +=15;
  54. } else if (keyCode==RIGHT) {
  55. ballX +=15;
  56. } else if (keyCode==LEFT) {
  57. ballX -=15;
  58. }
  59.  
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement