Example #1
0
  public void controlEvent(ControlEvent theEvent) {
    // DropdownList is of type ControlGroup.
    // A controlEvent will be triggered from inside the ControlGroup class.
    // therefore you need to check the originator of the Event with
    // if (theEvent.isGroup())
    // to avoid an error message thrown by controlP5.

    /*  if (theEvent.getController().getName().equals("restart")) {
      paddles[0].points=0;
      paddles[1].points=0;
    }*/

    if (theEvent.isGroup()) {
      // check if the Event was triggered from a ControlGroup
      //  println("event from group : "+theEvent.getGroup().getValue()+" from
      // "+theEvent.getGroup());
      if (theEvent.getGroup().toString().equals("paddle1 [DropdownList]")) {
        println("paddle1 " + theEvent.getGroup().getValue());
        paddleSelector1 = translations[(int) theEvent.getGroup().getValue()];
        println(jointNames[paddleSelector1]);
      } else if (theEvent.getGroup().toString().equals("paddle2 [DropdownList]")) {
        println("paddle2 " + theEvent.getGroup().getValue());
        paddleSelector2 = translations[(int) theEvent.getGroup().getValue()];
        println(jointNames[paddleSelector2]);
      } else if (theEvent.getGroup().toString().equals("1_or_2_player [DropdownList]")) {
        if ((int) theEvent.getGroup().getValue() == 0) {
          onePlayer = true;
        } else {
          onePlayer = false;
        }
      } else if (theEvent.getGroup().toString().equals("speed [DropdownList]")) {
        if ((int) theEvent.getGroup().getValue() == 0) {
          ball.speed = new PVector(5, 5);
        } else if ((int) theEvent.getGroup().getValue() == 1) {
          ball.speed = new PVector(10, 10);
        } else if ((int) theEvent.getGroup().getValue() == 2) {
          ball.speed = new PVector(15, 15);
        }
      }
    } else if (theEvent.isController()) {
      println(
          "event from controller : "
              + theEvent.getController().getValue()
              + " from "
              + theEvent.getController());
    }
  }
Example #2
0
  public void draw() {
    background(0);
    fill(0, 255, 0);
    stroke(255);
    // get kinect color image
    context.update();
    // scale to an arbitrary size and position (e.g. scale down 75%, and align to bottom / center)
    skeleton.updateSkeleton();

    if (onePlayer) {
      paddles[0].update(skeleton.getScreenCoords(1, paddleSelector1).y);
      paddles[1].update(skeleton.getScreenCoords(1, paddleSelector2).y);
    } else {
      paddles[0].update(skeleton.getScreenCoords(1, paddleSelector1).y);
      try {
        paddles[1].update(skeleton.getScreenCoords(2, paddleSelector2).y);
      } catch (Exception e) {
      }
    }

    for (int i = 0; i < paddles.length; i++) {

      paddles[i].drawPaddle();
    }
    ball.update();
    ball.checkCollision(paddles);
    ball.drawBall();

    /*PVector rHand = skeleton.getScreenCoords(1, SimpleOpenNI.SKEL_RIGHT_HAND) ;
    PVector lHand = skeleton.getScreenCoords(1, SimpleOpenNI.SKEL_LEFT_HAND) ;
    fill(255, 0, 0);
    ellipse(rHand.x, rHand.y, 20, 20);
    ellipse(lHand.x, lHand.y, 20, 20);*/
    float offset = 80;
    text(
        str(paddles[0].points),
        width - (offset + (0.5f * textWidth(str(paddles[0].points)))),
        height - 50);
    text(str(paddles[1].points), offset, height - 50);
    fill(0, 255, 0, 255 - ((255 / (timer + 1)) * (timer + 1)));

    if (timer > 0) {
      String txt = "POINT";
      text(txt, (width / 2) - (0.5f * textWidth(txt)), height / 2);
      timer--;
    }
  }