コード例 #1
0
  public void update(float delta) {
    if (MathUtils.random() < delta * Constants.ICICLE_SPAWNS_PER_SECOND) {

      Vector2 newIciclePosition =
          new Vector2(MathUtils.random() * viewport.getWorldWidth(), viewport.getWorldHeight());
      Icicle newIcicle = new Icicle(newIciclePosition);
      icicleList.add(newIcicle);
    }

    for (Icicle icicle : icicleList) {
      icicle.update(delta);
    }

    // TODO: begin a removal session
    icicleList.begin();

    // TODO: Remove any icicle completely off the bottom of the screen
    for (int i = 0; i < icicleList.size; i++) {
      if (icicleList.get(i).position.y < -Constants.ICICLES_HEIGHT) {
        icicleList.removeIndex(i);
      }
    }

    // TODO: End removal session
    icicleList.end();
  }
コード例 #2
0
  public void update(float delta) {
    if (MathUtils.random() < delta * Constants.ICICLE_SPAWNS_PER_SECOND) {
      Vector2 newIciclePosition =
          new Vector2(MathUtils.random() * viewport.getWorldWidth(), viewport.getWorldHeight());
      Icicle newIcicle = new Icicle(newIciclePosition);
      icicleList.add(newIcicle);
    }

    for (Icicle icicle : icicleList) {
      icicle.update(delta);
    }

    icicleList.begin();
    for (int i = 0; i < icicleList.size; i++) {
      if (icicleList.get(i).position.y < -Constants.ICICLES_HEIGHT) {
        // TODO: Increment count of icicles dodged
        iciclesDodged++;
        icicleList.removeIndex(i);
      }
    }
    icicleList.end();
  }
コード例 #3
0
ファイル: GigaGal.java プロジェクト: matvidako/ud406
  public void update(float delta, Array<Platform> platforms) {

    lastFramePosition.set(position);
    velocity.y -= Constants.GRAVITY;
    position.mulAdd(velocity, delta);

    if (position.y < Constants.KILL_PLANE) {
      init();
    }

    // Land on/fall off platforms
    if (jumpState != Enums.JumpState.JUMPING) {
      if (jumpState != JumpState.RECOILING) {
        jumpState = Enums.JumpState.FALLING;
      }

      for (Platform platform : platforms) {
        if (landedOnPlatform(platform)) {
          jumpState = Enums.JumpState.GROUNDED;
          velocity.y = 0;
          velocity.x = 0;
          position.y = platform.top + Constants.GIGAGAL_EYE_HEIGHT;
        }
      }
    }

    // Collide with enemies

    Rectangle gigaGalBounds =
        new Rectangle(
            position.x - Constants.GIGAGAL_STANCE_WIDTH / 2,
            position.y - Constants.GIGAGAL_EYE_HEIGHT,
            Constants.GIGAGAL_STANCE_WIDTH,
            Constants.GIGAGAL_HEIGHT);

    for (Enemy enemy : level.getEnemies()) {
      Rectangle enemyBounds =
          new Rectangle(
              enemy.position.x - Constants.ENEMY_COLLISION_RADIUS,
              enemy.position.y - Constants.ENEMY_COLLISION_RADIUS,
              2 * Constants.ENEMY_COLLISION_RADIUS,
              2 * Constants.ENEMY_COLLISION_RADIUS);
      if (gigaGalBounds.overlaps(enemyBounds)) {

        if (position.x < enemy.position.x) {
          recoilFromEnemy(Direction.LEFT);
        } else {
          recoilFromEnemy(Direction.RIGHT);
        }
      }
    }

    // Move left/right
    if (jumpState != JumpState.RECOILING) {
      if (Gdx.input.isKeyPressed(Keys.LEFT)) {
        moveLeft(delta);
      } else if (Gdx.input.isKeyPressed(Keys.RIGHT)) {
        moveRight(delta);
      } else {
        walkState = Enums.WalkState.NOT_WALKING;
      }
    }

    // Jump
    if (Gdx.input.isKeyPressed(Keys.Z)) {
      switch (jumpState) {
        case GROUNDED:
          startJump();
          break;
        case JUMPING:
          continueJump();
      }
    } else {
      endJump();
    }

    // TODO: Check if GigaGal should pick up a powerup
    // This is a tough one. Check for overlaps similar to how we detect collisions with enemies,
    // then remove any picked up powerups (and update GigaGal's ammo count)
    // Remember to check out the solution project if you run into trouble!
    DelayedRemovalArray<Powerup> powerups = level.getPowerups();
    powerups.begin();
    for (int i = 0; i < powerups.size; i++) {
      Powerup powerup = powerups.get(i);
      Rectangle powerupBounds =
          new Rectangle(
              powerup.position.x - Constants.POWERUP_CENTER.x,
              powerup.position.y - Constants.POWERUP_CENTER.y,
              Assets.instance.powerupAssets.powerup.getRegionWidth(),
              Assets.instance.powerupAssets.powerup.getRegionHeight());
      if (gigaGalBounds.overlaps(powerupBounds)) {
        ammo += Constants.POWERUP_AMMO;
        powerups.removeIndex(i);
      }
    }
    powerups.end();

    // Shoot
    // TODO: Check if GigaGal has any ammo left
    if (Gdx.input.isKeyJustPressed(Keys.X) && ammo > 0) {

      // TODO: Decrement ammo
      ammo--;
      Vector2 bulletPosition;

      if (facing == Direction.RIGHT) {
        bulletPosition =
            new Vector2(
                position.x + Constants.GIGAGAL_CANNON_OFFSET.x,
                position.y + Constants.GIGAGAL_CANNON_OFFSET.y);
      } else {
        bulletPosition =
            new Vector2(
                position.x - Constants.GIGAGAL_CANNON_OFFSET.x,
                position.y + Constants.GIGAGAL_CANNON_OFFSET.y);
      }
      level.spawnBullet(bulletPosition, facing);
    }
  }