Exemplo n.º 1
0
    void Start()
    {
        print("GameManager.Start()");
        //DoDstarLite = true;
        if (boardArray != null)       //Only run if boardArray has been initialized (not if on title screen)
        {
            print("boardArray: " + boardArray);
            //Access enemies
            enemies = FindObjectsOfType <Enemy>();
            //Instantiate their search space
            if (enemies != null)
            {
                foreach (Enemy e in enemies)
                {
                    //print ("enemy: "+e);
                    //Make sure they are initialized to the correct tile.
                    SpecialPathNode tile = e.GetTileOn();
                    //print ("tile: "+tile);
                    if (tile != null)
                    {
                        e.TileX = tile.X;
                        e.TileY = tile.Y;
                    }
                    //Debug.Log("Enemy: " + e.TileX + ", " + e.TileY + "; Player: " + tile.X + ", " + tile.Y);
                    e.InstantiateAStar(boardArray);
                    e.InstantiateDStar(boardArray);
                }
            }
            //Get location of exit tile
            foreach (SpecialPathNode n in boardArray)
            {
                if (n != null)
                {
                    if (n.tile != null)
                    {
                        if (n.tile.gameObject.tag == "Exit")
                        {
                            ExitTile = n;
                            n.IsWall = false;
                            Debug.Log("FOUND EXIT");
                        }
                    }
                }
            }

            //Get player location
            player = FindObjectOfType <Player>();
            Debug.Log("PLAYER: " + player);
            player.HealthPoints = PLAYERHP;
            PlayerLocation      = player.GetComponent <Player>().GetTileOn();
        }
    }
Exemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        //print ("GameManager.Update()");
        lastPlayedLevel = level;
        enemies         = FindObjectsOfType <Enemy>();
        int numEnemies = enemies.Length;

        if (exitBlock != null && numEnemies == 0)
        {
            GameObject.Destroy(exitBlock);
            showExitMessage();
        }
        else if (ExitTile != null && numEnemies > 0 && exitBlock == null)
        {
            exitBlock = Instantiate(boardScript.obstacleTile, new Vector3(ExitTile.X, ExitTile.Y, 0f), Quaternion.identity) as GameObject;
            hideExitMessage();
        }
        if (player == null && enemies.Length == 0)
        {
            //print ("update: null and length enemies==0");
            Mover[] movers = FindObjectsOfType <Mover>();
            foreach (Mover m in movers)
            {
                print("(" + (player == null) + " | " + (enemies.Length == 0) + "killing mover from GameManager");
                m.Die();
            }
        }
        else if (player == null)
        {
            //print ("update: player null");
            GameOver();
        }
        else
        {
            //print ("update: player not null");
            PlayerLocation = player.GetComponent <Player>().GetTileOn();
            if (!doingSetup)
            {
                if (PreviousPlayerLocation == null)
                {
                    PreviousPlayerLocation = PlayerLocation;
                    //PathToPlayer();
                }


                //Debug.Log("GameManager Player Location: " + PlayerLocation.X + ", " + PlayerLocation.Y);
                //Debug.Log(player.transform.position);
                if (PlayerLocation != PreviousPlayerLocation)
                {
                    //PathToPlayer();
                    PreviousPlayerLocation = PlayerLocation;
                }
            }
        }

        /*
         * for(int i = 0; i < boardArray.GetLength(0); i++)
         * {
         *  for (int j = 0; j < boardArray.GetLength(1); j++)
         *  {
         *      if (boardArray != null && boardArray[i,j].tile != null && boardArray[i,j].tile.tag == "Floor")
         *      {
         *          boardArray[i, j].tile.GetComponent<SpriteRenderer>().color = Color.white;
         *      }
         *  }
         * }*/
    }
Exemplo n.º 3
0
    void InitGame()
    {
        print("GameManager.InitGame()");
        doingSetup = true;
        if (exitText == null)
        {
            exitText         = GameObject.Find("ExitText").GetComponent <Text>();
            exitText.enabled = false;
        }
        else if (exitText != null && exitText.enabled)
        {
            exitText.enabled = false;
        }
        if (levelDisplayText == null)
        {
            levelDisplayText      = GameObject.Find("LevelDisplayText").GetComponent <Text>();
            levelDisplayText.text = "Level: " + level;
        }
        else if (levelDisplayText != null)
        {
            levelDisplayText.text = "Level: " + level;
        }

        titleImage.SetActive(false);
        titleBool  = false;
        levelImage = GameObject.Find("LevelImage");
        levelText  = levelImage.GetComponentInChildren <Text>();
//		levelText = GameObject.Find("LevelText").GetComponent<Text>();
        levelText.text = "Level: " + level;
        levelImage.SetActive(true);
        Invoke("HideLevelImage", levelStartDelay);

        //cameraScript = GetComponent<CameraUpdater>();
        //cameraScript.target = null;

        boardScript = GetComponent <BoardManager>();
        //enemies.Clear();
        boardArray = null;
        boardArray = boardScript.SetupPCGScene(level);
        if (boardArray == null)
        {
            boardArray = boardScript.SetupDefaultScene();
        }
        int xNum = boardArray.GetLength(0);
        int yNum = boardArray.GetLength(1);

        for (int y = 0; y < yNum; y++)
        {
            for (int x = 0; x < xNum; x++)
            {
                //Initialize any empty cells to non-walkable
                if (boardArray[x, y] == null)
                {
                    boardArray[x, y]        = new SpecialPathNode();
                    boardArray[x, y].X      = x;
                    boardArray[x, y].Y      = y;
                    boardArray[x, y].IsWall = true;
                }
            }
        }
        Start();
    }