Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Game {
- private static final boolean resizable = true;
- private static volatile boolean running = true;
- private static final float zNear = 0.3f;
- private static final float zFar = 100f;
- private static final int gridSize = 10;
- private static final float tileSize = 0.20f;
- private static final boolean fullscreen = false;
- private static final boolean vsync = true;
- private static final boolean printFPS = true;
- private static final float ceilingHeight = 10;
- private static final float floorHeight = -1;
- private static final int fov = 80;
- private static int fps;
- private static long lastFPS;
- private static Timer timer;
- private static int delta;
- private static Random random;
- private static Player player;
- private static BasicLevel basicLevel;
- private static ArrayList<TriangleMob> triangleMob = new ArrayList<TriangleMob>();
- private static void updateFPS() {
- if (timer.getTime() - lastFPS > 1000) {
- if (printFPS) {
- System.out.println("FPS: " + fps);
- }
- fps = 0;
- lastFPS += 1000;
- }
- fps++;
- }
- public static void main(String[] args) {
- try {
- if (fullscreen) {
- Display.setDisplayModeAndFullscreen(Display.getDesktopDisplayMode());
- } else {
- Display.setResizable(resizable);
- Display.setDisplayMode(new DisplayMode(800, 600));
- }
- Display.setTitle("Minefront Pre-Alpha 0.02 LWJGL Port");
- Display.setVSyncEnabled(vsync);
- Display.create();
- } catch (LWJGLException ex) {
- ex.printStackTrace();
- Display.destroy();
- System.exit(1);
- }
- if (fullscreen) {
- Mouse.setGrabbed(true);
- } else {
- Mouse.setGrabbed(false);
- }
- if (!GLContext.getCapabilities().OpenGL11) {
- System.err.println("Your OpenGL version doesn't support the required functionality.");
- Display.destroy();
- System.exit(1);
- }
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluPerspective(fov, (float) Display.getWidth() / (float) Display.getHeight(), zNear, zFar);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glEnable(GL_DEPTH_TEST);
- glEnable(GL_TEXTURE_2D);
- glEnable(GL_BLEND);
- glEnable(GL_ALPHA_TEST);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
- glEnable(GL_CULL_FACE);
- glCullFace(GL_BACK);
- //Initialize Timer
- timer = new Timer();
- timer.getDelta();
- lastFPS = timer.getTime();
- random = new Random();
- //Initialize the BasicLevel
- basicLevel = new BasicLevel(gridSize, ceilingHeight, floorHeight, tileSize);
- //Initialize the Player
- player = new Player();
- triangleMob.add(new TriangleMob());
- while (running) {
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- delta = timer.getDelta();
- glLoadIdentity();
- glRotatef(player.getRotation().x, 1, 0, 0);
- glRotatef(player.getRotation().y, 0, 1, 0);
- glRotatef(player.getRotation().z, 0, 0, 1);
- glTranslatef(player.getPosition().x, player.getPosition().y, player.getPosition().z);
- logic();
- render();
- if (printFPS) {
- updateFPS();
- }
- Display.update();
- if (vsync) {
- Display.sync(60);
- }
- if (Display.isCloseRequested()) {
- running = false;
- }
- }
- Display.destroy();
- System.exit(0);
- }
- private static void logic() {
- player.move(delta);
- for(int i=0; i<triangleMob.size();i++) {
- triangleMob.get(i).move(new Vector3f(0f,0f,0f));
- }
- if(Keyboard.isKeyDown(Keyboard.KEY_C)) {
- triangleMob.add(new TriangleMob(new Vector3f(50*random.nextFloat(),50*random.nextFloat(),50*random.nextFloat())));
- }
- System.out.println(TriangleMob.getCount());
- }
- private static void render() {
- basicLevel.render();
- for(int i=0; i<triangleMob.size();i++) {
- triangleMob.get(i).render();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment