コード例 #1
0
ファイル: ZedSurvivor.java プロジェクト: faijdherbe/LD22
  @Override
  public void updateGameLoop(long timeSinceLastFrame) {
    // TODO Auto-generated method stub
    super.updateGameLoop(timeSinceLastFrame);

    time += (timeSinceLastFrame / 1000000);
    realtime += time / 1000;
    if (time > secondsPerDay) {
      time = time % secondsPerDay;

      /* daybreak! spawn more items and mobs */
      for (int i = 0; i < mobSpawnCount; i++) {
        this.mobs.add((MobAI) level.spawnMob());
      }

      mobSpawnCount += 20;

      Item ammo = new AmmoPack();
      ammo.origin = level.getSpawnLocation();
      this.level.addItem(ammo);

      HealthPack h = new HealthPack();
      h.origin = this.level.randomSpawnPoint();
      this.level.addItem(h);
    }

    ArrayList<Projectile> died = new ArrayList<Projectile>();
    ArrayList<Mob> diedMobs = new ArrayList<Mob>();
    for (Projectile p : projectiles) {
      p.update(timeSinceLastFrame);

      for (Mob m : mobs) {
        if (m.hitTest(p) && !diedMobs.contains(m)) {
          died.add(p);
          m.dealDamage(p.damage);
          if (m.health == 0) {
            diedMobs.add(m);
            score++;
          }
        }
      }
      mobs.removeAll(diedMobs);
      diedMobs.clear();

      if (p.ttl < 0) {
        died.add(p);
      }
    }
    projectiles.removeAll(died);

    if (player.weapon != null && player.fireButtonPressed && player.weapon.readyToFire()) {

      Projectile[] p = player.weapon.fire(player);
      for (Projectile projectile : p) {
        projectiles.add(projectile);
      }
    }

    player.update(timeSinceLastFrame);

    for (MobAI mob : mobs) {
      Vector2f dist = new Vector2f(mob.origin.x - player.origin.x, mob.origin.y - player.origin.y);
      if (Math.abs(dist.x) > Math.abs(dist.y)) {
        mob.setDirection((dist.x < 0) ? Sprite.Direction.RIGHT : Sprite.Direction.LEFT);

      } else {
        mob.setDirection((dist.y < 0) ? Sprite.Direction.DOWN : Sprite.Direction.UP);
      }
      mob.update(timeSinceLastFrame);
      if (mob.hitTest(player.origin, 2)) {
        player.dealDamage(1);
      }
    }
    if (player.health == 0) {
      this.launcher.setGameWindow(new ZedGameOverMenu(this.score));
    }

    for (Item item : level.items) {
      if (item != null) item.update(timeSinceLastFrame);
    }
  }