Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.OGRage.test3d;
- import java.awt.Canvas;
- import java.awt.Graphics;
- import java.awt.image.BufferStrategy;
- import java.awt.image.BufferedImage;
- import java.awt.image.DataBufferInt;
- import javax.swing.JFrame;
- import com.OGRage.test3d.graphics.Render;
- import com.OGRage.test3d.graphics.Screen;
- public class Display extends Canvas implements Runnable {
- private static final long serialVersionUID = 1L;
- public static final int WIDTH = 800;
- public static final int HEIGHT = 600;
- public static final String TITLE = "Zombie Front Pre Alpha 0.01";
- private Thread thread;
- private Screen screen;
- private BufferedImage img;
- private boolean running = true;
- private Render render;
- private int[] pixels;
- public Display() {
- screen = new Screen(WIDTH, HEIGHT);
- img = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);
- pixels = ((DataBufferInt)img.getRaster().getDataBuffer()).getData();
- }
- private void start() {
- if (running)
- return;
- running = true;
- thread = new Thread(this);
- }
- @SuppressWarnings("unused")
- private void stop() {
- if (!running)
- return;
- try{
- thread.join();
- } catch (Exception e) {
- e.printStackTrace();
- System.exit(0);
- }
- }
- public void run() {
- while (running) {
- tick();
- render();
- }
- }
- private void tick() {
- }
- private void render() {
- BufferStrategy bs = this.getBufferStrategy();
- if (bs == null) {
- createBufferStrategy(3);
- System.out.println("Buffer created!");
- return;
- }
- for (int i = 0; i< WIDTH * HEIGHT; i++) {
- pixels[i] = screen.pixels[i];
- }
- Graphics g = bs.getDrawGraphics();
- screen.render();
- g.drawImage(img, 0, 0, WIDTH, HEIGHT, null);
- g.dispose();
- bs.show();
- }
- public static void main(String[] args) {
- Display game = new Display();
- JFrame Frame = new JFrame();
- Frame.setLocationRelativeTo(null);
- Frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- Frame.pack();
- Frame.add(game);
- Frame.setSize(WIDTH, HEIGHT);
- Frame.setTitle(TITLE);
- Frame.setLocationRelativeTo(null);
- Frame.setResizable(false);
- Frame.setVisible(true);
- System.out.println("hello you");
- game.start();
- }
- public Render getRender() {
- return render;
- }
- public void setRender(Render render) {
- this.render = render;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement