/** @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer) */
  public void init(GameContainer container) throws SlickException {
    polygon.addPoint(100, 100);
    polygon.addPoint(200, 80);
    polygon.addPoint(320, 150);
    polygon.addPoint(230, 210);
    polygon.addPoint(170, 260);

    path.curveTo(200, 200, 200, 100, 100, 200);
    path.curveTo(400, 100, 400, 200, 200, 100);
    path.curveTo(500, 500, 400, 200, 200, 100);
  }
Exemplo n.º 2
0
  /**
   * Process the points in a polygon definition
   *
   * @param poly The polygon being built
   * @param element The XML element being read
   * @param tokens The tokens representing the path
   * @return The number of points found
   * @throws ParsingException Indicates an invalid token in the path
   */
  private static int processPoly(Polygon poly, Element element, StringTokenizer tokens)
      throws ParsingException {
    int count = 0;

    ArrayList pts = new ArrayList();
    boolean moved = false;
    boolean closed = false;

    while (tokens.hasMoreTokens()) {
      String nextToken = tokens.nextToken();
      if (nextToken.equals("L")) {
        continue;
      }
      if (nextToken.equals("z")) {
        closed = true;
        break;
      }
      if (nextToken.equals("M")) {
        if (!moved) {
          moved = true;
          continue;
        }

        return 0;
      }
      if (nextToken.equals("C")) {
        return 0;
      }

      String tokenX = nextToken;
      String tokenY = tokens.nextToken();

      try {
        float x = Float.parseFloat(tokenX);
        float y = Float.parseFloat(tokenY);

        poly.addPoint(x, y);
        count++;
      } catch (NumberFormatException e) {
        throw new ParsingException(element.getAttribute("id"), "Invalid token in points list", e);
      }
    }

    poly.setClosed(closed);
    return count;
  }
  /** @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer) */
  public void init(GameContainer container) throws SlickException {
    poly.addPoint(120, 120);
    poly.addPoint(420, 100);
    poly.addPoint(620, 420);
    poly.addPoint(300, 320);

    image = new Image("testdata/rocks.png");

    texPaint =
        new TexCoordGenerator() {
          public Vector2f getCoordFor(float x, float y) {
            float tx = (texRect.getX() - x) / texRect.getWidth();
            float ty = (texRect.getY() - y) / texRect.getHeight();

            return new Vector2f(tx, ty);
          }
        };
  }
Exemplo n.º 4
0
  /** @see org.newdawn.slick.BasicGame#init(org.newdawn.slick.GameContainer) */
  public void init(GameContainer container) throws SlickException {
    this.container = container;

    rect = new Rectangle(400, 100, 200, 150);
    round = new RoundedRectangle(150, 100, 200, 150, 50);
    round2 = new RoundedRectangle(150, 300, 200, 150, 50);
    center = new Rectangle(350, 250, 100, 100);

    poly = new Polygon();
    poly.addPoint(400, 350);
    poly.addPoint(550, 320);
    poly.addPoint(600, 380);
    poly.addPoint(620, 450);
    poly.addPoint(500, 450);

    gradient = new GradientFill(0, -75, Color.red, 0, 75, Color.yellow);
    gradient2 = new GradientFill(0, -75, Color.blue, 0, 75, Color.white);
    gradient4 = new GradientFill(-50, -40, Color.green, 50, 40, Color.cyan);
  }
Exemplo n.º 5
0
  /**
   * @see org.newdawn.slick.svg.inkscape.ElementProcessor#process(org.newdawn.slick.svg.Loader,
   *     org.w3c.dom.Element, org.newdawn.slick.svg.Diagram, org.newdawn.slick.geom.Transform)
   */
  public void process(Loader loader, Element element, Diagram diagram, Transform t)
      throws ParsingException {
    Transform transform = Util.getTransform(element);
    transform = new Transform(t, transform);

    String points = element.getAttribute("points");
    if (element.getNodeName().equals("path")) {
      points = element.getAttribute("d");
    }

    StringTokenizer tokens = new StringTokenizer(points, ", ");
    Polygon poly = new Polygon();
    int count = processPoly(poly, element, tokens);

    NonGeometricData data = Util.getNonGeometricData(element);
    if (count > 3) {
      Shape shape = poly.transform(transform);

      diagram.addFigure(new Figure(Figure.POLYGON, shape, data, transform));
    }
  }