Example #1
0
  /**
   * Set the teams and assign the players models according to their teams.
   *
   * @param players - array of player usernames.
   * @param teams - team allocating, "0" for guard and "1" for spy.
   */
  public void setTeams(String[] players, String[] teams) {

    // System.out.println("Players: " + players.length + ", Teams: "
    // + teams.length);
    //
    // for (String s : teams)
    // System.out.print(s + ", ");
    // System.out.println("===================");
    //
    // System.out.println(this.players.size());
    //
    // for (String s : players)
    // System.out.print(s + ", ");
    // System.out.println("===================");

    for (int i = 0; i < players.length; i++) {

      // Assign the team
      Player p = getPlayer(players[i]);

      if (p == null) System.err.println("Player " + players[i] + " is null");

      p.setSide((teams[i].equals("0") ? Team.GUARD : Team.SPY));

      // The string will reference a pre-loaded model in the renderer
      String model = (teams[i].equals("0") ? "Guard" : "Spy");

      // Translation and rotations
      SpawnPoint spawn = getNextSpawn(p.getSide());
      p.setRoom(spawn.room);
      p.setX(spawn.x);
      p.setY(spawn.y);
      Vec3 trans = new Vec3(p.getX(), 0, p.getY());
      Vec3 rot = new Vec3(0, -p.getRotation(), 0);
      Vec3 scale = new Vec3(0.1, 0.1, 0.1);

      // Player model

      // Sets up the renderer for drawing the teams correctly
      R_Player.Team rteam = R_Player.Team.SPY;
      if (p.getSide() == Team.GUARD) {
        rteam = R_Player.Team.GUARD;
      }
      R_Player pl =
          new R_Player(p.getUsername(), game.getR_ModelData(model), rteam, trans, rot, scale);

      // Assign the model to the player and the renderer
      p.setModel(pl);
      // game.r_addModel(pl);
    }

    // for (Player p : this.players) {
    // if (p.getRoom().equals(game.getPlayer().getRoom()))
    // game.r_addModel(p.getModel());
    // }
    // for (Player p : this.players) {
    // System.out.println(p.getUsername() + " is a "
    // + p.getSide().toString());
    // }

    // Now that the models have been loaded we can finally render the level
    readyToRender = true;
  }