예제 #1
0
  public void update(float deltaTime) {
    this.timer += deltaTime; // timer for endscreen
    this.timerCheckpoint += deltaTime; // timer for endscreen
    // Input Update
    controller.update(deltaTime);

    // Netzwerk Update
    this.updateEvents();

    if (controller.character != null) {
      // FIXME: last and current postition are always equal
      // if (controller.character.currentPosition.x != controller.character.lastPosition.x ||
      // controller.character.currentPosition.y != controller.character.lastPosition.y)
      deltaTimeUpdate += deltaTime;

      if (deltaTimeUpdate > 0.0005f) {
        MoveCharacter move = new MoveCharacter();

        move.x = controller.character.currentPosition.x;
        move.y = controller.character.currentPosition.y;
        move.direction = controller.character.direction.getValue();
        move.idle = controller.character.idle;

        client.sendTCP(move);

        deltaTimeUpdate = 0;
      }
    }

    Camera cam = CameraHelper.instance.camera;
    // The camera dimensions, halved
    float cameraHalfWidth = cam.viewportWidth * .5f;
    float cameraHalfHeight = cam.viewportHeight * .5f;

    // Move camera after player as normal
    if (controller.character != null) {
      int pos_x = (int) controller.character.currentPosition.x;
      if (pos_x % 2 == 0) pos_x++;
      int pos_y = (int) controller.character.currentPosition.y;
      if (pos_y % 2 == 0) pos_y++;
      CameraHelper.instance.camera.position.set(pos_x, pos_y, 0);
    }

    float cameraLeft = cam.position.x - cameraHalfWidth;
    float cameraRight = cam.position.x + cameraHalfWidth;
    float cameraBottom = cam.position.y - cameraHalfHeight;
    float cameraTop = cam.position.y + cameraHalfHeight;

    // Horizontal axis
    if (mapPixelWidth < cam.viewportWidth) {
      cam.position.x = mapPixelWidth / 2;
    } else if (cameraLeft <= 0) {
      cam.position.x = 0 + cameraHalfWidth;
    } else if (cameraRight >= mapPixelWidth) {
      cam.position.x = mapPixelWidth - cameraHalfWidth;
    }

    // Vertical axis
    if (mapPixelHeight < cam.viewportHeight) {
      cam.position.y = mapPixelHeight / 2;
    } else if (cameraBottom <= 0) {
      cam.position.y = 0 + cameraHalfHeight;
    } else if (cameraTop >= mapPixelHeight) {
      cam.position.y = mapPixelHeight - cameraHalfHeight;
    }

    // update objects
    checkpointCount = 0;
    deadTouries = 0;
    playingTouries = 0;
    for (GameObject obj : objs.getObjects()) {
      obj.update(deltaTime);
      resetIfOutsideOfMap(obj);

      if (obj instanceof CheckpointGameObject && ((CheckpointGameObject) obj).checked) {
        checkpointCount++;
      }

      // check for playing Tourist
      if (obj instanceof TouriCharacterObject) {
        playingTouries++;
      }
      // check for dead players
      if (obj instanceof CharacterObject) {
        if (((CharacterObject) obj).isDead) {
          deadTouries++;
        }
      }
    }

    // System.out.println(" timer: " +  timer);
    checkDeadTouries(this.timer > MAX_TIMER && MAX_TIMER != 0);
    // System.out.println(" MAX_TIMER: " +  MAX_TIMER);

    System.out.println(" timerCheckpoint: " + timerCheckpoint);
    checkCheckpoints(this.timerCheckpoint > MAX_TIMER_CHECKPOINT && MAX_TIMER_CHECKPOINT != 0);
    System.out.println(" MAX_TIMER_CHECKPOINT: " + MAX_TIMER_CHECKPOINT);

    // check for collusion
    for (GameObject obj : objs.getObjects()) {
      for (GameObject collusionObj : objs.getObjects()) {
        if (obj == collusionObj) continue;

        CollusionDirections.CollusionDirectionsTypes col =
            obj.bounds.intersection(collusionObj.bounds);
        if (col != CollusionDirections.CollusionDirectionsTypes.NONE) {
          obj.isCollusion(collusionObj, col);
        }
      }
    }
  }
예제 #2
0
 public void draw(SpriteBatch batch) {
   level.render();
   for (GameObject obj : objs.getObjects()) {
     obj.draw(batch);
   }
 }