Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. float spieler_x;
  2. float spieler_y;
  3. float ball_x;
  4. float ball_y;
  5. float ball_geschwindigkeit_x;
  6. float ball_geschwindigkeit_y;
  7.  
  8. int runde;
  9.  
  10. void setup(){
  11. spieler_x = 20;
  12. spieler_y = 60;
  13. ball_x = 400;
  14. ball_y = 300;
  15. ball_geschwindigkeit_x = -4;
  16. ball_geschwindigkeit_y = 0;
  17. runde = 0;
  18. size(800, 600);
  19. rectMode(CENTER);
  20. }
  21.  
  22. void draw(){
  23. background(0);
  24. rect(spieler_x, spieler_y, 20, 100);
  25. rect(ball_x, ball_y, 10, 10);
  26. if(keyPressed){
  27. if(keyCode == DOWN){
  28. if(spieler_y < 550){
  29. spieler_y = spieler_y + 5;
  30. }
  31. }
  32. if(keyCode == UP){
  33. if(spieler_y > 50){
  34. spieler_y = spieler_y - 5;
  35. }
  36. }
  37. }
  38. ball_x = ball_x + ball_geschwindigkeit_x;
  39. ball_y = ball_y + ball_geschwindigkeit_y;
  40.  
  41. if(ball_x < 30){
  42. if(ball_y < (spieler_y + 55) && ball_y > (spieler_y - 55)){
  43. ball_geschwindigkeit_x = (-ball_geschwindigkeit_x) + 1;
  44. ball_geschwindigkeit_y = ball_geschwindigkeit_y - (spieler_y - ball_y) * 0.1;
  45. runde = runde + 1;
  46. }else{
  47. ball_x = 400;
  48. ball_y = 300;
  49. ball_geschwindigkeit_x = -4;
  50. ball_geschwindigkeit_y = 0;
  51. runde = 0;
  52. }
  53. }
  54. if(ball_y > 595 || ball_y < 5){
  55. ball_geschwindigkeit_y = -ball_geschwindigkeit_y;
  56. }
  57. if(ball_x > 795){
  58. ball_geschwindigkeit_x = -ball_geschwindigkeit_x;
  59. }
  60. text("Runde: " + runde, 700, 20);
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement