Exemplo n.º 1
0
 public void
     createAsteroid() { // todo as we run lower on asteroids, apply affects to players ship to
                        // simulate entering a planet
   Asteroid asteroid =
       new Asteroid(WorldHandler.createAsteroid(stage.getWorld(), stage.getPlanetHandler()));
   AsteroidActorData data = (AsteroidActorData) asteroid.getActorData();
   data.asteroid = asteroid;
   stage.addAsteroid(asteroid);
   asteroidCount++;
   Gdx.app.log(
       "COUNT",
       "AsteroidLevel Count: "
           + asteroidCount
           + " / "
           + stage.getPlanetHandler().getAsteriodCount());
   if (asteroidCount == stage.getPlanetHandler().getAsteriodCount() && !triggered) {
     triggered = true;
     Gdx.app.log("COUNT", "AsteroidLevel complete");
     if (obstacleTimer != null) obstacleTimer.cancel();
     stage.setUpNormalLevel();
   }
   if (asteroidCount > stage.getPlanetHandler().getAsteriodCount()) {
     asteroid.getActorData().isRemoved = true;
     stage.addDead(asteroid.getBody());
   }
 }
Exemplo n.º 2
0
  @SuppressWarnings("Duplicates")
  public void handleContact(Body a, Body b) {
    boolean playerHitAsteroid =
        (WorldHandler.isAsteroid(a) && WorldHandler.isPlayer(b))
            || WorldHandler.isPlayer(a) && WorldHandler.isAsteroid(b);
    boolean bulletHitAsteroid =
        (a.isBullet() && WorldHandler.isAsteroid(b)) || b.isBullet() && WorldHandler.isAsteroid(a);
    boolean playerHitPickup =
        (WorldHandler.isPlayer(a) && WorldHandler.isPickup(b))
            || (WorldHandler.isPickup(a) && WorldHandler.isPlayer(b));

    Body asteroid;
    Body player;
    final Body bullet;
    if (playerHitAsteroid) {
      if (WorldHandler.isAsteroid(a)) {
        asteroid = a;
        player = b;
      } else {
        asteroid = b;
        player = a;
      }
      PlayerActorData p_data = (PlayerActorData) player.getUserData();
      AsteroidActorData a_data = (AsteroidActorData) asteroid.getUserData();
      if (a_data.subHealth(5) <= 0) {
        a_data.isRemoved = true;
        stage.addDead(asteroid);
      }
      asteroid.applyForceToCenter(new Vector2(0, 100f), true);

      if (p_data.subHealth(a_data.getDamage()) <= 0) {
        // game over
        Gdx.app.log("plr", "plr dead"); // todo player death
      }
      if (infoLabel != null) infoLabel.setText("Player HP: " + p_data.getHealth());
      playerHPBar.setBarWidth((int) p_data.getHealth());
    }
    if (bulletHitAsteroid) {
      if (a.isBullet()) {
        bullet = a;
        asteroid = b;
      } else {
        bullet = b;
        asteroid = a;
      }
      ActorData b_data = (ActorData) bullet.getUserData();
      AsteroidActorData a_data = (AsteroidActorData) asteroid.getUserData();

      new Timer()
          .scheduleTask(
              new Timer.Task() {
                @Override
                public void run() {
                  createExplosion(bullet.getPosition().x + 1f, bullet.getPosition().y + 0.7f);
                }
              },
              0.05f);

      b_data.isRemoved = true;
      stage.addDead(bullet);
      playerHandler.addCurrency(2);

      if (a_data.subHealth(WorldHandler.getProjectileDamage(bullet)) <= 0) {
        Gdx.app.log("OGH", "Asteroid dead - Spawn pickup?");
        if (random.nextInt(100) > 70) {
          final Body finalAsteroid = asteroid;
          new Timer()
              .scheduleTask(
                  new Timer.Task() {
                    @Override
                    public void run() {
                      createPickup(finalAsteroid.getPosition().x, finalAsteroid.getPosition().y);
                    }
                  },
                  2);
        }

        stage.addDead(asteroid);
        a_data.isRemoved = true;
      }
    }
    Body pickup;
    if (playerHitPickup) {
      if (WorldHandler.isPlayer(a)) {
        player = a;
        pickup = b;
      } else {
        player = b;
        pickup = a;
      }
      PickupData pData = (PickupData) pickup.getUserData();
      PlayerActorData plData = (PlayerActorData) player.getUserData();

      pData.isRemoved = true;
      stage.addDead(pickup);

      if (pData.getType().equals(Constants.CURRENCY_PICKUP_ASSET_ID))
        playerHandler.addCurrency(100);
      else plData.addHealth(50); // todo magic numbers
    }
  }