Beispiel #1
0
 public void addCube(int x, int y, int z) {
   Cube tempCube = new Cube("stoneTop.png", -x, -y, -z);
   if (!collision(-x, -y, -z)
       && !collision(
           (int) controller.getX(), (int) controller.getY(), (int) controller.getZ(), tempCube)) {
     cubes.add(tempCube);
   }
 }
Beispiel #2
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;
    }
  }
Beispiel #3
0
 public boolean collisionJump(float x, float y, float z) {
   boolean collision = false;
   for (Cube cube : cubes) {
     if (cube.collision(-x, -y, -z, controller.playerHeight, controller.playerBox)) {
       collision = true;
       controller.jumping = false;
       break;
     }
   }
   return collision;
 }
Beispiel #4
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));
 }
Beispiel #5
0
  public void renderHud() {
    glClear(GL_DEPTH_BUFFER_BIT);
    glTranslatef(-controller.getX(), -controller.getY(), -controller.getZ());
    glRotatef((float) (-controller.getRotX() * controller.mouseSpeed), 0.0f, 1.0f, 0.0f);
    glRotatef((float) (-controller.getRotY() * -controller.mouseSpeed), 1.0f, 0.0f, 0.0f);

    glColor3f(0f, 1.0f, 0f);
    glLineWidth(2f);

    glBegin(GL_LINES);
    glVertex3f(-1.5f, 0f, -50f);
    glVertex3f(-0.5f, 0f, -50f);

    glVertex3f(0.5f, 0f, -50f);
    glVertex3f(1.5f, 0f, -50f);

    glVertex3f(0f, -1.5f, -50f);
    glVertex3f(0f, -0.5f, -50f);

    glVertex3f(0f, 0.5f, -50f);
    glVertex3f(0f, 1.5f, -50f);
    glEnd();

    glColor3f(1f, 1f, 1f);

    Model currentWeapon = null;
    Texture weaponTexture = null;

    switch (controller.getSelectedWeapon()) {
      case 1:
        currentWeapon = knife;
        weaponTexture = knifeT;
        break;
      case 2:
        currentWeapon = gun;
        weaponTexture = gunT;
        break;
      case 3:
        currentWeapon = m4;
        weaponTexture = m4T;
        break;
    }

    weaponTexture.bind();

    for (Face face : currentWeapon.faces) {
      Vector3f v1 = currentWeapon.verticies.get((int) face.vertex.x - 1);
      Vector3f v2 = currentWeapon.verticies.get((int) face.vertex.y - 1);
      Vector3f v3 = currentWeapon.verticies.get((int) face.vertex.z - 1);

      Vector2f t1 = currentWeapon.textures.get((int) face.texture.x - 1);
      Vector2f t2 = currentWeapon.textures.get((int) face.texture.y - 1);
      Vector2f t3 = currentWeapon.textures.get((int) face.texture.z - 1);

      glBegin(GL_TRIANGLES);
      glTexCoord2f(t1.x, t1.y);
      glVertex3f(
          v1.x + controller.gunXOffset, v1.y + controller.gunYOffset, v1.z + controller.gunZOffset);
      glTexCoord2f(t2.x, t2.y);
      glVertex3f(
          v2.x + controller.gunXOffset, v2.y + controller.gunYOffset, v2.z + controller.gunZOffset);
      glTexCoord2f(t3.x, t3.y);
      glVertex3f(
          v3.x + controller.gunXOffset, v3.y + controller.gunYOffset, v3.z + controller.gunZOffset);
      glEnd();
    }

    text.drawString("health:123   armor:123", -300, -200);
  }
Beispiel #6
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;
    }
  }