Beispiel #1
0
  public void draw() {
    Graphics g = environment.getScreenHandler().getCurrentGraphics();
    g.clearRect(
        0,
        0,
        environment.getScreenHandler().getWidth(),
        environment.getScreenHandler().getHeight());
    fps.update();
    fps.draw(g, Color.red, 10, 10);
    g.setColor(Color.white);
    g.drawString(model.getInfoString(), 50, 10);
    g.setColor(Color.white);
    if (cheatMode) {
      g.setColor(Color.white);
      g.drawString("CHEATMODE", 80, 10);
    }
    g.setClip(cont.getOffsetX(), cont.getOffsetY(), cont.getDrawingSizeX(), cont.getDrawingSizeY());
    if (model.isInitialized()) {
      model.getMap().draw(g, 0);

      model.getMyCar().draw(g, 0);
      CarDrawInterface cars[] = model.getOpponentCars();
      for (int i = 0; i < cars.length; i++) {
        cars[i].draw(g, 0);
      }
      if (!model.isStarted()) {
        g.setColor(Color.white);
        g.clearRect(50, 50, 400, 150);
        g.drawString("Accellerate to start game", 100, 100);
        if (model.isMultiplayer()) {
          if (model.getNoOfHumanCars() > 1) {
            g.drawString(
                "Currently " + (model.getNoOfHumanCars() - 1) + " other human player(s) connected",
                100,
                120);
          } else {
            g.drawString("Only you and computer contolled cars are connected", 100, 120);
          }
          g.drawString("You can wait for more human players to connect", 100, 140);
        }
      }
    } else {
      g.setColor(Color.white);
      g.clearRect(50, 50, 400, 150);
      g.drawString("Loading game data, please wait...", 100, 100);
    }
  }
Beispiel #2
0
  public void update() {
    if (model.isInitialized()) {
      model.update();

      // Scroll map
      int scrollBorderLeft = 200;
      int scrollBorderRight = 200;
      int scrollBorderUp = 200;
      int scrollBorderDown = 200;
      CarDrawInterface car = model.getMyCar();
      if (car.getPosX() < (cont.getScrollingOffsetX() + scrollBorderLeft)) {
        cont.setScrollingOffsetX(car.getPosX() - scrollBorderLeft);
      }
      if (car.getPosX()
          > (cont.getScrollingOffsetX() + cont.getDrawingSizeX() - scrollBorderRight)) {
        cont.setScrollingOffsetX(car.getPosX() - cont.getDrawingSizeX() + scrollBorderRight);
      }
      if (car.getPosY() < (cont.getScrollingOffsetY() + scrollBorderUp)) {
        cont.setScrollingOffsetY(car.getPosY() - scrollBorderUp);
      }
      if (car.getPosY()
          > (cont.getScrollingOffsetY() + cont.getDrawingSizeY() - scrollBorderDown)) {
        cont.setScrollingOffsetY(car.getPosY() - cont.getDrawingSizeY() + scrollBorderDown);
      }

      // Make sure we don't scroll the map to much
      if (cont.getScrollingOffsetX() < 0) {
        cont.setScrollingOffsetX(0);
      }
      if (cont.getScrollingOffsetX() > cont.getScrollingSizeX() - cont.getDrawingSizeX()) {
        cont.setScrollingOffsetX(cont.getScrollingSizeX() - cont.getDrawingSizeX());
      }
      if (cont.getScrollingOffsetY() < 0) {
        cont.setScrollingOffsetY(0);
      }
      if (cont.getScrollingOffsetY() > cont.getScrollingSizeY() - cont.getDrawingSizeY()) {
        cont.setScrollingOffsetY(cont.getScrollingSizeY() - cont.getDrawingSizeY());
      }
    }
  }