Advertisement
Guest User

Untitled

a guest
Apr 27th, 2015
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.36 KB | None | 0 0
  1. package com.OGRage.test3d;
  2.  
  3. import java.awt.Canvas;
  4. import java.awt.Graphics;
  5. import java.awt.image.BufferStrategy;
  6. import java.awt.image.BufferedImage;
  7. import java.awt.image.DataBufferInt;
  8.  
  9. import javax.swing.JFrame;
  10.  
  11. import com.OGRage.test3d.graphics.Render;
  12. import com.OGRage.test3d.graphics.Screen;
  13.  
  14. public class Display extends Canvas implements Runnable {
  15.     private static final long serialVersionUID = 1L;
  16.  
  17.     public static final int WIDTH = 800;
  18.     public static final int HEIGHT = 600;
  19.     public static final String TITLE = "Zombie Front Pre Alpha 0.01";
  20.  
  21.     private Thread thread;
  22.     private Screen screen;
  23.     private BufferedImage img;
  24.     private boolean running = true;
  25.     private Render render;
  26.     private int[] pixels;
  27.    
  28.     public Display() {
  29.         screen = new Screen(WIDTH, HEIGHT);
  30.         img = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);
  31.         pixels = ((DataBufferInt)img.getRaster().getDataBuffer()).getData();
  32.     }
  33.  
  34.    
  35.  
  36.     private void start() {
  37.         if (running)
  38.             return;
  39.         running = true;
  40.         thread = new Thread(this);
  41.  
  42.     }
  43.  
  44.     @SuppressWarnings("unused")
  45.     private void stop() {
  46.         if (!running)
  47.             return;
  48.         try{
  49.         thread.join();
  50.         } catch (Exception e) {
  51.             e.printStackTrace();
  52.             System.exit(0);
  53.         }
  54.     }
  55.  
  56.     public void run() {
  57.       while (running) {
  58.          tick();
  59.          render();
  60.       }
  61.     }
  62.  
  63.     private void tick() {
  64.        
  65.     }
  66.    
  67.    
  68.     private void render() {
  69.         BufferStrategy bs = this.getBufferStrategy();
  70.         if (bs == null) {
  71.             createBufferStrategy(3);
  72.             System.out.println("Buffer created!");
  73.             return;
  74.         }
  75.        
  76.         for (int i = 0; i< WIDTH * HEIGHT; i++) {
  77.             pixels[i] = screen.pixels[i];
  78.         }
  79.        
  80.         Graphics g = bs.getDrawGraphics();
  81.         screen.render();
  82.         g.drawImage(img, 0, 0, WIDTH, HEIGHT, null);
  83.         g.dispose();
  84.         bs.show();
  85.        
  86.        
  87.        
  88.        
  89.     }
  90.     public static void main(String[] args) {
  91.         Display game = new Display();
  92.         JFrame Frame = new JFrame();
  93.         Frame.setLocationRelativeTo(null);
  94.         Frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  95.         Frame.pack();
  96.         Frame.add(game);
  97.         Frame.setSize(WIDTH, HEIGHT);
  98.         Frame.setTitle(TITLE);
  99.         Frame.setLocationRelativeTo(null);
  100.         Frame.setResizable(false);
  101.         Frame.setVisible(true);
  102.        
  103.         System.out.println("hello you");
  104.        
  105.         game.start();
  106.     }
  107.  
  108.  
  109.  
  110.     public Render getRender() {
  111.         return render;
  112.     }
  113.  
  114.  
  115.  
  116.     public void setRender(Render render) {
  117.         this.render = render;
  118.     }
  119.  
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement