Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.anim8.engine;
- /*
- * public static int windowWidth = 427;
- public static int windowHeight = 640;
- public static String gameName = "Burch-A-Gotchi";
- gameState.render();
- */
- 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 main {
- public enum State {
- OPENING_CREDITS, MAIN_MENU, GAME,
- }
- private static State state = State.GAME;
- public static int windowWidth = 427;
- public static int windowHeight = 640;
- public static String gameName = "Burch-A-Gotchi";
- /** time at last frame */
- long lastFrame;
- /** frames per second */
- int fps;
- /** last fps time */
- long lastFPS;
- public void start() {
- try {
- Display.setDisplayMode(new DisplayMode(windowWidth, windowHeight));
- 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()) {
- int delta = getDelta();
- switch(state){
- case OPENING_CREDITS:
- break;
- case MAIN_MENU:
- break;
- case GAME:
- gameState.render();
- break;
- }
- update();
- glFlush();
- Display.update();
- Display.sync(60); // cap fps to 60fps
- }
- Display.destroy();
- }
- private void glFlush() {
- // TODO Auto-generated method stub
- }
- public void update() {
- 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 and set it in the title bar
- */
- public void updateFPS() {
- if (getTime() - lastFPS > 1000) {
- Display.setTitle(gameName + " | FPS: " + fps);
- fps = 0;
- lastFPS += 1000;
- }
- fps++;
- }
- public void initGL() {
- GL11.glMatrixMode(GL11.GL_PROJECTION);
- GL11.glLoadIdentity();
- GL11.glOrtho(0, windowWidth, windowHeight, 0, 1, -1);
- GL11.glMatrixMode(GL11.GL_MODELVIEW);
- GL11.glEnable(GL11.GL_TEXTURE_2D);
- GL11.glEnable(GL11.GL_BLEND);
- GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
- }
- public static void main(String[] argv) {
- main main = new main();
- main.start();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement