Package com.aqpproject.game

Source Code of com.aqpproject.game.Main

/*
* AQP Project
* http://http://code.google.com/p/aqp-project/
* Alexandre Gomez - Clément Troesch - Fabrice Latterner
*/
package com.aqpproject.game;

import com.aqpproject.tools.preprocessor.Preprocessor;
import com.aqpproject.visualisation.InitializationEvent;
import com.aqpproject.visualisation.InitializationListener;
import com.aqpproject.visualisation.gdx.GameGDX;
import com.aqpproject.worldmodel.game.WorldModelGame;
import java.awt.Toolkit;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.parsers.ParserConfigurationException;
import org.xml.sax.SAXException;

/**
* Main class
*
* @author Alexandre, Clement, Fabrice
*/
public class Main {

    /**
     * Main entry point
     *
     * @param args the command line arguments
     */
    public static void main(String[] args) throws InterruptedException {


        //Preprocessor: Generate the maps
        Preprocessor preprocessor = new Preprocessor();
        preprocessor.generateMap();
        if (preprocessor.hasNewMap()) {
            while (!preprocessor.isMapGenerated()) {
                //Wait
            }

            try {
                Thread.sleep(2000);
            } catch (InterruptedException ex) {
                Logger.getLogger(Preprocessor.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

        Singleton.getVisualisation().addInitializationListener(new InitializationListener() {

            @Override
            public void visualisationInitialized(InitializationEvent e) {
                //World Model
                try {
                    Singleton.getWorldModel().initialize();
                } catch (Exception ex) {
                    Logger.getLogger(GameGDX.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });

        //Visualisation
        Toolkit toolkit = Toolkit.getDefaultToolkit();
        int width = toolkit.getScreenSize().width - 256;
        int height = (int) (width * (9.f / 16.f));
        Singleton.getVisualisation().initialize(width, height, false);

        //Input
        Singleton.getInput().initialize();

        //Physics
        Singleton.getPhysics().initialize();

        //IA
        Singleton.getIA().initialize();

        try {
            Singleton.getPhysics().loadPhysicsTiles("config/static_objects.xml");
        } catch (ParserConfigurationException | IOException | SAXException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }

        while (Singleton.getWorldModel().isRunning()) {
            try {
                long delta = Singleton.getWorldModel().getTime() - Singleton.getWorldModel().getLastUpdate();
                if (delta >= WorldModelGame.UPDATE_RATE) {

                    Singleton.getWorldModel().saveEntitiesState();
                    Singleton.getInput().update();
                    Singleton.getNetwork().update();
                    Singleton.getIA().update();
                    Singleton.getPhysics().update();
                    Singleton.getWorldModel().update();
                    Singleton.getVisualisation().updateParticles(Singleton.getWorldModel().getDeltaTime());
                    Singleton.getNetwork().update();


                }
                Thread.sleep(10);
            } catch (InterruptedException ex) {
                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
            }

        }
        try {
            Singleton.getAudioController().destroy();
        } catch (ParserConfigurationException | SAXException | IOException ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
        Singleton.getPhysics().destroy();
        Singleton.getWorldModel().destroy();
        Singleton.getInput().destroy();
        Singleton.getVisualisation().destroy();
        Singleton.getNetwork().destroy();

    }
}
TOP

Related Classes of com.aqpproject.game.Main

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.