Пример #1
0
  @Override
  protected void processSystem() {
    final float dt = world.getDelta();

    if (input.isKeyJustPressed(Keys.C)) {
      cameraSystem.freeLookEnabled = !cameraSystem.freeLookEnabled;
    }

    if (movementBlocker.update(dt) != TimerState.Active) {
      float angle = 0;
      boolean performRotation = true;

      Transform playerTransform = playerSystem.getShipTransform();

      if (input.isKeyJustPressed(Keys.UP)) {
        angle = -90;
        playerTransform.toRightDir(tmpAxis);
      } else if (input.isKeyJustPressed(Keys.DOWN)) {
        angle = 90;
        playerTransform.toRightDir(tmpAxis);
      } else if (input.isKeyJustPressed(Keys.LEFT)) {
        angle = -90;
        playerTransform.toDirection(tmpAxis);
      } else if (input.isKeyJustPressed(Keys.RIGHT)) {
        angle = 90;
        playerTransform.toDirection(tmpAxis);
      } else performRotation = false;

      if (performRotation) {
        if (playerSystem.tryRotateAroundPlanet(angle, tmpAxis)) {
          movementBlocker.start();
        }
      }
    }
  }
Пример #2
0
  @Override
  public void update(ParticleSystem system, int delta) {
    int cx = (int) cameraSystem.getOffsetX();
    int cy = (int) cameraSystem.getOffsetY();

    timer -= delta;

    if (timer <= 0) {
      timer = interval;

      int rowLowerBound =
          Math.max(0, (cy > 0 ? 0 : Math.abs(cy / blockMap.getBlockDepth()) - 1) - 5);
      int rowUpperBound =
          Math.min(
              blockMap.getDepth(),
              Math.abs(cy / blockMap.getBlockDepth())
                  + 1
                  + container.getHeight() / blockMap.getBlockDepth()
                  + 1
                  + blockMap.getHeight()
                  + 5);

      int columnLowerBound =
          Math.max(0, (cx > 0 ? 0 : Math.abs(cx / blockMap.getBlockWidth()) - 2) - 5);
      int columnUpperBound =
          Math.min(
              blockMap.getWidth(),
              Math.abs(cx / blockMap.getBlockWidth())
                  + 1
                  + container.getWidth() / blockMap.getBlockWidth()
                  + 2
                  + 5);

      int sy = rowLowerBound + (int) (Math.random() * (rowUpperBound - rowLowerBound - 1));
      int sx = columnLowerBound + (int) (Math.random() * (columnUpperBound - columnLowerBound - 1));

      boolean foundTree = false;

      for (int j = sy; !foundTree && j < rowUpperBound; ++j) {
        for (int i = sx; !foundTree && i < columnUpperBound; ++i) {
          if (blockMap.dataPackage.trees[i][j] > 0) {
            foundTree = true;

            Particle p = system.getNewParticle(this, 3000);
            p.setImage(
                AssetManager.getInstance()
                    .getImage(
                        "tree-particle-"
                            + Integer.toString((int) ((float) Math.random() * 100) % 3 + 1)));
            double r = Math.random();

            p.setColor(1, 1, 1, 0);
            p.setSize(50);
            p.setVelocity(
                (float) Math.cos(r * (float) Math.PI / 4.0f),
                (float) Math.sin(r * (float) Math.PI / 4.0f),
                0.3f);
            p.setOriented(true);

            r = (float) Math.random() * 300.0f;
            float a = (float) (Math.random() * 2.0 * Math.PI);
            int height =
                Math.max(
                    1,
                    (int)
                        (blockMap.dataPackage.heightMap[j][i] * blockMap.dataPackage.getHeight()));

            p.setPosition(
                i * blockMap.getBlockWidth() - 30,
                j * blockMap.getBlockDepth()
                    - (blockMap.getTowerHeight(i, j) + 1) * blockMap.getBlockHeight());
          }
        }
      }
    }
  }