Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2009
508
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.80 KB | None | 0 0
  1. public void render()
  2.     {
  3.         //System.out.printf("Width: %d Height: %d\n", getWidth(), getHeight());
  4.  
  5.         if (strategy == null || strategy.contentsLost())
  6.         {
  7.             // Create BufferStrategy for rendering/drawing
  8.             createBufferStrategy(2);
  9.             strategy = getBufferStrategy();
  10.             Graphics g = strategy.getDrawGraphics();
  11.             this.g2 = (Graphics2D) g;
  12.         }
  13.  
  14.  
  15.         // Turn on anti-aliasing
  16.         this.g2.setRenderingHint (RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  17.  
  18.  
  19.  
  20.         // Render Background
  21.         this.g2.setColor(Color.BLACK);
  22.         this.g2.fillRect(0, 0, getWidth(), getHeight());
  23.  
  24.         // Render Game Objects
  25.         for(int i = 0; i < ballCount; i++)
  26.         {
  27.             balls[i].draw(this.g2);
  28.         }
  29.  
  30.         Ball tempBall = currentBall;
  31.         if (tempBall != null) tempBall.draw(this.g2);
  32.  
  33.  
  34.         // Render Foreground (text, etc)
  35.  
  36.         // Draw Power Arrow and Speed Text along arrow if we are launching a ball
  37.         Arrow tempArrow = powerArrow;
  38.         if (tempArrow != null)
  39.         {
  40.             tempArrow.draw(this.g2);
  41.  
  42.             // Power Arrow Magnitude Text
  43.             this.g2.setColor(Color.WHITE);
  44.             this.g2.drawString(String.format("%.2f px/s", tempArrow.getLength() * arrowScale, 2), (tempArrow.getX2() + tempArrow.getX1())/2, (tempArrow.getY1() + tempArrow.getY2())/2);
  45.         }
  46.  
  47.         // Display Help Text in center if no balls
  48.         if (ballCount == 0 && currentBall == null)
  49.         {
  50.             String helpString = "Click and drag your mouse to launch a ball.";
  51.             this.g2.setColor(Color.WHITE);
  52.             this.g2.drawString(helpString,  getWidth()/2 - (this.g2.getFontMetrics().stringWidth(helpString)/2), getHeight()/2);
  53.         }
  54.  
  55.         // Draw our framerate and ball count
  56.         this.g2.setColor(Color.WHITE);
  57.         this.g2.drawString("FPS: " + currentFrameRate + " Balls: "  + ballCount, 15, 15);
  58.  
  59.  
  60.         if (!strategy.contentsLost()) strategy.show();
  61.  
  62.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement