Example #1
0
  public void render(Vehicle vehicle) {
    Vector adjustedPosition = vehicle.position().add(viewPoint);
    int x = (int) adjustedPosition.x();
    int y = (int) adjustedPosition.y();

    Vector tip = new Vector(x + vehicle.boundingRadius(), y);
    Vector left = new Vector(x - 5, y - 5);
    Vector right = new Vector(x - 5, y + 5);

    int[] xPos = {(int) tip.x(), (int) left.x(), (int) right.x()};
    int[] yPos = {(int) tip.y(), (int) left.y(), (int) right.y()};

    AffineTransform orig = graphics.getTransform();

    AffineTransform rot =
        AffineTransform.getRotateInstance(vehicle.heading().x(), vehicle.heading().y(), x, y);
    graphics.transform(rot);
    graphics.drawPolygon(xPos, yPos, 3);
    graphics.setTransform(orig);

    if (showFeelers) {
      Vector[] feelers = createFeelersFor(vehicle);
      for (Vector feeler : feelers) {
        graphics.drawLine(x, y, (int) feeler.x(), (int) feeler.y());
      }
    }
    renderHealthBar(vehicle, x, y);
    renderEnergyBar(vehicle, x, y);
  }
Example #2
0
  public void render(Wall wall) {
    Stroke stroke = graphics.getStroke();
    graphics.setStroke(new BasicStroke(10));
    Vector from = wall.from().add(viewPoint);
    Vector to = wall.to().add(viewPoint);
    graphics.drawLine((int) from.x(), (int) from.y(), (int) to.x(), (int) to.y());
    graphics.setStroke(stroke);

    if (showWallNormals) {
      Vector centre = wall.centre().add(viewPoint);
      Vector normal = wall.normal();
      int x = (int) centre.x();
      int y = (int) centre.y();
      int toX = x + (int) (normal.x() * 10);
      int toY = y + (int) (normal.y() * 10);
      graphics.drawLine(x, y, toX, toY);
    }
  }
Example #3
0
 public void render(Bullet bullet) {
   Vector adjustedPosition = bullet.position().add(viewPoint);
   int x1 = (int) adjustedPosition.x();
   int y1 = (int) adjustedPosition.y();
   Vector tail = bullet.heading().reverse();
   int x2 = x1 + (int) tail.x() * 10;
   int y2 = y1 + (int) tail.y() * 10;
   graphics.drawLine(x1, y1, x2, y2);
 }
Example #4
0
 public void render(TargetingSystem targetingSystem) {
   Vector pos = targetingSystem.position().add(viewPoint);
   int x = (int) pos.x();
   int y = (int) pos.y();
   int radius = (int) targetingSystem.boundingRadius();
   int diameter = radius * 2;
   graphics.drawOval(x - radius, y - radius, diameter, diameter);
   double hx = targetingSystem.heading().x();
   double hy = targetingSystem.heading().y();
   graphics.drawLine(
       x + (int) (hx * radius),
       y + (int) (hy * radius),
       x + (int) (hx * diameter),
       y + (int) (hy * diameter));
 }