Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.joetannoury.game;
- import org.lwjgl.LWJGLException;
- import org.lwjgl.Sys;
- import org.lwjgl.opengl.Display;
- import org.lwjgl.opengl.DisplayMode;
- import org.lwjgl.opengl.GL11;
- public class Game {
- /** Size of the window */
- public static int WIDTH = 1000, HEIGHT = (int) (WIDTH*0.6);
- /** time at last frame */
- long lastFrame;
- /** frames per second */
- int fps;
- /** last fps time */
- long lastFPS;
- public void start() {
- try {
- Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT));
- Display.setTitle("WreckCurve");
- Display.create();
- } catch (LWJGLException e) {
- e.printStackTrace();
- System.exit(0);
- }
- initGL(); // init OpenGL
- getDelta(); // call once before loop to initialise lastFrame
- lastFPS = getTime(); // call before loop to initialise fps timer
- while (!Display.isCloseRequested()) {
- update(getDelta());
- renderGL();
- Display.update();
- Display.sync(60); // cap the fps to 60fps
- }
- Display.destroy();
- }
- public void update(int delta) {
- new Update(delta);
- updateFPS(); // update FPS Counter
- }
- /**
- * Calculate how many milliseconds have passed
- * since last frame.
- *
- * @return milliseconds passed since last frame
- */
- public int getDelta() {
- long time = getTime();
- int delta = (int) (time - lastFrame);
- lastFrame = time;
- return delta;
- }
- /**
- * Get the accurate system time
- *
- * @return The system time in milliseconds
- */
- public long getTime() {
- return (Sys.getTime() * 1000) / Sys.getTimerResolution();
- }
- /**
- * Calculate the FPS
- */
- public void updateFPS() {
- if (getTime() - lastFPS > 1000) {
- //Display.setTitle("FPS: " + fps);
- fps = 0;
- lastFPS += 1000;
- }
- fps++;
- }
- public void initGL() {
- GL11.glMatrixMode(GL11.GL_PROJECTION);
- GL11.glLoadIdentity();
- GL11.glOrtho(0, WIDTH, 0, HEIGHT, 1, -1);
- GL11.glMatrixMode(GL11.GL_MODELVIEW);
- }
- public void renderGL() {
- new Render();
- }
- public static void main(String[] argv) {
- Game game = new Game();
- game.start();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement