コード例 #1
0
ファイル: Round.java プロジェクト: TeamPochard/Assessment-3
  /**
   * Spawns a mob somewhere on the map. Ensures it doesn't intersect anything and is on a spawn tile
   *
   * @param mob
   * @return
   */
  public boolean spawnMob(Mob mob) {
    float x = mob.getX();
    float y = mob.getY();
    TextureSet textureSet = mob.getWalkingTextureSet();

    // Check mob isn't out of bounds.
    if (x < 0
        || x > getMapWidth() - textureSet.getWidth()
        || y > getMapHeight() - textureSet.getHeight()) {
      return false;
    }

    // Check mob doesn't intersect anything.
    for (Entity entity : entities) {
      if (entity instanceof Character
          && (mob.intersects(entity.getX(), entity.getY(), entity.getWidth(), entity.getHeight())
              || mob.collidesX(0)
              || mob.collidesY(0))) {
        return false;
      }
    }

    if (getSpawnLayer().getCell((int) x / getTileWidth(), (int) y / getTileHeight()) == null) {
      return false;
    }

    entities.add(mob);
    return true;
  }
コード例 #2
0
ファイル: Round.java プロジェクト: TeamPochard/Assessment-3
  /**
   * Creates a mob and adds it to the list of entities, but only if it doesn't intersect with
   * another character.
   *
   * @param x the initial x coordinate
   * @param y the initial y coordinate
   * @param health the initial health of the mob
   * @param textureSet the texture set to use
   * @param speed how fast the mob moves in pixels per second
   * @return true if the mob was successfully added, false if there was an intersection and the mob
   *     wasn't added
   */
  public boolean createMob(
      Mob mob, float x, float y, int health, TextureSet textureSet, int speed) {

    // Check mob isn't out of bounds.
    if (x < 0
        || x > getMapWidth() - textureSet.getWidth()
        || y > getMapHeight() - textureSet.getHeight()) {
      return false;
    }

    // Check mob doesn't intersect anything.
    for (Entity entity : entities) {
      if (entity instanceof Character
          && (mob.intersects(entity.getX(), entity.getY(), entity.getWidth(), entity.getHeight())
              || mob.collidesX(0)
              || mob.collidesY(0))) {
        return false;
      }
    }

    entities.add(mob);
    return true;
  }
コード例 #3
0
ファイル: Round.java プロジェクト: TeamPochard/Assessment-3
  /**
   * Updates all entities in this Round.
   *
   * @param delta the time elapsed since the last update
   */
  public void update(float delta) {

    powerUpManager.update(delta);
    floatyNumbersManager.update(delta);

    if (objective != null) {
      objective.update(delta);

      if (objective.getStatus() == Objective.OBJECTIVE_COMPLETED) {
        parent.showWinScreen(player.getScore());
      } else if (player.isDead()) {
        parent.showLoseScreen();
      }
    }

    // int updateNumber =0, totalNumber=entities.size(), numMobs=0;
    for (int i = 0; i < entities.size(); i++) {
      Entity entity = entities.get(i);
      /*            if(entity instanceof Mob)
      numMobs++;*/

      if (entity.isRemoved()) {
        if (entity instanceof Mob && ((Mob) entity).isDead()) {
          int score =
              (int)
                  (((Mob) entity).getScore()
                      * (powerUpManager.getIsActive(PowerupManager.powerupTypes.SCORE_MULTIPLIER)
                          ? Player.PLAYER_SCORE_MULTIPLIER
                          : 1));
          player.addScore(score);
          floatyNumbersManager.createScoreNumber(score, entity.getX(), entity.getY());
          if (objective.getObjectiveType() == Objective.objectiveType.BOSS) {
            spawnRandomMobs(1, 0, 0, 1000, 1000);
          }
        }

        entities.remove(i);
      } else if ((entity.distanceTo(player.getX(), player.getY()) < UPDATE_DISTANCE_X)
          && (entity.distanceTo(player.getX(), player.getY()) < UPDATE_DISTANCE_Y)) {
        // Don't bother updating entities that aren't on screen.
        entity.update(delta);
        // updateNumber++;
      }
    }

    if (Gdx.input.isKeyJustPressed(Input.Keys.P)) {
      for (int x = 0; x < 1000; x++) {
        createProjectile(
            MathUtils.random(300, 1500),
            MathUtils.random(300, 1500),
            MathUtils.random(300, 1500),
            MathUtils.random(300, 1500),
            500,
            0,
            0,
            0,
            player);
      }
    }
    // System.out.println("total:"+totalNumber+" updated:"+updateNumber+" numMobs:"+numMobs);
  }