Exemple #1
0
  public static void updateDimensions(Boolean updateCanvas) {
    CANVAS_WIDTH = WIDTH - (WALL_WIDTH * 2);
    CANVAS_HEIGHT = HEIGHT;

    if (updateCanvas) {
      Canvas cvs = control.getCanvas(1);
      cvs.setWidth(Asteroids.WIDTH);
      cvs.setHeight(Asteroids.HEIGHT);

      Image wall = Util.getImage("side_wall.png");

      Canvas leftWall = control.getLeftWall();
      Canvas rightWall = control.getRightWall();

      GraphicsContext lw = leftWall.getGraphicsContext2D();
      GraphicsContext rw = rightWall.getGraphicsContext2D();

      leftWall.setHeight(Asteroids.HEIGHT);
      rightWall.setHeight(Asteroids.HEIGHT);

      double wall_height =
          (((Asteroids.WALL_WIDTH * 100) / wall.getWidth()) / 100) * wall.getHeight();

      for (int h = 0; h < Asteroids.HEIGHT; h += wall_height) {
        lw.drawImage(wall, 0, wall_height * h, Asteroids.WALL_WIDTH, wall_height);
        Util.drawRotatedImage(rw, wall, 180, 0, wall_height * h, Asteroids.WALL_WIDTH, wall_height);
      }
    }
  }
Exemple #2
0
  @Override
  public void start(Stage ps) throws Exception {
    window = ps;
    control = new WindowControl();

    music = new MediaPlayer(new Media(Util.getResource("music.mp3").toString()));
    breakSound = new MediaPlayer(new Media(Util.getResource("asteroid_break.mp3").toString()));
    explosionSound = new MediaPlayer(new Media(Util.getResource("explosion.mp3").toString()));

    window.setTitle("Asteroids: Space adventure - By macjuul");

    Image icon_128 = Util.getImage("icon_128.png");
    Image icon_32 = Util.getImage("icon_32.png");
    Image icon_16 = Util.getImage("icon_16.png");

    window.getIcons().addAll(icon_128, icon_32, icon_16);

    window.setMinWidth(WIDTH);
    window.setMinHeight(HEIGHT);
    window.setWidth(WIDTH);
    window.setHeight(HEIGHT);

    Parent layout = (Parent) control.loadLayout();

    Scene s = new Scene(layout);

    // Set our stylesheet
    s.getStylesheets().add(Util.getResource("window/style.css").toExternalForm());

    s.setCursor(Cursor.CROSSHAIR);

    window.setScene(s);

    window
        .widthProperty()
        .addListener(
            (ObservableValue<? extends Number> ov, Number oldN, Number newN) -> {
              WIDTH = newN.intValue();

              updateDimensions(true);
            });

    window
        .heightProperty()
        .addListener(
            (ObservableValue<? extends Number> ov, Number oldN, Number newN) -> {
              HEIGHT = (int) newN.intValue();

              updateDimensions(true);
            });

    // Open the window
    window.show();

    window.setOnCloseRequest(
        e -> {
          Platform.exit();
          System.exit(0);
        });
  }