示例#1
0
  public void shoot() {
    // this is very similar to the above method
    int maxIterations = 500;
    float newX = 0, newY = 0, newZ = 0;

    for (int i = 0; i < maxIterations; i += 1) {
      newX =
          -(controller.getX()
              + (float)
                  (-(i)
                      * (Math.sin(Math.toRadians(controller.getAngleX())))
                      * (Math.cos(Math.toRadians(controller.getAngleY())))));
      newY =
          -(controller.getY()
              + (float) (-(i) * (Math.sin(Math.toRadians(controller.getAngleY())))));
      newZ =
          -(controller.getZ()
              + (float)
                  ((i)
                      * (Math.cos(Math.toRadians(controller.getAngleX())))
                      * (Math.cos(Math.toRadians(controller.getAngleY())))));

      if (checkShootZombie(newX, newY, newZ)) break;
    }
  }
示例#2
0
 public void addZombie() {
   // adds a zombie where the player is looking
   float newX = 0, newZ = 0;
   newX =
       -(controller.getX()
           + (float)
               (-(100)
                   * (Math.sin(Math.toRadians(controller.getAngleX())))
                   * (Math.cos(Math.toRadians(controller.getAngleY())))));
   newZ =
       -(controller.getZ()
           + (float)
               ((100)
                   * (Math.cos(Math.toRadians(controller.getAngleX())))
                   * (Math.cos(Math.toRadians(controller.getAngleY())))));
   zombies.add(new Zombie(controller, zombieM, newX, newZ));
 }
示例#3
0
  public void checkSelected() {
    // this method highlights a cube if it is being looked at
    // I use a method of ray tracing to check along the players line of sight
    if (controller.getSelectedWeapon() != 1) return;

    boolean anythingSelected = false;
    int maxIterations = 500;

    float newX = 0, newY = 0, newZ = 0;

    for (int i = 0; i < maxIterations; i += 1) {
      newX =
          -(controller.getX()
              + (float)
                  (-(i)
                      * (Math.sin(Math.toRadians(controller.getAngleX())))
                      * (Math.cos(Math.toRadians(controller.getAngleY())))));
      newY =
          -(controller.getY()
              + (float) (-(i) * (Math.sin(Math.toRadians(controller.getAngleY())))));
      newZ =
          -(controller.getZ()
              + (float)
                  ((i)
                      * (Math.cos(Math.toRadians(controller.getAngleX())))
                      * (Math.cos(Math.toRadians(controller.getAngleY())))));

      if (collisionLooking(-newX, -newY, -newZ)) {
        Cube selected = getCube(-(int) newX, -(int) newY, -(int) newZ);
        int[][] sides = new int[6][3];
        float[] differences = new float[6];
        for (int j = 0; j < sides.length; j++) {
          sides[j] = selected.getSideMid(j);
        }

        for (int j = 0; j < sides.length; j++) {
          differences[j] =
              (float)
                  Math.sqrt(
                      Math.pow((sides[j][0] - newX), 2)
                          + Math.pow((sides[j][1] - newY), 2)
                          + Math.pow((sides[j][2] - newZ), 2));
        }

        float smallest = differences[0];
        for (int j = 0; j < differences.length; j++) {
          if (differences[j] < smallest) smallest = differences[j];
        }

        int side = -1;

        for (int j = 0; j < differences.length; j++) {
          if (differences[j] == smallest) side = j;
        }

        selected.selectedSide[side] = true;

        selectedCube = selected;
        selectedSide = side;
        anythingSelected = true;

        break;
      }
    }

    if (!anythingSelected) {
      selectedCube = null;
      selectedSide = -1;
    }
  }