示例#1
0
  public void update(long dtime) {
    super.update(dtime);
    if (this.health == 0 && this.dead == false) {
      if (this == Gamestate.getInstance().getPlayer()) {
        this.setController(new NoController());
      }

      SOUNDS.TANK_EXPLODE.play();
      Vector3f bpos = new Vector3f(this.getBase().getPos());
      Gamestate.getInstance().addObject(new ExplosionCluster(bpos, new Vector3f(0, 1.2f, 0), 20));
      this.setController(new NoController());
      this.dead = true;
      this.base.unjoin(this.turret);
      this.parts.remove(this.turret);

    } else {
      lastFired++;
      Vector2f lookdir = turret.getPhys().getDir();
      if (lookdir.y > 25.0f) lookdir.y = 25.0f;
      if (lookdir.y < -25.0f) lookdir.y = -25.0f;

      if (lookdir.x > 55.0f) lookdir.x = 55.0f;
      if (lookdir.x < -55.0f) lookdir.x = -55.0f;

      turret.getPhys().setDir(lookdir);
    }
  }
示例#2
0
  /**
   * Gets all x,y coordinates, that have the lowest z-value, therefore making an appropriate measure
   * for a 3D->2D conversion
   *
   * @param verticesBuffer the vertices buffer
   * @return the coordinates
   */
  private List<Vector2f> getCoordinates(FloatBuffer verticesBuffer) {

    // get Coordinates into an array
    float[] vertices = new float[verticesBuffer.capacity()];

    for (int i = 0; i < verticesBuffer.capacity(); i++) {
      vertices[i] = verticesBuffer.get(i);
    }
    // read closest points based on their z-value

    // find smallest z-value
    float z = Float.MAX_VALUE;
    for (int i = 2; i < vertices.length; i += 3) {
      if (vertices[i] < z) {
        z = vertices[i];
      }
    }

    // add all points with a z-value that are equals
    Vector2f vertex;
    List<Vector2f> finalList = new ArrayList<Vector2f>();
    for (int i = 2; i < vertices.length; i += 9) {
      if (vertices[i] == z) {
        vertex = new Vector2f();
        vertex.x = vertices[i - 2];
        vertex.y = vertices[i - 1];
        finalList.add(vertex);
      }
    }

    return finalList;
  }
示例#3
0
  /*
   * Takes in a 3D location and spits out its texture coordinate. This version
   * simply returns 1/2 the x and y coordinate, offset by 0.5 This will ensure
   * that all texture coordinates are valid, based on assumption about the
   * incoming 3D location. This is valid because we know this method will only
   * be called from our spheretri methods.
   */
  private static void xyTex(Vector3f v, Vector2f tex) {

    tex.x = v.x / 2 + 0.5f;
    tex.y = v.y / 2 + 0.5f;
  }
示例#4
0
  /**
   * Set the layout of the child elements here. Will be executed if the display or a parent window
   * was resized.
   */
  public void layout() {

    // reset to the position and size to the original position
    position.set(positionOriginal);
    size.set(sizeOriginal);

    /*
       Position
    */

    position.x = calcHorizontalAlign(horizontalAlign);
    position.y = calcVerticalAlign(verticalAlign);

    // recalculate position x relative to parent if unit is percentage
    if (unitPositionX == EUnitType.PERCENTAGE
        && positionType == EPositionType.RELATIVE
        && parent != null) {
      getPosition().x += parent.getSize().x * positionOriginal.x / 100f;
    } else if (unitPositionX == EUnitType.PERCENTAGE && positionType == EPositionType.ABSOLUTE) {
      // recalculate position x absolute to display if unit is percentage
      getPosition().x += Display.getWidth() * positionOriginal.x / 100f;
    } else {
      getPosition().x += positionOriginal.x;
    }

    // recalculate position x relative to parent if unit is percentage
    if (unitPositionY == EUnitType.PERCENTAGE
        && positionType == EPositionType.RELATIVE
        && parent != null) {
      getPosition().y += parent.getSize().y * positionOriginal.y / 100f;
    } else if (unitPositionY == EUnitType.PERCENTAGE && positionType == EPositionType.ABSOLUTE) {
      // recalculate position x absolute to display if unit is percentage
      getPosition().y += Display.getHeight() * positionOriginal.y / 100f;
    } else {
      getPosition().y += positionOriginal.y;
    }

    /*
       Size
    */

    // recalculate width relative to parent if unit is percentage
    if (unitSizeX == EUnitType.PERCENTAGE
        && positionType == EPositionType.RELATIVE
        && parent != null) {
      getSize().x = parent.getSize().x * size.x / 100f;
    } else if (unitSizeX == EUnitType.PERCENTAGE && positionType == EPositionType.ABSOLUTE) {
      // recalculate width absolute to display if unit is percentage
      getSize().x = Display.getWidth() * size.x / 100f;
    }

    // recalculate height relative to parent if unit is percentage
    if (unitSizeY == EUnitType.PERCENTAGE
        && positionType == EPositionType.RELATIVE
        && parent != null) {
      getSize().y = parent.getSize().y * size.y / 100f;
    } else if (unitSizeY == EUnitType.PERCENTAGE && positionType == EPositionType.ABSOLUTE) {
      // recalculate height absolute to display if unit is percentage
      getSize().y = Display.getHeight() * size.y / 100f;
    }
  }