Exemplo n.º 1
0
 @Override
 public void paintComponent(Graphics g) {
   Graphics2D g2 = (Graphics2D) g;
   Object hint = new Object();
   if (isAntialiased()) {
     hint = g2.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
     g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
   }
   translation = getTranslation();
   Color oldColor = g2.getColor();
   g2.setColor(new Color(230, 230, 250));
   g2.fill(translation.createTransformedShape(getShape()));
   g2.setColor(Color.BLACK);
   g2.draw(translation.createTransformedShape(getShape()));
   if (isShowingSensors) {
     for (Iterator<Sensor> sIter = sensors.iterator(); sIter.hasNext(); ) {
       Sensor s = (Sensor) sIter.next();
       s.paintComponent(g2);
     }
   }
   if (isShowingStatusFrame) {
     paintStatusFrame(g2);
   }
   g2.setColor(oldColor);
   if (isAntialiased()) {
     g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, hint);
   }
 }
Exemplo n.º 2
0
  @Override
  public void moveComponent() {
    inMotion = true;
    direction = body.getRotation();
    net.phys2d.math.ROVector2f p = body.getPosition();
    x = p.getX();
    y = p.getY();
    for (Iterator<Sensor> sIter = sensors.iterator(); sIter.hasNext(); ) {
      Sensor s = (Sensor) sIter.next();
      s.moveComponent();
    }

    final double distance = Util.euclideanDistance(lastX, lastY, x, y);
    final double velDist = lastVelocity - getSpeed() > 0 ? lastVelocity - getSpeed() : 0;
    if (velDist > 10) {
      crashmeter += velDist;
    }
    if (velDist > maxDeceleration) {
      maxDeceleration = velDist;
    }
    overallDeceleration += velDist;
    lastVelocity = getSpeed();

    odometer += distance;
    lastX = x;
    lastY = y;
  }