Beispiel #1
0
        /**
         * Initialisation of the game
         * Generation of the scene from the level file
         */
        void Start()
        {
            //GameModel.Init();
            GameModel.resetDataBeforeLevel ();

            level = GameModel.ActualLevel;

            //Debug.Log (level.Name);

            //Debug.Log ("START Start GameController");

            //recupération des options
            handSide = HandSide.RIGHT_HAND;

            //lire fichier niveau
            //LevelParser parser = new LevelParser (FILE_PATH);

            //génération du héros

            //instanciate a hero using the class contained in the model
            Hero modelHero = GameModel.Hero;
            string heroClass = modelHero.GetType ().ToString ();

            if (heroClass == "Warrior")
            heroGameObject = Instantiate (warrior);
            else if (heroClass == "Monk")
            heroGameObject = Instantiate (monk);
            else if (heroClass == "Wizard")
            heroGameObject = Instantiate (wizard);
            else
            heroGameObject = Instantiate (warrior);

            //Debug.Log (heroGameObject);
            GameModel.HerosInGame.Add (heroGameObject.GetComponent<Hero> ());
            hero = GameModel.HerosInGame [0];
            float vitesseHeros = hero.MovementSpeed;
            hero.XpQuantity = modelHero.XpQuantity;

            //LEAP
            leapInstance = Instantiate (leapPrefab);
            //Debug.Log ("leapInstance : " + leapInstance);
            //the leap motion scene is child of camera so it follow the translation
            leapInstance.transform.parent = Camera.allCameras[0].transform;
            leapInstance.transform.position = new Vector3 (0f, 2.5f, 1.6f);
            //sets the "hand parent" field so the arms also are child of camera and don't flicker
            leapControl = leapInstance.GetComponent<HandController> ();
            leapControl.setModel(handSide, hero);
            leapControl.setGameController(this);

            leapControl.handParent = Camera.allCameras[0].transform;

            leapCanvas = Instantiate(leapCanvasPrefab);

            //Génération de terrain
            float longueurTerrain = vitesseHeros * tempsMusique;

            /*ter = Instantiate( terrain, new Vector3(0,0,0), Quaternion.identity) as GameObject;
            ter.transform.Rotate (0, -90, 0);
            ter.transform.localScale = new Vector3 (longueurTerrain, 1, 1);
            */
            ter = Instantiate (terrain, new Vector3 (-100, -2, 0), Quaternion.identity) as Terrain;
            //ter.terrainData.size = new Vector3 (1.0f, 1.0f, 1.0f);
            //ter.terrainData.size = new Vector3 (200, 200, 1);

            //génération des ennemis
            npcList = new List<GameObject> ();
            //Debug.Log (npcList);

            //List<Thing> ennemies = parser.getEnnemies ();
            List<Item> items = level.ItemList;
            //Debug.Log ("FINAL ITEM LIST COUNT : " + items.Count);

            foreach (Item item in items) {
            GameObject go = null;

            if (item.Type == "basicLancer")
                go = basicLancer;
            else if (item.Type == "fireLancer")
                go = fireLancer;
            else if (item.Type == "iceLancer")
                go = iceLancer;
            else if (item.Type == "basicDragonet")
                go = basicDragonet;
            else if (item.Type == "fireDragonet")
                go = fireDragonet;
            else if (item.Type == "iceDragonet")
                go = iceDragonet;
            else if (item.Type == "wall")
                go = wall;
            else if (item.Type == "cannon")
                go = canon;
            else if (item.Type == "assassin")
                go = assassin;
            else if (item.Type == "life")
                go = lifePotion;
            else if (item.Type == "power")
                go = powerPotion;
            else if (item.Type == "invincibility")
                go = invincibilityPotion;

            if (go != null){
                GameObject instance = Instantiate(go, new Vector3(item.PositionInX, go.transform.localScale.y/2, vitesseHeros*item.PositionInSeconds), Quaternion.identity) as GameObject;
                NPC npc = instance.GetComponent<NPC>();

                if (npc != null)
                    GameModel.NPCsInGame.Add(npc);
                //GameModel.NPCsInGame[GameModel.NPCsInGame.Count-1].transform.Rotate(0, 180, 0);
            }
            }

            //Génération du HUD
            hudMaster = Instantiate (hud).GetComponent<HudMaster>();
            //Debug.Log ("hudMaster : " + hudMaster);
            state = GameState.PLAY;

            Camera.main.transform.parent = heroGameObject.transform;
            Camera.main.transform.position = new Vector3 (0, 2.18f, 0);
            //Camera.main.transform.Translate(new Vector3(0, 2.18f, 0));

            pausedMenu = GameObject.Find("Canvas");
            pausedMenu.SetActive(false);
            paused = false;

            Time.timeScale = 1.0f;

            musicCanvas = Instantiate (musicCanvasPrefab);
            audioManager = musicCanvas.GetComponent<AudioManager> ();

            audioManager.SetMusicName (level.MusicPath);
            audioManager.Init ();

            //If leap is not connected, Pause game and show warning message
            if ( !leapControl.IsConnected())
            {
            //pause()
            audioManager.Pause();
            Time.timeScale = 0.0f;

            GameObject detectedCanvas = GameObject.Find("DetectedLeapCanvas");
            detectedCanvas.GetComponent<Canvas>().enabled = true;
            }

            //Debug.Log ("END Start GameController");

            //ADD TUTORIAL MANAGER

            if (level.Tutorial) {
            GameObject tutoGO = Resources.Load("prefabs/controllers/TutorialManager") as GameObject;
             	Instantiate (tutoGO);
            }
        }
Beispiel #2
0
    // Use this for initialization
    /**
     * Initialize all values
     */
    void Start()
    {
        GameModel.initSandbox ();

        handSide = HandSide.RIGHT_HAND;

        //GameObject heroGameObject = Instantiate (warrior);
        GameObject heroGameObject = Instantiate (wizard);
        Hero hero = heroGameObject.GetComponent<Hero> ();
        GameModel.HerosInGame.Add (hero);
        string heroClass = hero.GetType ().ToString ();
        //LEAP
        leapInstance = Instantiate (leapPrefab);
        //Debug.Log ("leapInstance : " + leapInstance);
        //the leap motion scene is child of camera so it follow the translation
        leapInstance.transform.parent = Camera.main.transform;
        leapInstance.transform.position = new Vector3 (0f, 2.5f, 1.6f);
        //sets the "hand parent" field so the arms also are child of camera and don't flicker
        leapControl = leapInstance.GetComponent<HandController> ();
        leapControl.setModel(handSide, hero);
        leapControl.handParent = Camera.main.transform;

        //If leap is not connected, Pause game and show warning message
        if ( !leapControl.IsConnected())
        {
            //pause()
            Time.timeScale = 0.0f;

            GameObject detectedCanvas = GameObject.Find("DetectedLeapCanvas");
            detectedCanvas.GetComponent<Canvas>().enabled = true;
        }

        ter = Instantiate (terrain, new Vector3 (-100, -2, 0), Quaternion.identity) as Terrain;

        //Génération du HUD
        hudMaster = Instantiate (hud).GetComponent<HudMaster>();

        Camera.main.transform.parent = heroGameObject.transform;
        Camera.main.transform.position = new Vector3 (0, 2.18f, 0);
    }