SHARE
TWEET

Untitled

a guest May 25th, 2019 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.awt.Color;
  2. import java.awt.Graphics;
  3. import java.awt.Point;
  4.  
  5. import javax.swing.JPanel;
  6.  
  7. @SuppressWarnings("serial")
  8. public class RenderPanel extends JPanel
  9. {
  10.  
  11.     public static final Color GREEN = new Color(1666073);
  12.  
  13.     @Override
  14.     protected void paintComponent(Graphics g)
  15.     {
  16.         super.paintComponent(g);
  17.        
  18.         Snake snake = Snake.snake;
  19.  
  20.         g.setColor(GREEN);
  21.        
  22.         g.fillRect(0, 0, 800, 700);
  23.  
  24.         g.setColor(Color.BLUE);
  25.  
  26.         for (Point point : snake.snakeParts)
  27.         {
  28.             g.fillRect(point.x * Snake.SCALE, point.y * Snake.SCALE, Snake.SCALE, Snake.SCALE);
  29.         }
  30.        
  31.         g.fillRect(snake.head.x * Snake.SCALE, snake.head.y * Snake.SCALE, Snake.SCALE, Snake.SCALE);
  32.        
  33.         g.setColor(Color.RED);
  34.        
  35.         g.fillRect(snake.cherry.x * Snake.SCALE, snake.cherry.y * Snake.SCALE, Snake.SCALE, Snake.SCALE);
  36.        
  37.         String string = "Score: " + snake.score + ", Length: " + snake.tailLength + ", Time: " + snake.time / 20;
  38.        
  39.         g.setColor(Color.white);
  40.        
  41.         g.drawString(string, (int) (getWidth() / 2 - string.length() * 2.5f), 10);
  42.  
  43.         string = "Game Over!";
  44.  
  45.         if (snake.over)
  46.         {
  47.             g.drawString(string, (int) (getWidth() / 2 - string.length() * 2.5f), (int) snake.dim.getHeight() / 4);
  48.         }
  49.  
  50.         string = "Paused!";
  51.  
  52.         if (snake.paused && !snake.over)
  53.         {
  54.             g.drawString(string, (int) (getWidth() / 2 - string.length() * 2.5f), (int) snake.dim.getHeight() / 4);
  55.         }
  56.     }
  57. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top