Exemple #1
10
  public void render() {
    Graphics g = screen.getGraphics();
    // Drawing Things!
    sky.render(g);
    level.render(
        g,
        (int) sX,
        (int) sY,
        (pixel.width / Tile.tileSize) + 2,
        (pixel.height / Tile.tileSize) + 2);
    character.render(g);
    inventory.render(g);
    health.render(g);

    for (int i = 0; i < mob.toArray().length; i++) {
      mob.get(i).render(g);
    }
    g = getGraphics();

    g.drawImage(screen, 0, 0, size.width, size.height, 0, 0, pixel.width, pixel.height, null);

    g.dispose();
  }
 public void moveLayerThree(Graphics g) {
   backy += (int) (player1.getVelocity() * 0.1);
   midy += (int) (player1.getVelocity() * 0.5);
   drawEnemy(g);
   drawCoin(g);
   drawBox(g);
   drawPoof(g);
   drawStar(g);
   drawJumper(g);
   drawSpike(g);
   drawPup(g);
   if (backy <= dieHeight) {
     // System.out.println(die);
     g.drawImage(player1.move(2), player1.getX(), player1.getY(), this);
     if (player1.animationComplete()) {
       die = true;
     }
   } else {
     if (backy <= dieHeight) {
       player1.resetCounter();
     }
     if (keys[KeyEvent.VK_RIGHT]) {
       g.drawImage(player1.move(1), player1.getX(), player1.getY(), this);
     } else if (keys[KeyEvent.VK_LEFT]) {
       g.drawImage(player1.move(-1), player1.getX(), player1.getY(), this);
     } else {
       g.drawImage(player1.move(0), player1.getX(), player1.getY(), this);
     }
   }
 }
Exemple #3
0
  public void paint(Graphics g) {
    if (!gameComplete) {
      if (!initialPaintComplete) {
        g.setColor(Color.WHITE);
        g.fillRect(0, 0, MaxX, MaxY);
        initialPaintComplete = true;
      }

      Graphics blockGraphics = blockBuffer.getGraphics();
      Graphics padGraphics = padBuffer.getGraphics();
      Graphics ballGraphics = ballBuffer.getGraphics();
      Graphics ballPreviousGraphics = ballBufferPrevious.getGraphics();

      ballPreviousGraphics.setColor(Color.WHITE);
      ballPreviousGraphics.fillRect(0, 0, ballDiameter, ballDiameter);
      g.drawImage(ballBufferPrevious, ballPreviousX, ballPreviousY, null);

      ballGraphics.setColor(Color.BLUE);
      ballGraphics.fillOval(0, 0, ballDiameter, ballDiameter); // whole line white
      g.drawImage(ballBuffer, ballX, ballY, null);

      ballGraphics.setColor(Color.RED);
      ballGraphics.fillOval(4, 4, ballDiameter - 8, ballDiameter - 8); // whole line white
      g.drawImage(ballBuffer, ballX, ballY, null);

      padGraphics.setColor(Color.WHITE);
      padGraphics.fillRect(0, 0, MaxX, blockHeight); // whole line white
      padGraphics.setColor(Color.BLACK);
      padLeft = padx - padLength / 2;

      if (padLeft >= 0 && padx + padLength / 2 < MaxX) {
        padGraphics.fillRoundRect(padLeft, 0, padLength, padHeight, padHeight, padHeight);
      }
      if (padLeft < 0) {
        padGraphics.fillRoundRect(0, 0, padLength, padHeight, padHeight, padHeight);
      } else if (padx + padLength / 2 >= MaxX) {
        padGraphics.fillRoundRect(MaxX - padLength, 0, padLength, padHeight, padHeight, padHeight);
      }
      g.drawImage(padBuffer, 0, padTop, null);
      // g.drawString(msg, 50, 50);
      // Drawing Blocks

      Iterator<Entry<String, Color>> it = blockMap.entrySet().iterator();
      blockGraphics.setColor(Color.WHITE);
      blockGraphics.fillRect(0, 0, blockSetWidth, blockSetHeight); // whole line white
      while (it.hasNext()) {
        Map.Entry<String, Color> pairs = (Map.Entry<String, Color>) it.next();
        String coordinate = pairs.getKey();
        blockGraphics.setColor(pairs.getValue());
        blockGraphics.fillRect(
            new Pair(coordinate).first, new Pair(coordinate).second, blockLength, blockHeight);
      }
      if (repaintBlocks) {
        g.drawImage(blockBuffer, blockStartX, blockStartY, null);
        if (--count < 0) repaintBlocks = false;
      }
    }
  }
 public void gameOverMenu(
     Graphics g) { // CHANGE THIS TO INCLUDE HIGHSCORES AND STUFF AFTER TEXTFILES ARE MADE
   // Menu that shows up when user gets Game Over
   if (pause == true && die == true) {
     g.drawImage(
         new ImageIcon("InGameMenu/pauseBckgrnd.png").getImage(), 0, 0, this); // Graphics stuff
     g.setFont(scoreFont);
     g.setColor(Color.BLACK);
     g.drawImage(new ImageIcon("InGameMenu/GameOver.png").getImage(), 10, 200, this);
     displayScore2(g, 115, 350, 185, 385, 110, 440, 110, 490); // Shows stats
     g.drawImage(menuB.getPic(mx, my), menuB.getX(), menuB.getY(), this); // Draws menu button
   }
 }
 public void lvlClearMenu(Graphics g) {
   // Menu that shows up after a level has been cleared
   if (pause == true && lvlClear == true) {
     g.drawImage(
         new ImageIcon("InGameMenu/pauseBckgrnd.png").getImage(), 0, 0, this); // <Graphics stuff
     g.drawImage(new ImageIcon("InGameMenu/stageClearPic.png").getImage(), 100, 0, this);
     displayScore2(g, 115, 350, 185, 380, 110, 440, 110, 490); // Displays stats
     g.drawImage(
         resumeB.getPic(mx, my), resumeB.getX(), resumeB.getY(), this); // Draws resume button
     g.drawImage(
         menuB.getPic(mx, my), menuB.getX(), menuB.getY(), this); // Draws the back to menu button
   }
 }
Exemple #6
0
  public void mouseWheelMoved(MouseWheelEvent event) {

    int zoom = event.getWheelRotation();

    mx = event.getX();
    my = event.getY();

    showStatus("Mouse rotated (" + zoom + ")");

    // zoom out
    if (zoom >= 0) {
      dbg.setColor(Color.black);
      //			dbg.drawImage (background, SIZE/2-current_size/2,
      //			        SIZE/2-current_size/2, current_size, current_size, this);
    }
    // zoom in
    else if (zoom < 0) {
      int width = building.getWidth(this);
      int height = building.getHeight(this);
      dbg.drawImage(
          building, width, height, width / 2, height / 2, width, height, width, height, this);
    }

    repaint();
    event.consume();
  }
Exemple #7
0
  /** Paint it. */
  public void paint(Graphics g) {
    Dimension d = getSize();
    if (!inited || buff == null || d.width != buffSize.width || d.height != buffSize.height) {
      buffSize.width = d.width;
      buffSize.height = d.height;
      buff = createImage(d.width + 4, d.height + 4);
      if (buff == null) return;
      buffG = buff.getGraphics();
      inited = true;
    }

    buffG.setColor(Color.lightGray);
    buffG.fillRect(0, 0, prefSize.width, prefSize.height);
    PressedRect(buffG, 0, 0, prefSize.width - 2, prefSize.height - 2);

    buffG.setColor(Color.lightGray);
    buffG.fillRect(0, 0, prefSize.width + 2, prefSize.height + 2);
    if (!gameover) if ((gameover = is_game_over())) end_game();
    for (int i = 0; i < rows; i++) {
      for (int j = 0; j < cols; j++) {
        drawBlock(buffG, i, j, status(i, j));
      }
    }
    // PressedRect(buffG,0,0,prefSize.width + 2,prefSize.height + 2);
    if (buff != null) g.drawImage(buff, 0, 0, null);
  }
 public void moveLayerOne(
     Graphics g) { // drawing the background, we have to make this into percentage afterwards
   g.drawImage(
       gameBckgrnd,
       0,
       (((int) (backy * 0.1)) % 23080) - 23080,
       this); // makes it continues and i have an extra image on top just to be safe
 }
 public void drawStar(Graphics g) {
   // draws the stars
   for (Star i : starList) {
     g.drawImage(
         i.getPics().get(i.getCounter()), i.getX(), i.getY(), i.getWidth(), i.getHeight(), null);
     i.count();
   }
 }
 public synchronized void paintIcon(Component c, Graphics g, int x, int y) {
   g.setColor(Color.white);
   g.fillRect(0, 0, c.getWidth(), c.getHeight());
   if (getImageObserver() == null) {
     g.drawImage(
         getImage(),
         c.getWidth() / 2 - getIconWidth() / 2,
         c.getHeight() / 2 - getIconHeight() / 2,
         c);
   } else {
     g.drawImage(
         getImage(),
         c.getWidth() / 2 - getIconWidth() / 2,
         c.getHeight() / 2 - getIconHeight() / 2,
         getImageObserver());
   }
 }
 /* applet paint event. Called by update and whenever applet needs to e be updated. */
 public void paint(Graphics g) {
   /*		g.drawString("Sandy's Sunflowers",220,30);
   		g.drawString("Arrow keys to move",220,50);
   		g.drawString("Space to water", 220, 70);
   		g.drawString("Return to plant", 220, 90);
   */
   g.drawImage(backbuffer, 0, 0, this);
 }
