예제 #1
0
 /*
 public void updateCollision(Player b) {
  Point topLeft = new Point();
  topLeft.x = (int) b.getPosition().getX();
  topLeft.y = (int) b.getPosition().getY();
  Point topRight = new Point();
  topRight.x = (int) (b.getPosition().getX() + b.RADIUS * 2);
  topRight.y = (int) b.getPosition().getY();
  Point bottomLeft = new Point();
  bottomLeft.x = (int) b.getPosition().getX();
  bottomLeft.y = (int) (b.getPosition().getY() + b.RADIUS * 2);
  Point bottomRight = new Point();
  bottomRight.x = (int) (b.getPosition().getX() + b.RADIUS * 2);
  bottomRight.y = (int) (b.getPosition().getY() + b.RADIUS * 2);
  if (poly.contains(topLeft) || poly.contains(topRight) || poly.contains(bottomRight) || poly.contains(bottomLeft)) {
   reflect (b);
   System.out.println("TRIGGERED");
  }
 }
 */
 public void reflect(Player b) {
   double barrierSlope = ((double) (y1 - y2)) / ((double) (x1 - x2));
   if (barrierSlope == 1) {
     Point p = new Point();
     p.x = (int) b.getVel().getY();
     p.y = (int) b.getVel().getX();
   }
   if (Math.abs(barrierSlope) < 1) {
     System.out.print("shallow");
     double newX = (1 - barrierSlope) * b.getVel().getX();
     double newY = -1 * (b.VEL * 2) - newX;
     Point p = new Point();
     p.x = (int) newX;
     p.y = (int) newY;
     b.setVel(p);
   }
   if (Math.abs(barrierSlope) > 1) {
     System.out.println("steep");
     double newY = (1 - 1 / barrierSlope) * b.getVel().getY();
     double newX = -1 * (b.VEL * 2) - newY;
     Point p = new Point();
     p.x = (int) newX;
     p.y = (int) newY;
     b.setVel(p);
   }
 }
예제 #2
0
 // Bharat's collision system
 public void bounce(Player b) {
   double trueAngle = Math.atan(b.getVel().getX() / b.getVel().getY());
   double incAngle = trueAngle + angle;
   double newAngle = incAngle + angle + Math.PI;
   Point p = new Point();
   p.x = (int) (b.VEL * Math.cos(newAngle));
   p.y = (int) (b.VEL * Math.sin(newAngle));
   b.setVel(p);
 }