Advertisement
Guest User

Main

a guest
Aug 5th, 2013
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.40 KB | None | 0 0
  1. package com.addictivescripts.bubbles;
  2.  
  3. import com.addictivescripts.bubbles.objects.gameobjects.GameObjectsContainer;
  4. import com.addictivescripts.bubbles.objects.gameobjects.bubbles.RegularBubble;
  5. import com.addictivescripts.bubbles.objects.gameobjects.bubbles.Size;
  6. import com.addictivescripts.bubbles.util.api.Point;
  7. import com.addictivescripts.bubbles.util.data.Constants;
  8. import org.lwjgl.LWJGLException;
  9. import org.lwjgl.input.Keyboard;
  10. import org.lwjgl.input.Mouse;
  11. import org.lwjgl.opengl.Display;
  12. import org.lwjgl.opengl.DisplayMode;
  13. import org.lwjgl.opengl.GL11;
  14.  
  15. /**
  16.  * Created with IntelliJ IDEA.
  17.  * User: Sharon
  18.  * Date: 8/4/13
  19.  * Time: 9:57 PM
  20.  * To change this template use File | Settings | File Templates.
  21.  */
  22.  
  23. public class Game {
  24.     private long lastFrame = getTime();
  25.  
  26.     public GameObjectsContainer objectsContainer;
  27.  
  28.     public static void main(String[] args) {
  29.         new Game();
  30.     }
  31.  
  32.     private Game() {
  33.         objectsContainer = new GameObjectsContainer();
  34.  
  35.         objectsContainer.addObject(new RegularBubble(this, new Point(200, 200), Size.FOUR, 4, 0));
  36.  
  37.         try {
  38.             Display.setDisplayMode(new DisplayMode(Constants.SIZE_WIDTH, Constants.SIZE_HEIGHT));
  39.             Display.setTitle("Bubbles Popper - by KliK");
  40.  
  41.             Display.create();
  42.         } catch (LWJGLException e) {
  43.             e.printStackTrace();
  44.         }
  45.  
  46.         initGL();
  47.  
  48.         while (!Display.isCloseRequested()) {
  49.             int delta = getDelta();
  50.             System.out.println(Mouse.getX() + " " + Mouse.getY());
  51.             GL11.glClearColor(0.8f, 0.8f, 0.8f, 1.0f);
  52.             GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
  53.  
  54.             if (Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) {
  55.                 break;
  56.             }
  57.  
  58.             objectsContainer.update(delta);
  59.             objectsContainer.draw();
  60.  
  61.             Display.update();
  62.             Display.sync(60);
  63.         }
  64.  
  65.         Display.destroy();
  66.     }
  67.  
  68.     public void initGL() {
  69.         GL11.glMatrixMode(GL11.GL_PROJECTION);
  70.         GL11.glLoadIdentity();
  71.         GL11.glOrtho(0, 800, 0, 600, 1, -1);
  72.         GL11.glMatrixMode(GL11.GL_MODELVIEW);
  73.     }
  74.  
  75.     public long getTime() {
  76.         return System.nanoTime() / 1_000_000;
  77.     }
  78.  
  79.     public int getDelta() {
  80.         long time = getTime();
  81.         int delta = (int) (time - lastFrame);
  82.         lastFrame = time;
  83.  
  84.         return delta;
  85.     }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement