Package net.shadewind.racetrack

Examples of net.shadewind.racetrack.Car


       
    List<Vector2i> startPositions = map.getStartPositions();
    int position = 0;
    cars.clear();
    for (Client c : clients) {
      Car car = new Car();
      car.pushPosition(startPositions.get(position));
      cars.put(c, car);
      position = (position + 1) % startPositions.size();
    }
   
    for (Client c : clients) {
      c.gameStarted(map, collisionsEnabled);
      for (Client carClient : clients) {
        Car car = cars.get(carClient);
        c.carReset(carClient.getId(), car.getPosition());
      }
    }
   
    state = GameState.STARTED;
    turnPointer = -1;
View Full Code Here


  public synchronized void drive(Client client, Vector2i acc)
  {
    if (activeClients.get(turnPointer) != client)
      return;
   
    Car car = cars.get(client);
    car.drive(acc);
    logger.info("Car " + client.getId() + " drove " + acc.x() + "," + acc.y());
   
    for (Client c : clients)
      c.carDriven(client.getId(), car.getPosition(), car.getVelocity());

    checkCrash(client);
    checkFinish(client);
    nextTurn();
  }
View Full Code Here

    activeClients.remove(client);
  }
 
  private void checkCrash(Client client)
  {
    Car car = cars.get(client);
    Vector2i position = car.getPosition();
    if (map.getBlockType(position.x(), position.y()) == '#') {
      deactivateClient(client);
      car.setCrashed(true);
      for (Client c : clients)
        c.carCrashed(client.getId());
    }
   
    if (collisionsEnabled) {
      for (Client otherClient : clients) {
        if (client == otherClient)
          continue;
       
        Car otherCar = cars.get(otherClient);
        if (car.getPosition().equals(otherCar.getPosition())) {
          deactivateClient(client);
          car.setCrashed(true);
          for (Client c : clients)
            c.carCrashed(client.getId());
          break;
View Full Code Here

    }
  }

  private void checkFinish(Client client)
  {
    Car car = cars.get(client);
    List<Vector2i> path = car.getPath();
    List<Vector2i> pointPath = new ArrayList<Vector2i>();
    for (int i = 0; i < (path.size() - 1); i++)
      pointPath.addAll(drawLine(path.get(i), path.get(i + 1)));
   
    int checkpointCount = 0;
    int totalCheckpoints = map.getCheckpoints();
    for (Vector2i v : pointPath) {
      //System.out.println(v.toString());
      char block = map.getBlockType(v.x(), v.y());
      switch (block)
      {
      case '1':
      case '2':
      case '3':
      case '4':
      case '5':
      case '6':
      case '7':
      case '8':
      case '9':
        int n = block - '0';
        if ((checkpointCount + 1) == n)
          checkpointCount = n;
        break;
       
      case 'E':
        if (checkpointCount == totalCheckpoints) {
          deactivateClient(client);
          car.setFinished(true);
          for (Client c : clients)
            c.carFinished(client.getId());
        }
        return;   
      }
View Full Code Here

  {
    cancelTimeout();
   
    List<Score> scores = new ArrayList<Score>();
    for (Client client : clients) {
      Car car = cars.get(client);
      if (car.isFinished()) {
        scores.add(new Score(
            client.getName(),
            car.getPath().size() - 1,
            map.getName(),
            collisionsEnabled));
      }
    }
    highscoreManager.addScores(scores);
View Full Code Here

  }

  private void paintAcceleratorControls(Graphics2D g)
  {
    Player player = client.getPlayer();
    Car car = player.getCar();
    Vector2i pos = car.getPosition();
    if (pos == null)
      return;
   
    double originX = pos.x() + 0.5;
    double originY = pos.y() + 0.5;
View Full Code Here

  {
    List<Player> players = new ArrayList<Player>(client.getPlayers());
    Collections.sort(players);
    int colorIndex = 0;
    for (Player player : players) {
      Car car = player.getCar();
      List<Vector2i> path = car.getPath();
     
      g.setColor(COLORS[colorIndex]);
      g.setStroke(new BasicStroke(0.1f));
     
      for (int i = 0; i < path.size(); i++) {
View Full Code Here

  {
    int playerId = command.intArgument(0);
    Player player = players.get(playerId);
    if (player == null)
      throw new CommException("Unknown player id = " + playerId);
    Car car = player.getCar();
    car.reset();
    car.pushPosition(new Vector2i(
        command.intArgument(1),
        command.intArgument(2)));
    listener.carReset(player);
  }
View Full Code Here

  {
    Player player = players.get(command.intArgument(0));
    if (player == null)
      throw new CommException("Player is unknown.");
   
    Car car = player.getCar();
    car.pushPosition(new Vector2i(command.intArgument(1), command.intArgument(2)));
    car.setVelocity(new Vector2i(command.intArgument(3), command.intArgument(4)));
    listener.carDriven(player);
  }
View Full Code Here

  {
    Player player = players.get(command.intArgument(0));
    if (player == null)
      throw new CommException("Player is unknown.");
   
    Car car = player.getCar();
    car.setCrashed(true);
    listener.carCrashed(player);
  }
View Full Code Here

TOP

Related Classes of net.shadewind.racetrack.Car

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.