Ejemplo n.º 1
0
Archivo: NPC.cs Proyecto: gonzsa04/IA
        // Reinicia el NPC. Puede ocurrir por chocarse contra un enemigo, o por reiniciar el juego debido a que se ha capturado la bandera
        public void reset(bool fromCollision)
        {
            // Suelta la bandera si la lleva actualmente
            if (hasFlag)
            {
                // La bandera será el primer y único hijo que tenga, en este caso
                if (transform.childCount > 0)
                {
                    transform.GetChild(0).parent = null;
                    gameManager.flagDropped();
                }
            }

            // Reinicia las variables
            hasFlag            = false;
            transform.position = startPosition;
            transform.rotation = startRotation;

            // Reinicia los comportamientos si el reinicio viene de un comportamiento.
            // Si el reinicio no viene de un comportamiento entonces no se reinicia, porque ya será todo reiniciado desde el propio gestor del juego.
            if (fromCollision)
            {
                for (int i = 0; i < behaviors.Length; ++i)
                {
                    var enemy = behaviors[i].GetVariable("Enemy") as SharedTransform;
                    if (enemy != null)
                    {
                        enemy.Value = null;
                    }
                    if (behaviors[i].Group == gameManager.ActiveGroup)
                    {
                        BehaviorManager.instance.RestartBehavior(behaviors[i]);
                        break;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        // reset the NPC. reset can either come from running into an enemy or from resetting the game because of a flag capture
        public void reset(bool fromCollision)
        {
            // drop the flag if it currently has the flag
            if (hasFlag)
            {
                // the flag will be the first and only child
                if (transform.childCount > 0)
                {
                    transform.GetChild(0).parent = null;
                    gameManager.flagDropped();
                }
            }

            // reset the variables
            hasFlag            = false;
            transform.position = startPosition;
            transform.rotation = startRotation;

            // restart the behaviors if resetting from a behavior. Don't reset if not coming from a behavior because the behaviors will be
            // reset by the game manager
            if (fromCollision)
            {
                for (int i = 0; i < behaviors.Length; ++i)
                {
                    var enemy = behaviors[i].GetVariable("Enemy") as SharedTransform;
                    if (enemy != null)
                    {
                        enemy.Value = null;
                    }
                    if (behaviors[i].group == gameManager.ActiveGroup)
                    {
                        BehaviorManager.instance.restartBehavior(behaviors[i]);
                        break;
                    }
                }
            }
        }