Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (753)
Games in Android Showcase (228)
games submitted by our members
Games in WIP (842)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
  JavaGaming.org - Pastebin



Author: Ultroman (posted 2012-09-14 11:32:47, viewed 334 times)

1   2   3   4   5   6   7   8   9   10   11   12   13   14   15   16   17   18   19   20   21   22   23   24   25   26   27   28   29   30   31   32   33   34   35   36   37   38   39   40   41   42   43   44   45   46   47   48   49   50   51   52   53   54   55   56   57   58   59   60   61   62   63   64   65  
public void update(Graphics g)
   {
      //start off transforms at identity
      g2d.setTransform(identity);
      
      //erase the background
      g2d.setPaint(Color.BLACK);
      g2d.fillRect(0, 0, getSize().width, getSize().height);
      
      // You translate EVERYTHING that is drawn after this line, so it moves around the ship. Only the world should do that.
      // Also, instead of just casting to an int, I'd recommend doing (int)Math.round(-ship.getX() + (ScreenWidth / 2)) and
      // (int)Math.round(-ship.getY() + (ScreenHeight / 2)) instead, so you get less rounding errors, and smoother movement.
      g.translate(-(int)ship.getX() + ScreenWidth / 2, -(int)ship.getY() + ScreenHeight / 2);

      // Set Background IMG
      g2d.drawImage(bg, 0, 0, null);
      
      // Draw the game graphics first, so things wont fly on top of your HUD
      drawShip();
      drawBullets();
      drawAsteroids();

      // translate back before drawing your HUD, so it follows your ship. I'm not sure if you need to translate back the rest
      // of the screensize too. Probably...test it out.
      g.translate((int)ship.getX(), (int)ship.getY());

      // Calc FPS
      long currentTime = System.currentTimeMillis(); 
      if (currentTime > nextSecond)
      { 
         nextSecond += 1000; 
         frameInLastSecond = framesInCurrentSecond; 
         framesInCurrentSecond = 0; 
      } 
      framesInCurrentSecond++; 
       
      // FPS
      g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
      g2d.setColor(Color.WHITE);
      g2d.setFont(new Font("Arial", Font.PLAIN, 20));
      g2d.drawString(frameInLastSecond + " fps", 10, 30);
      g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
       
      //print some status information
      g2d.setFont(new Font("Arial", Font.PLAIN, 9));
      g2d.setColor(Color.LIGHT_GRAY);
      g2d.drawString("Ship: " + Math.round(ship.getX()) + "," + Math.round(ship.getY()) , 10, 60);
      g2d.drawString("Move angle: " + Math.round(ship.getMoveAngle())+90, 10, 70);
      g2d.drawString("Face angle: " + Math.round(ship.getFaceAngle()), 10, 80);
      g2d.drawString("Ship VelX: " + Math.round(ship.getVelX()), 10, 90);
      g2d.drawString("Ship VelY: " + Math.round(ship.getVelY()), 10, 100);
      g2d.drawString("Version: " + GameVersion, 10, 110);
      g2d.drawString("Asteroids: " + AsteroidsAlive, 10, 120);
      
      // Print Score
      g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
      g2d.setColor(Color.WHITE);
      g2d.setFont(new Font("Arial", Font.PLAIN, 20));
      g2d.drawString("Score: " + Score, 360, 30);
      
      
      // Repaint the applet window
      paint(g);
      
   }





Dump your java code here :



Special syntax:
  • To highlight a line (yellow background), prefix it with '@@'
  • To indicate that a line should be removed (red background), prefix it with '-'
  • To indicate that a line should be added (green background), prefix it with '+'
  • To post multiple snippets, seperate them by '~~~~'
  EOF
 
ivj94 (584 views)
2018-03-24 14:47:39

ivj94 (49 views)
2018-03-24 14:46:31

ivj94 (382 views)
2018-03-24 14:43:53

Solater (63 views)
2018-03-17 05:04:08

nelsongames (109 views)
2018-03-05 17:56:34

Gornova (159 views)
2018-03-02 22:15:33

buddyBro (703 views)
2018-02-28 16:59:18

buddyBro (92 views)
2018-02-28 16:45:17

xxMrPHDxx (493 views)
2017-12-31 17:17:51

xxMrPHDxx (733 views)
2017-12-31 17:15:51
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!