Exemple #12
0
  /**
   * Draw a ball at screen coordinate (x, y) with a ball index `id' (0, 0) represents the top-left
   * corner `x', `y', `radius' are given in pixels the ball index (gray code) `id' can be 0 to 15
   */
  void paint(Graphics gc, int x, int y, int id, double radius) {
    if (balls == null) makeBalls();
    Image img = balls[id]; // id = [0..15]

    int size = (int) (radius * 2 + .5);
    gc.drawImage(img, x - size / 2, y - size / 2, size, size, null);
    // System.out.println("" + x + " " + y + " " + id + " " + radius);
  }
 public void displayScore2(
     Graphics g, int cx, int cy, int sx1, int sy1, int sx2, int sy2, int sx3, int sy3) {
   g.setFont(scoreFont);
   g.setColor(Color.WHITE);
   g.drawImage(new ImageIcon("InGameMenu/coin.png").getImage(), cx, cy, this);
   g.drawString("" + coins, sx1, sy1);
   g.drawString("Score:  " + score, sx2, sy2);
   g.drawString("Height:  " + height + " m", sx3, sy3);
 }
Exemple #14
0
  public void mouseMoved(MouseEvent e) {
    mx = e.getX();
    my = e.getY();
    showStatus("Mouse at (" + mx + "," + my + ")");

    //	      update background
    dbg.drawImage(background, 0, 0, this);

    // draw the choosen building

    my = my - (int) (building.getHeight(null)) / 2;
    mx = mx - (int) (building.getWidth(null)) / 2;

    dbg.drawImage(building, mx, my, this);

    repaint();
    e.consume();
  }
 // -------------------------------------------------------------------------------------------------------------------------------------------------------
 // Drawing
 public void drawCoin(Graphics g) {
   // draws the coins
   for (Coin i : coinList) {
     g.drawImage(
         i.getPics().get(i.getCounter()), i.getX(), i.getY(), i.getWidth(), i.getHeight(), null);
     i.count();
     i.setDirection();
   }
 }
 public void squish(Graphics g, ImageIcon icon, int x, int y, double scale) {
   if (isVisible()) {
     g.drawImage(
         icon.getImage(),
         x,
         y,
         (int) (icon.getIconWidth() * scale),
         (int) (icon.getIconHeight() * scale),
         this);
   }
 }
 public void update(Graphics g) {
   Graphics gr;
   if (offScreenBuffer == null
       || (!(offScreenBuffer.getWidth(this) == this.size().width
           && offScreenBuffer.getHeight(this) == this.size().height))) {
     offScreenBuffer = this.createImage(size().width, size().height);
   }
   gr = offScreenBuffer.getGraphics();
   paint(gr);
   g.drawImage(offScreenBuffer, 0, 0, this);
 }
  /** Paint it. */
  public void paint(Graphics g) {
    Dimension d = getSize();
    g.setColor(Color.black);
    int xoff = d.width / 3;
    int yoff = d.height / 3;
    g.drawLine(xoff, 0, xoff, d.height);
    g.drawLine(2 * xoff, 0, 2 * xoff, d.height);
    g.drawLine(0, yoff, d.width, yoff);
    g.drawLine(0, 2 * yoff, d.width, 2 * yoff);

    int i = 0;
    for (int r = 0; r < 3; r++) {
      for (int c = 0; c < 3; c++, i++) {
        if ((white & (1 << i)) != 0) {
          g.drawImage(notImage, c * xoff + 1, r * yoff + 1, this);
        } else if ((black & (1 << i)) != 0) {
          g.drawImage(crossImage, c * xoff + 1, r * yoff + 1, this);
        }
      }
    }
  }
  // ------------------------------------------------------------------------------------------------------------------------------------
  // In game menus
  public void pauseMenu(Graphics g) {
    // Pause menu
    if (pause == true && lvlClear == false) {
      g.setFont(scoreFont);
      g.setColor(Color.BLACK);
      g.drawImage(new ImageIcon("InGameMenu/pauseBckgrnd.png").getImage(), 0, 0, this);
      g.drawString("P A U S E D", 155, 200);
      displayScore2(g, 115, 350, 185, 380, 110, 440, 110, 490); // Displays stats
      g.drawImage(
          resumeB.getPic(mx, my), resumeB.getX(), resumeB.getY(), this); // Draws the resume button
      g.drawImage(
          menuB.getPic(mx, my), menuB.getX(), menuB.getY(), this); // Draws the back to menu button

      if (musicOn == true) { // Draws the mute or unmute button (based on if music is on or not)
        g.drawImage(muteB.getPic(mx, my), muteB.getX(), muteB.getY(), this);
      }
      if (musicOn == false) {
        g.drawImage(unmuteB.getPic(mx, my), unmuteB.getX(), unmuteB.getY(), this);
      }
    }
  }
Exemple #20
0
  public void paint(Graphics g) {

    g.setColor(Color.white); // Background flushing
    g.fillRect(0, 0, 800, 800);

    g.setColor(Color.red);
    for (Target a : targets) // Target painting
    {
      if (a.getImageType() == "clay_pigeon.gif")
        g.drawImage(target1, a.getX(), a.getY(), a.getSize(), a.getSize(), this);
      if (a.getImageType() == "Disc1.gif")
        g.drawImage(target2, a.getX(), a.getY(), a.getSize(), a.getSize(), this);
    }

    //    	g.setColor(Color.red);
    //    	for(int i = 0; i < regions.size(); i++) // Region painting
    //    	{
    //    		g.fillRect(regions.get(i).getX(), regions.get(i).getY(), regions.get(i).getW(),
    // regions.get(i).getH());
    //    	}

  }
Exemple #21
0
  // draws the current snapshot
  public void paintComponent(Graphics g) {

    // System.out.println("In paint in draw");
    super.paintComponent(g);
    my_width = getSize().width;
    my_height = getSize().height;
    if (my_image != null) g.drawImage(my_image, 0, 0, my_width, my_height, this);

    setBackground(new Color(1.0f, 1.0f, 1.0f));
    //         g.setColor(Color.black);
    //         g.drawRect(0,0,my_width-1,my_height-1);

  }
 public void drawPowerUpEffect(Graphics g) {
   if (player1.getPower().equals("Magnet")) {
     Image magpic = magnetList.get((int) count % 6);
     g.drawImage(
         magpic,
         player1.getX() - ((magpic.getWidth(null) - player1.getWidth()) / 2),
         player1.getY() - ((magpic.getHeight(null) - player1.getHeight()) / 2),
         magpic.getWidth(null),
         magpic.getHeight(null),
         this);
     count += 0.1;
   } else if (player1.getPower().equals("Ball")) {
     g.drawImage(
         ballPower,
         player1.getX() - ballPower.getWidth(null) / 2 + 17,
         player1.getY() + player1.getHeight() - 20,
         ballPower.getWidth(null),
         ballPower.getHeight(null),
         this);
   } else if (player1.getPower().equals("Sheild")) {
     g.drawImage(
         sheildPower,
         player1.getX() - ((sheildPower.getWidth(null) - player1.getWidth()) / 2),
         player1.getY() - ((sheildPower.getHeight(null) - player1.getHeight()) / 2),
         sheildPower.getWidth(null),
         sheildPower.getHeight(null),
         this);
   } else if (player1.getPower().equals("Umbrella")) {
     g.drawImage(
         umbrellaPower,
         player1.getX() - (umbrellaPower.getWidth(null) / 2) + 20,
         player1.getY() - umbrellaPower.getHeight(null) + 40,
         umbrellaPower.getWidth(null),
         umbrellaPower.getHeight(null),
         this);
   } else if (player1.getPower().equals("")) {
   }
 }
Exemple #23
0
 protected void paintComponent(Graphics g) {
   super.paintComponent(g);
   if (model != null) {
     newImgBuf(); // refresh the image buffer if necessary
     // compute the real-to-screen ratio, this variable differs
     // from model.real2Screen by zoomScale
     Dimension sz = getSize();
     double real2Screen0 = model.getScaleFromSpan(realSpan, sz.width, sz.height);
     model.setMatrix(viewMatrix, real2Screen0 * zoomScale, sz.width / 2, sz.height / 2);
     imgG.setColor(Color.BLACK);
     imgG.fillRect(0, 0, sz.width, sz.height);
     model.paint(imgG);
     g.drawImage(img, 0, 0, this);
   }
 }
Exemple #24
0
  public void paint(Graphics g) {
    if (offg == null) {
      initScreen();
      // initObjects();
      return;
    }

    // offg.setColor(getBackground());
    offg.setColor(new Color(128, 0, 0));
    offg.fillRect(0, 0, getWidth(), getHeight());

    // IGCore.paint(offg);

    g.drawImage(offscreen, 0, 0, getWidth(), getHeight(), this);
  }
 /** Update - Method, implements double buffering */
 public void update(Graphics g) {
   // initialize buffer
   if (dbImage == null) {
     dbImage = createImage(this.getSize().width, this.getSize().height);
     dbg = dbImage.getGraphics();
   }
   // clear screen in background
   dbg.setColor(getBackground());
   dbg.fillRect(0, 0, this.getSize().width, this.getSize().height);
   // draw elements in background
   dbg.setColor(getForeground());
   paint(dbg);
   // draw image on the screen
   g.drawImage(dbImage, 0, 0, this);
 }
 public void moveLayerTwo(Graphics g) { // making it look fancy and shit
   Graphics2D g2d = (Graphics2D) g;
   for (Decorations i : decoList) {
     if (i.isFlipped() == true) { // if its flipped then flip the image or don't
       g2d.drawImage(
           i.getImage(),
           479,
           i.getYTop(),
           -i.getImage().getWidth(null),
           i.getImage().getHeight(null),
           null);
     } else {
       g.drawImage(i.getImage(), 0, i.getYTop(), this);
     }
   }
 }
Exemple #27
0
    public void draw(Graphics g, ImageObserver ob) {
      if (!todraw) {
        g.setColor(bgcolor);
        g.drawRect(x, y, w + 2 * border, h + 2 * border);
        g.fillRect(x, y, w + 2 * border, h + 2 * border);
        return;
      }

      if (selected) g.setColor(selected_color);
      else g.setColor(unselected_color);

      g.drawRect(x, y, w + 2 * border, h + 2 * border);
      g.fillRect(x, y, w + 2 * border, h + 2 * border);
      g.drawImage(image[im], x + border, y + border, ob);

      // g.setColor(Color.black);
      // g.drawString("" + im,x+5,y+5);
    }
Exemple #28
0
 /** Update - Methode, Realisierung der Doppelpufferung zur Reduzierung des Bildschirmflackerns */
 public void update(Graphics g) {
   // Initialize double buffer with background image
   //		if (dbImage == null)
   //		{
   //			dbImage = createImage (this.getSize().width, this.getSize().height);
   //			dbg = dbImage.getGraphics ();
   //		}
   //
   //		// set background
   //		//dbg.setColor (getBackground ());
   //		//dbg.fillRect (0, 0, this.getSize().width, this.getSize().height);
   //
   //		// set foreground
   //		dbg.setColor (getForeground());
   //		paint (dbg);
   //
   //		// draw buffer images
   g.drawImage(dbImage, 0, 0, this);
 }
 public void drawEnemy(Graphics g) {
   Graphics2D g2d = (Graphics2D) g;
   for (Enemy i : enemyList) {
     if (i.getFlip()) {
       g2d.drawImage(
           i.getPics().get(i.getCounter()),
           i.getX() + i.getWidth(),
           i.getY(),
           -i.getWidth(),
           i.getHeight(),
           null); // flips the image if the flip is true
     } else {
       g.drawImage(
           i.getPics().get(i.getCounter()), i.getX(), i.getY(), i.getWidth(), i.getHeight(), null);
     }
     i.count();
     i.setDirection();
     i.move();
   }
 }
Exemple #30
0
  public void update(Graphics g) {
    Dimension d = size();
    if (d.width < 1 || d.height < 1) return;

    if ((offscreen == null)
        || (d.width != offscreensize.width)
        || (d.height != offscreensize.height)) {
      offscreen = createImage(d.width, d.height);
      offscreensize = d;
      offGraphics = offscreen.getGraphics();
    }

    offGraphics.setColor(getBackground());
    offGraphics.fillRect(0, 0, d.width, d.height);
    Font font = new Font("Dialog", Font.PLAIN, 10);
    offGraphics.setFont(font);
    fm = offGraphics.getFontMetrics();
    paint(offGraphics);
    g.drawImage(offscreen, 0, 0, null);
  }