Advertisement
juliand665

Metamorph.java

Jan 19th, 2014
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.68 KB | None | 0 0
  1. package src;
  2.  
  3. import static org.lwjgl.opengl.GL11.*;
  4.  
  5. import java.awt.GraphicsDevice;
  6. import java.awt.GraphicsEnvironment;
  7. import java.awt.Toolkit;
  8. import java.awt.event.KeyEvent;
  9. import java.awt.event.MouseEvent;
  10. import java.awt.event.WindowEvent;
  11.  
  12. import javax.swing.JFrame;
  13. import javax.swing.JPanel;
  14.  
  15. import org.lwjgl.LWJGLException;
  16. import org.lwjgl.input.Keyboard;
  17. import org.lwjgl.input.Mouse;
  18. import org.lwjgl.opengl.Display;
  19. import org.lwjgl.opengl.DisplayMode;
  20.  
  21. public class Metamorph
  22. {
  23.    
  24.     public static Metamorph instance;
  25.     public static Art art;
  26.     public static SoundEngine sound;
  27.     public static Renderer renderer;
  28.     public EnumScreens currentScreen;
  29.     public static Game game;
  30.  
  31.     public Metamorph()
  32.     {
  33.         super();
  34.        
  35.         initMM();
  36.         initGL();
  37.        
  38.         mainLoop();
  39.        
  40.         cleanUp();
  41.     }
  42.    
  43.     public void initMM()
  44.     {
  45.         art = new Art();
  46.         sound = new SoundEngine();
  47.         renderer = new Renderer(art);
  48.         instance = this;
  49.        
  50.         try
  51.         {
  52.             Display.setDisplayMode(new DisplayMode(1280,720));
  53.             Display.create();
  54.             Mouse.create();
  55.             Keyboard.create();
  56.             Display.setTitle("Metamorph");
  57.             Display.setVSyncEnabled(true);
  58.         } catch (LWJGLException e)
  59.         {
  60.             e.printStackTrace();
  61.         }
  62.  
  63.         currentScreen = EnumScreens.MAIN;
  64.     }
  65.  
  66.     public static void initGL()
  67.     {
  68.         glMatrixMode(GL_PROJECTION);
  69.         glLoadIdentity();
  70.         glOrtho(0, Display.getWidth(), 0, Display.getHeight(), 1, -1);
  71.         glEnable(GL_BLEND);
  72.         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  73.         glMatrixMode(GL_MODELVIEW);
  74.         glClearColor(0, 0, 0, 1);
  75.         glDisable(GL_DEPTH_TEST);
  76.     }
  77.    
  78.     public void mainLoop()
  79.     {
  80.         while(!Display.isCloseRequested())
  81.         {
  82.             handleInput();
  83.  
  84.             tick();
  85.            
  86.             render();
  87.         }
  88.     }
  89.    
  90.     public void render()
  91.     {
  92.         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  93.  
  94.         glLoadIdentity();
  95.         glScalef(1.0f, -1.0f, 1.0f);
  96.         glTranslatef(0f, -720f, 0f);
  97.         //glScalef(1280f/800, 720f/500, 1f);
  98.  
  99.         renderer.render();
  100.  
  101.         Display.update();
  102.         Display.sync(60);
  103.     }
  104.    
  105.     public void tick()
  106.     {
  107.         if(game != null)
  108.             game.world.tick();
  109.     }
  110.  
  111.     public static void cleanUp()
  112.     {
  113.         Display.destroy();
  114.     }
  115.  
  116.     public static void main(String[] args)
  117.     {
  118.         instance = new Metamorph();
  119.     }
  120.  
  121.     public void initGame()
  122.     {
  123.         game = new Game();
  124.         game.init();
  125.     }
  126.  
  127.     public void handleInput()
  128.     {
  129.         if(Mouse.isButtonDown(0))
  130.         {
  131.             System.out.println(Mouse.getX() + " " + Mouse.getY());
  132.             int sel = -1;
  133.             if(Mouse.getX() > 1000 && Mouse.getX() < 1240 && Mouse.getY() > 320 && Mouse.getY() < 700)
  134.                 sel = Math.round((Mouse.getY() - 357.5F)/75F);
  135.             if(sel == 0)
  136.             {
  137.                 currentScreen = EnumScreens.GAME;
  138.                 initGame();
  139.             }
  140.             if(sel == 4)
  141.             {
  142.                 cleanUp();
  143.             }
  144.         }
  145.     }
  146.  
  147. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement