public void draw() {

    background(255);

    for (int i = 0; i < balls.size(); i++) {
      Ball ball = (Ball) balls.get(i);
      ball.calc();
      ball.display();
    }
  }
Beispiel #2
0
  /** Update all of the Ball's and draw them */
  public void update() {

    if (balls.size() != 0) {

      for (int i = 0; i < balls.size(); i++) {
        Ball b = (Ball) balls.get(i);
        b.update();
        b.attract = kelly;
        b.drawBall();
      }
    }
  }
  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());
    }
  }
  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--;
    }
  }
Beispiel #5
0
  /** If a key is pressed perform the respective actions */
  public void keyPressed() {

    // Add 'stems' to the balls
    if (keyCode == SHIFT) {
      stems = !stems;
      for (int i = 0; i < balls.size(); i++) {
        Ball b = (Ball) balls.get(i);
        b.STEM = stems;
      }
    }
    // toggle repaint background
    else if (key == 'b') REPAINT = !REPAINT;
    // Empty the ArrayList of Balls
    else if (key == 'x') balls.clear();
    // Add a ball
    else if (key == 'f') addBall();
  }
Beispiel #6
0
  /** Add a ball to the ArrayList at current mouse position */
  public void addBall() {

    // Store current mouse position
    x1 = mouseX;
    y1 = mouseY;
    // Get a random offset for the ball
    int xDiff = (int) random(-10, 10);
    int yDiff = (int) random(-10, 10);
    // Add the mouse's (x,y) and the random offset
    int x = mouseX + xDiff;
    int y = mouseY + yDiff;
    // Create new ball
    Ball b = new Ball(x, y, ballSize);
    b.STEM = stems;
    b.attract = kelly;
    balls.add(b);
  }
Beispiel #7
0
  public void draw() {

    // Center in display window
    translate(width / 2, height / 2, -1500);
    // if the user turned on the angled view
    if (a) {
      rotateX(radians(-30));
    }

    background(0);
    lights();
    noFill();
    smooth();
    // if the user turned on borders
    if (b) {
      stroke(255);
    }

    stage.create();
    ball.create();

    if (z) {
      fill(255, 255, 255, 100);
      instructions.loadInstructions();
    }

    if (keyPressed) {
      if (key == 'a' || key == 'A') {
        a = (a) ? false : true;
      }

      if (key == 'b' || key == 'B') {
        b = (b) ? false : true;
      }

      if (key == 'c' || key == 'C') {
        c = (c) ? false : true;
      }

      if (key == 'g' || key == 'G') {
        g = (g) ? false : true;
      }

      if (key == 'z') {
        z = (z) ? false : true;
      }
    }
  }