Example #1
0
  /** Shoots a {@link Bullet} at the specified position */
  public void shoot(Vector2 position) {

    Vector2 direction = new Vector2(position);
    direction.sub(this.getPosition());
    direction.nor();
    this.setAngle(direction.angleRad());

    this.setTransform(body.getPosition(), direction.angleRad());

    Vector2 velocity = new Vector2(direction.x * BULLET_SPEED, direction.y * BULLET_SPEED);

    Bullet bullet = new Bullet(level, this.getPosition(), velocity);
    bullet.setAngle(direction.angleRad());
    level.add(bullet);
  }
Example #2
0
  // TODO Comment
  private void updateVertexDefault(int index, boolean inside) {

    BoundingBox box = boundingBoxes.items[index / verticesPerBox];
    box.needsCullingUpdate = true;

    int k = index % vertices.size;
    StripVertex stripVertex = vertexDataArray.items[k];
    AuxVertexFinder auxVertexFinder = this.auxVertexFinder;

    Array<Float> vertexData = inside ? stripVertex.insideVertexData : stripVertex.outsideVertexData;
    vertexData.clear();

    auxVertexFinder.setInsideStrip(inside);

    Vector2 currentVertex = vertices.items[k];
    Vector2 defaultAux = auxVertexFinder.getAux(vertices, k);

    boolean roundCorner = false;

    { // within these brackets i figure out if i should round the corner.
      // i hope to rewrite this code to something i can understand one day after writing it
      Vector2 previous = tmp.set(vertices.items[(k - 1 + vertices.size) % vertices.size]);
      Vector2 copyOfDefaultAux = tmp1.set(defaultAux);

      previous.sub(currentVertex);
      copyOfDefaultAux.sub(currentVertex);

      float angle = previous.angleRad() - copyOfDefaultAux.angleRad();
      angle = ((angle + MathUtils.PI2) % MathUtils.PI) * 2f;
      boolean angleMoreThanPI;
      if (inside) {
        angleMoreThanPI = angle > MathUtils.PI * 1.1f;
      } else {
        angleMoreThanPI = angle < MathUtils.PI * 0.9f;
      }

      if (auxVertexFinder.clockWisePolygon) angleMoreThanPI = !angleMoreThanPI;

      if (angleMoreThanPI) {
        boolean sharpCorner = Math.abs(MathUtils.PI - angle) > Math.PI * 0.4f;
        roundCorner = roundSharpCorners && sharpCorner;
      }
    }

    if (roundCorner) {
      Vector2 beginningAux = auxVertexFinder.getAuxEnding(vertices, k, 0);
      Vector2 endingAux = auxVertexFinder.getAuxBeginning(vertices, k, 0);
      Vector2 middleAux =
          tmp.set(defaultAux).sub(currentVertex).nor().scl(halfWidth).add(currentVertex);

      add(currentVertex, VERTEX_TYPE_USER, vertexData);
      add(beginningAux, VERTEX_TYPE_AUX, vertexData);

      add(currentVertex, VERTEX_TYPE_USER, vertexData);
      add(middleAux, VERTEX_TYPE_AUX, vertexData);

      add(currentVertex, VERTEX_TYPE_USER, vertexData);
      add(endingAux, VERTEX_TYPE_AUX, vertexData);
    } else {
      add(currentVertex, VERTEX_TYPE_USER, vertexData);
      add(defaultAux, VERTEX_TYPE_AUX, vertexData);
    }
  }