Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (732)
Games in Android Showcase (222)
games submitted by our members
Games in WIP (806)
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: buddyBro (posted 2017-04-05 03:38:00, viewed 595 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  
void begin() {
      int frame = 0;
      long beginTime = 0, endTime;
      while (true) {
         while (pause) {
            checkPause();
            wait(30);
         }

         painter.clear(); // painter is a custom class that extends JFrame

         // camera stuff
         camera.move(controller);
         camera.update(world.width, world.length, world.height);
         controller.setView(camera.angle, camera.orig(), camera.normal);

         // update everything (like move character, add particles, etc)
         world.update(terrain, controller);

         world.draw(painter, camera); // this calls painter.polygon a bunch of times to draw the scene on the canvas
         painter.repaint();
         checkPause();
         wait(10);
         endTime = System.nanoTime() + 1;
         if (endTime - beginTime > 1000000000L) {
            Painter.debugString[0] = "fps: " + frame + " ; paint surfaceCount: " + painter.surfaceCount + " ; paint drawCount: " + painter.drawCount;
            frame = 0;
            beginTime = endTime;
         }
         frame++;
      }
   }


1   2   3   4   5   6   7   8   9   10   11   12   13   14   15   16   17   18   19   20   21   22  
   Painter(int frameSize, int imageSize, Controller controller) {
      FRAME_SIZE = frameSize;
      IMAGE_SIZE = imageSize;
      canvasBuffer = new BufferedImage[BUFFER_COUNT];
      brushBuffer = new Graphics2D[BUFFER_COUNT];
      for (int i = 0; i < BUFFER_COUNT; i++) {
         canvasBuffer[i] = new BufferedImage(IMAGE_SIZE, IMAGE_SIZE, 1);
         brushBuffer[i] = (Graphics2D) canvasBuffer[i].getGraphics();
      }
      canvas = canvasBuffer[0];
      brush = brushBuffer[0];
      getContentPane().setSize(FRAME_SIZE, FRAME_SIZE);
      pack();
      borderSize = getHeight();
      setSize(FRAME_SIZE, FRAME_SIZE + borderSize);
      setLocationRelativeTo(null);
      addMouseListener(controller);
      addKeyListener(controller);
      addMouseMotionListener(controller);
      setDefaultCloseOperation(EXIT_ON_CLOSE);
      setVisible(true);
   }


1   2   3   4   5   6   7   8   9   10  
   void clear() {
      surfaceCount = 0;
      drawCount = 0;
      if (++buffer == BUFFER_COUNT)
         buffer = 0;
      canvas = canvasBuffer[buffer];
      brush = brushBuffer[buffer];
      brush.setBackground(Color.BLACK);
      brush.clearRect(0, 0, IMAGE_SIZE, IMAGE_SIZE);
   }


1   2   3   4   5   6   7   8   9   10   11  
   public void paint(Graphics graphics) {
      // these are just the debug strings printed at the top left corner
      brush.setColor(Color.WHITE);
      for (int i = 0; i < debugString.length; i++)
         brush.drawString(debugString[i], 25, 25 + 25 * i);
      for (int i = 0; i < outputString.length; i++)
         brush.drawString(outputString[i], 25, 650 + 25 * i);

      // draw from canvas to actual jframe
      graphics.drawImage(canvas, 0, borderSize, null);
   }


1   2   3   4   5   6   7   8   9   10   11   12   13   14   15   16   17   18  
   public void polygon(double[][] xy, double light, Color color, boolean frame) {
      if (xy != null) {
         surfaceCount++;
         for (int i = 0; i < xy[0].length; i++)
            if (xy[0][i] > -.5 && xy[0][i] < .5 && xy[1][i] < .5 && xy[1][i] > -.5) {
               drawCount++;
               int[][] xyScaled = Math3D.transform(xy, IMAGE_SIZE, IMAGE_SIZE / 2);
               if (frame) {
                  brush.setColor(Color.cyan);
                  brush.drawPolygon(xyScaled[0], xyScaled[1], xyScaled[0].length);
               } else {
                  setColor(light, color);
                  brush.fillPolygon(xyScaled[0], xyScaled[1], xyScaled[0].length);
               }
               return;
            }
      }
   }





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
 
Sralse (15 views)
2017-07-25 17:13:48

Archive (414 views)
2017-04-27 17:45:51

buddyBro (594 views)
2017-04-05 03:38:00

CopyableCougar4 (1057 views)
2017-03-24 15:39:42

theagentd (1088 views)
2017-03-24 15:32:08

Rule (1058 views)
2017-03-19 12:43:22

Rule (1044 views)
2017-03-19 12:42:17

Rule (1036 views)
2017-03-19 12:36:21

theagentd (1177 views)
2017-03-16 05:07:07

theagentd (1140 views)
2017-03-15 22:37:06
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

SF/X Libraries
by SkyAphid
2017-03-02 06:38:56

SF/X Libraries
by SkyAphid
2017-03-02 06:38:32

SF/X Libraries
by SkyAphid
2017-03-02 06:38:05

SF/X Libraries
by SkyAphid
2017-03-02 06:37:51
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!