Пример #1
0
  @Override
  public void update(long delta, Entity e) {

    MainRenderer mr = (MainRenderer) DisplayManager.r;

    if (isAbleToUpdate()) {
      cnt1++;
      cnt2++;
      speed = ValueDirectory.normal_player_speed;

      collider.origin = position;

      rotation.x = InputManager.getMousePosition().y;
      rotation.y = InputManager.getMousePosition().x;
      hasGravity = true;

      // boxes.get(0).pos = new Vector3f(-position.x, -position.y-1, -position.z);
    }

    super.update(delta, e);
    if (!KeyManager.hasBreak()) {
      Ray r = new Ray(this.position, this.look, mr.currentWorld.cm, 100);
      r.calculate();
      if (MouseManager.getBreaking() && cnt1 % (int) ValueDirectory.break_interval == 0) {
        mr.currentWorld.cm.setblock(r.pos.x, r.pos.y, r.pos.z, new OBJ(-1, 0, 0));
      }

      if (KeyManager.isJumping()) tryJump();
      mr.cursorCube.pos = new Vector3f(0, 100, 0);
      /*mr.cursorCube.pos.x = r.pos.x;
      mr.cursorCube.pos.y = r.pos.y;
      mr.cursorCube.pos.z = r.pos.z;*/

      OBJ oldBlock = new OBJ(-1, -1, -1);
      OBJ block = new OBJ(0, KeyManager.getKeyNum() - 1, 0);
      if (!MouseManager.getPlacing()) {
        cnt2 = -1;
      }
      if (!MouseManager.getBreaking()) {
        cnt1 = -1;
      }
      if (MouseManager.getPlacing() && cnt2 % (int) ValueDirectory.break_interval == 0) {
        switch (r.RayDirection()) {
          case up:
            mr.currentWorld.cm.setblock(
                Chunk.getSmallerInt(r.pos.x),
                Chunk.getSmallerInt(r.pos.y) - 1,
                Chunk.getSmallerInt(r.pos.z),
                block);
            if (collider.col()) {
              mr.currentWorld.cm.setblock(
                  Chunk.getSmallerInt(r.pos.x),
                  Chunk.getSmallerInt(r.pos.y) - 1,
                  Chunk.getSmallerInt(r.pos.z),
                  oldBlock);
            }
            break;

          case down:
            mr.currentWorld.cm.setblock(
                Chunk.getSmallerInt(r.pos.x),
                Chunk.getSmallerInt(r.pos.y) + 1,
                Chunk.getSmallerInt(r.pos.z),
                block);
            if (collider.col()) {
              mr.currentWorld.cm.setblock(
                  Chunk.getSmallerInt(r.pos.x),
                  Chunk.getSmallerInt(r.pos.y) + 1,
                  Chunk.getSmallerInt(r.pos.z),
                  oldBlock);
            }
            break;

          case front:
            mr.currentWorld.cm.setblock(
                Chunk.getSmallerInt(r.pos.x),
                Chunk.getSmallerInt(r.pos.y),
                Chunk.getSmallerInt(r.pos.z) + 1,
                block);
            if (collider.col()) {
              mr.currentWorld.cm.setblock(
                  Chunk.getSmallerInt(r.pos.x),
                  Chunk.getSmallerInt(r.pos.y),
                  Chunk.getSmallerInt(r.pos.z) + 1,
                  oldBlock);
            }
            break;

          case back:
            mr.currentWorld.cm.setblock(
                Chunk.getSmallerInt(r.pos.x),
                Chunk.getSmallerInt(r.pos.y),
                Chunk.getSmallerInt(r.pos.z) - 1,
                block);
            if (collider.col()) {
              mr.currentWorld.cm.setblock(
                  Chunk.getSmallerInt(r.pos.x),
                  Chunk.getSmallerInt(r.pos.y),
                  Chunk.getSmallerInt(r.pos.z) - 1,
                  oldBlock);
            }
            break;

          case left:
            mr.currentWorld.cm.setblock(
                Chunk.getSmallerInt(r.pos.x) - 1,
                Chunk.getSmallerInt(r.pos.y),
                Chunk.getSmallerInt(r.pos.z),
                block);
            if (collider.col()) {
              mr.currentWorld.cm.setblock(
                  Chunk.getSmallerInt(r.pos.x) - 1,
                  Chunk.getSmallerInt(r.pos.y),
                  Chunk.getSmallerInt(r.pos.z),
                  oldBlock);
            }
            break;

          case right:
            mr.currentWorld.cm.setblock(
                Chunk.getSmallerInt(r.pos.x) + 1,
                Chunk.getSmallerInt(r.pos.y),
                Chunk.getSmallerInt(r.pos.z),
                block);
            if (collider.col()) {
              mr.currentWorld.cm.setblock(
                  Chunk.getSmallerInt(r.pos.x) + 1,
                  Chunk.getSmallerInt(r.pos.y),
                  Chunk.getSmallerInt(r.pos.z),
                  oldBlock);
            }
            break;

          default:
            if (r.col)
              System.out.println(
                  "Error in Player.java: Unknow direction: " + r.RayDirection() + " !");
            else
              // System.out.println("No colission!");
              break;
        }
      }
    }
  }
Пример #2
0
 @Override
 public float getMoveAngle() {
   return KeyManager.direction();
 }