Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void render()
- {
- //System.out.printf("Width: %d Height: %d\n", getWidth(), getHeight());
- if (strategy == null || strategy.contentsLost())
- {
- // Create BufferStrategy for rendering/drawing
- createBufferStrategy(2);
- strategy = getBufferStrategy();
- Graphics g = strategy.getDrawGraphics();
- this.g2 = (Graphics2D) g;
- }
- // Turn on anti-aliasing
- this.g2.setRenderingHint (RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
- // Render Background
- this.g2.setColor(Color.BLACK);
- this.g2.fillRect(0, 0, getWidth(), getHeight());
- // Render Game Objects
- for(int i = 0; i < ballCount; i++)
- {
- balls[i].draw(this.g2);
- }
- Ball tempBall = currentBall;
- if (tempBall != null) tempBall.draw(this.g2);
- // Render Foreground (text, etc)
- // Draw Power Arrow and Speed Text along arrow if we are launching a ball
- Arrow tempArrow = powerArrow;
- if (tempArrow != null)
- {
- tempArrow.draw(this.g2);
- // Power Arrow Magnitude Text
- this.g2.setColor(Color.WHITE);
- this.g2.drawString(String.format("%.2f px/s", tempArrow.getLength() * arrowScale, 2), (tempArrow.getX2() + tempArrow.getX1())/2, (tempArrow.getY1() + tempArrow.getY2())/2);
- }
- // Display Help Text in center if no balls
- if (ballCount == 0 && currentBall == null)
- {
- String helpString = "Click and drag your mouse to launch a ball.";
- this.g2.setColor(Color.WHITE);
- this.g2.drawString(helpString, getWidth()/2 - (this.g2.getFontMetrics().stringWidth(helpString)/2), getHeight()/2);
- }
- // Draw our framerate and ball count
- this.g2.setColor(Color.WHITE);
- this.g2.drawString("FPS: " + currentFrameRate + " Balls: " + ballCount, 15, 15);
- if (!strategy.contentsLost()) strategy.show();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement