Пример #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);
    }
  }
Пример #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());
      }
    }
  }
Пример #3
0
  public void init(GameEnvironmentInterface environment) {
    this.environment = environment;
    bQuit = false;
    cheatMode = false;

    keyListener =
        new KeyAdapter() {
          public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
              bQuit = true;
            } else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
              model.startTurnLeft();
            } else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
              model.startTurnRight();
            } else if (e.getKeyCode() == KeyEvent.VK_UP) {
              model.startAccellerating();
            } else if (e.getKeyCode() == KeyEvent.VK_DOWN) {
              model.startBraking();
            }
            if (cheatMode) {
              if (e.getKeyCode() == KeyEvent.VK_1) {
                model.setCheatModeParameter("ALLCARSSHOWSERVERCAR", "NONE");
              }
              if (e.getKeyCode() == KeyEvent.VK_2) {
                model.setCheatModeParameter("ALLCARSSHOWSERVERCAR", "BOTH");
              }
              if (e.getKeyCode() == KeyEvent.VK_3) {
                model.setCheatModeParameter("ALLCARSSHOWSERVERCAR", "ONLY");
              }
              if (e.getKeyCode() == KeyEvent.VK_4) {
                model.setCheatModeParameter("MYCARSERVERUPDATETYPE", "1");
              }
              if (e.getKeyCode() == KeyEvent.VK_5) {
                model.setCheatModeParameter("MYCARSERVERUPDATETYPE", "2");
              }
            }
          }

          public void keyReleased(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_LEFT) {
              model.stopTurnLeft();
            } else if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
              model.stopTurnRight();
            } else if (e.getKeyCode() == KeyEvent.VK_UP) {
              model.stopAccellerating();
            } else if (e.getKeyCode() == KeyEvent.VK_DOWN) {
              model.stopBraking();
            }
          }
        };
    environment.getScreenHandler().setCursor(null);
    environment.getScreenHandler().getContainer().requestFocus();
    environment.getScreenHandler().getContainer().addKeyListener(keyListener);

    fps = new FpsCounter(50);
    cont = new BlockContainerData(20, 20, 30, 30, 32, 15, 12);

    model.init(environment, cont);

    environment.getScreenHandler().getContainer().setBackground(Color.black);
    // Preload images if not already loaded
    environment.getImageHandler().getImage("car1.gif");
    environment.getImageHandler().getImage("car2.gif");
    environment.getImageHandler().getImage("car3.gif");
    environment.getImageHandler().getImage("car4.gif");
    environment.getImageHandler().getImage("mapicons.gif");
    environment.getImageHandler().getImage("specialmapicons.gif");
  }