示例#1
0
 public Player(double x) {
   hp = 100;
   pX = x;
   playerTex = new ImageIcon("TEXTURE/stickman.png");
   pY = Constants.GROUND - playerTex.getIconHeight();
   pRect =
       new Rectangle2D.Double(x + playerTex.getIconWidth() / 2, pY, 1, playerTex.getIconHeight());
 }
示例#2
0
  /**
   * Creates a new GMap object based on a base directory specified in the constructure.
   *
   * @param cache - Base directory to search for cached image folders.
   */
  public GMap(String cache) {
    // data source
    this.gDataSourceMap = new GDataSourceMap(cache + "/map_cache");
    this.gDataSourceSatellite = new GDataSourceSatellite(cache + "/sat_cache");
    // this.gDataSourceOverlay = new GDataSourceOverlay(cache+"/overlay_cache");
    this.gDataSourceHybrid = new GDataSourceHybrid(cache + "/hybrid_cache", gDataSourceSatellite);

    // build default image
    defaultImage = getDefaultImage(GDataSource.sourceSize.width, GDataSource.sourceSize.height);

    // init gdraw draw object
    this.gDraw = new GDraw();

    // mode
    this.mode = MAP_MODE;

    // icon
    ImageIcon loadImage = new ImageIcon("images/google.png");
    googleImage = loadImage.getImage();
  }
示例#3
0
  // get an image from the given filename
  private static Image getImage(String filename) {

    // to read from file
    ImageIcon icon = new ImageIcon(filename);

    // try to read from URL
    if ((icon == null) || (icon.getImageLoadStatus() != MediaTracker.COMPLETE)) {
      try {
        URL url = new URL(filename);
        icon = new ImageIcon(url);
      } catch (Exception e) {
        /* not a url */
      }
    }

    // in case file is inside a .jar
    if ((icon == null) || (icon.getImageLoadStatus() != MediaTracker.COMPLETE)) {
      URL url = StdDraw.class.getResource(filename);
      if (url == null) throw new RuntimeException("image " + filename + " not found");
      icon = new ImageIcon(url);
    }

    return icon.getImage();
  }
示例#4
0
    @Override
    public void paintComponent(Graphics g) {
      super.paintComponent(g);
      Graphics2D g2 = (Graphics2D) g;

      // paint ball, paddle, and brick configuration
      g2.drawImage(background.getImage(), 0, 0, null);
      bconfig.paint(g2);
      paddle.paint(g2);
      ball.paint(g2);
      g2.setColor(Color.WHITE);
      g2.setFont(new Font("Serif", Font.PLAIN, 20));
      g2.drawString("Score: " + score, 15, 20);
      if (ball.getY() > 500) {
        g2.setColor(Color.WHITE);
        g2.setFont(new Font("Serif", Font.PLAIN, 30));
        g2.drawString("Game Over!", 200, 300);
        g2.drawString("Your final score was " + score, 150, 330);
        timer.stop();
      }
    }
示例#5
0
 public void paintComponent(Graphics g) {
   Graphics2D g2 = (Graphics2D) g;
   playerTex.paintIcon(this, g2, (int) pX, (int) pY);
 }