Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //CLient
- //Client malt nur,kriegt alle werte von server
- import processing.net.*;
- Client c;
- int ballx=400;
- int bally=400;
- int pady1;
- int padx2=780;
- int pady2;
- int padspeed=5;
- int scorep1;
- int scorep2;
- JSONObject json;
- String input;
- void setup() {
- c = new Client(this, "192.168.178.40", 12345);
- size(800, 800);
- json=new JSONObject();
- frameRate(50);
- }
- void draw() {
- //Optik
- background(150);
- textAlign(CENTER,CENTER);
- textSize(100);
- text(scorep1,200,400);
- text(scorep2,600,400);
- fill(0);
- ellipse(ballx, bally, 20, 20);
- rect(padx2, pady2, 10, 100);
- if (pady2>=height-100) {
- pady2=height-100;
- }
- if (pady2<=0) {
- pady2=0;
- }
- //paddel server
- rect(10, pady1, 10, 100);
- //json schreiben
- json.setInt("pady2", pady2);
- //Daten schreiben
- c.write(json.toString());
- //daten empfangen
- if (c.available() > 0) {
- input=c.readString();
- JSONObject json =parseJSONObject(input);
- //json auswerten
- ballx=json.getInt("ballx");
- bally=json.getInt("bally");
- pady1=json.getInt("pady1");
- scorep1=json.getInt("scorep1");
- scorep2=json.getInt("scorep1");
- }
- //paddel
- if (mouseY>pady2+50) {
- pady2=pady2+padspeed;
- }
- if (mouseY<pady2+50) {
- pady2=pady2-padspeed;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement