예제 #1
0
 @Override
 public void run() {
   for (Ball e : balls) {
     e.update();
   }
   repaint();
 }
예제 #2
0
  void the_derive(double time, double y[], double dy[]) {
    int i;
    BallVector balls = decode_balls(y); // new BallVector();//Ball[num_balls];
    BallVector dballs = new BallVector(); // new Ball[num_balls];

    for (i = 0; i < num_balls; i++) {
      Ball p = balls.get2(i);
      Ball d = new Ball();
      d.pos = p.speed;
      d.speed = wall_power(p);
      d.speed.y -= 1; // gravity
      dballs.add(d);
    }

    for (i = 0; i < num_balls; i++)
      for (int j = i + 1; j < num_balls; j++) {
        Ball p1 = balls.get2(i);
        Ball p2 = balls.get2(j);
        if (far_away_fast_calc(p1.pos, p2.pos, radius * 2)) continue;
        double dist = p1.pos.calc_dist(p2.pos);
        // if (dist>radius*2)
        //	continue;

        Vec collide_power = calc_collide_power(p1, p2, dist);
        dballs.get2(i).speed.add_to(collide_power);
        dballs.get2(j).speed.sub_to(collide_power);
      }
    for (i = 0; i < springs.size(); i++) {
      Spring s = springs.get2(i);
      Vec collide_power = calc_spring_power(balls.get2(s.start), balls.get2(s.end));
      dballs.get2(s.start).speed.add_to(collide_power);
      dballs.get2(s.end).speed.sub_to(collide_power);
    }
    encode_balls(dballs, dy);
  };
예제 #3
0
 @Override
 public void paint(Graphics g) {
   super.paint(g);
   g.setColor(Color.BLACK);
   g.fillRect(0, 0, Ballz.FRAME_WIDTH, Ballz.FRAME_HEIGHT);
   for (Ball e : balls) {
     e.paint(g);
   }
 }
  public void draw() {

    background(255);

    for (int i = 0; i < balls.size(); i++) {
      Ball ball = (Ball) balls.get(i);
      ball.calc();
      ball.display();
    }
  }
예제 #5
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();
      }
    }
  }
예제 #6
0
        public void handleMessage(Message msg) {
          Ball B;
          for (int idx = 0; idx < arBall.size(); idx++) {
            B = arBall.get(idx);
            B.Move(getWidth(), getHeight());
            if (B.count > 4) {
              arBall.remove(idx);
              idx--;
            }
          }

          invalidate();
          mHandler.sendEmptyMessageDelayed(0, DELAY);
        }
예제 #7
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());
    }
  }
예제 #8
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--;
    }
  }
예제 #9
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();
  }
예제 #10
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);
  }
예제 #11
0
 // 새로운 볼 생성
 public boolean onTouchEvent(MotionEvent event) {
   if (event.getAction() == MotionEvent.ACTION_DOWN) {
     Ball NewBall = Ball.Create((int) event.getX(), (int) event.getY(), RAD);
     arBall.add(NewBall);
     invalidate();
     return true;
   }
   return false;
 }
예제 #12
0
  // 새로운 볼 생성
  static Ball Create(int x, int y, int Rad) {
    Random Rnd = new Random();
    Ball NewBall = new Ball();

    NewBall.x = x;
    NewBall.y = y;
    NewBall.rad = Rad;
    do {
      NewBall.dx = Rnd.nextInt(11) - 5;
      NewBall.dy = Rnd.nextInt(11) - 5;
    } while (NewBall.dx == 0 || NewBall.dy == 0);

    NewBall.count = 0;
    NewBall.color = Color.rgb(Rnd.nextInt(256), Rnd.nextInt(256), Rnd.nextInt(256));

    return NewBall;
  }
예제 #13
0
파일: box.java 프로젝트: newshorts/pingpong
  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;
      }
    }
  }
예제 #14
0
 void new_ball(Vec vec) {
   Ball b = new Ball();
   b.pos = vec;
   balls.add(b);
 }