Advertisement
Guest User

Untitled

a guest
Jan 20th, 2020
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. //CLient
  2. //Client malt nur,kriegt alle werte von server
  3. import processing.net.*;
  4. Client c;
  5. int ballx=400;
  6. int bally=400;
  7. int pady1;
  8. int padx2=780;
  9. int pady2;
  10. int padspeed=5;
  11. int scorep1;
  12. int scorep2;
  13. JSONObject json;
  14. String input;
  15. void setup() {
  16. c = new Client(this, "192.168.178.40", 12345);
  17. size(800, 800);
  18. json=new JSONObject();
  19. frameRate(50);
  20. }
  21. void draw() {
  22. //Optik
  23. background(150);
  24. textAlign(CENTER,CENTER);
  25. textSize(100);
  26. text(scorep1,200,400);
  27. text(scorep2,600,400);
  28. fill(0);
  29. ellipse(ballx, bally, 20, 20);
  30. rect(padx2, pady2, 10, 100);
  31. if (pady2>=height-100) {
  32. pady2=height-100;
  33. }
  34. if (pady2<=0) {
  35. pady2=0;
  36. }
  37. //paddel server
  38. rect(10, pady1, 10, 100);
  39. //json schreiben
  40. json.setInt("pady2", pady2);
  41. //Daten schreiben
  42. c.write(json.toString());
  43. //daten empfangen
  44. if (c.available() > 0) {
  45. input=c.readString();
  46. JSONObject json =parseJSONObject(input);
  47. //json auswerten
  48. ballx=json.getInt("ballx");
  49. bally=json.getInt("bally");
  50. pady1=json.getInt("pady1");
  51. scorep1=json.getInt("scorep1");
  52. scorep2=json.getInt("scorep1");
  53. }
  54. //paddel
  55. if (mouseY>pady2+50) {
  56. pady2=pady2+padspeed;
  57. }
  58. if (mouseY<pady2+50) {
  59. pady2=pady2-padspeed;
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement