Example #1
0
    private bool movementSFXplaying;    // controlamos si el sonido de movimiento esta sonadno


    // Use this for initialization
    void Start()
    {
        // referencias
        scManager        = gameManager.GetComponent <ScoreManager>();
        gManager         = gameManager.GetComponent <GameManager>();
        lfManager        = gameManager.GetComponent <LifesManager>();
        audioSource      = GetComponent <AudioSource>();
        audioSource.clip = movementSound;
        audioSource.loop = true;            // el sonido sera en bucle

        // maracamos al jugador como incapaz de moverse
        canMove = false;

        // guardmos el nodo en el que estamos
        currentNode = grid.GetNodeContainingPosition(transform.position);
        initialNode = currentNode;
        Debug.Log("The PacMan is on the node: " + currentNode.gridPosition_x + " :x  " + currentNode.gridPosition_y + " :y");

        // comporvamos si es transitable o no
        if (!currentNode.isTransitable)
        {
            Debug.LogError("ERROR DE POSICIONAMIENTO: PacMan no puede estar en este nodo intransitable", this.gameObject);
        }

        // snapeamos al nodo en el que estamos para que se coloque bien por si no esta bien puesto
        grid.AdjustPosition(this.gameObject, currentNode);

        // miramos si el sondio de movimiento esta sonando
        movementSFXplaying = GetComponent <AudioSource>().isPlaying;
    }
Example #2
0
    // Use this for initialization
    void Start()
    {
        // guardamos el nodo en el que estamos
        currentNode = grid.GetNodeContainingPosition(transform.position);
        // usamos su posicion para colocarnos bien
        //transform.position = new Vector3(currentNode.position.x, currentNode.position.y, transform.position.z);

        grid.AdjustPosition(this.gameObject, currentNode);
    }
Example #3
0
    public MyGrid grid;             // referencia al grid

    // Use this for initialization
    void Start()
    {
        // guardamos el nodo en el que nos encontramos
        currentNode = grid.GetNodeContainingPosition(transform.position);
        // ajustamos nuestra posicion ("no es necesario pero me es mas sencillo a la hora de trabajar en el viewport")
        grid.AdjustPosition(this.gameObject, currentNode);

        currentNodePositionOnGrid = new Vector2((int)currentNode.gridPosition_x, (int)currentNode.gridPosition_y);
    }
Example #4
0
    public AudioClip catchClip;                // efecto sonoro al coger este objeto

    // DANI ATENTO A ESTA FUCNIO YA QUE NO SE LLAMARA A NO SER QUE LA HAGAS VIRTUAL Y EL RESTO DE STARTS OVERRIDEN Y LLAMANDO A ESTA FUNCION
    protected virtual void Start()
    {
        //Debug.Log(transform.position + " " + grid);

        // ajustamos la posicion de este objeto al nodo en el que esta
        // guardamos el nodo en el que estamos

        currentNode = grid.GetNodeContainingPosition(transform.position);

        //AdjustPosition();

        grid.AdjustPosition(this.gameObject, currentNode);
    }
    private float currentTimeOnBase;      // tiempo que llevamos en base

    // Use this for initialization
    public virtual void Start()
    {
        // captura de referencias
        grid   = GameObject.FindGameObjectWithTag("Grid").GetComponent <MyGrid>();
        pacMan = GameObject.FindGameObjectWithTag("PacMan").GetComponent <PacMan>();

        ghostBaseObject = GameObject.FindGameObjectWithTag("GhostBase");

        //ghostRenderer = transform.GetComponentInChildren<Renderer>();

        // base de los fantasmas
        ghostBase = grid.GetNodeContainingPosition(ghostBaseObject.transform.position); // guardamos donde se encuentra la base
        ghostBaseObject.transform.position = ghostBase.position;                        // ajustamos su posicion

        //  guardamos los materiales de los fantasmas
        // transform.GetComponentInChildren<Renderer>().material = initialMaterial;



        // DANI SI PUEDES HAZ QUE SEA LA ZONA ENTERA LA QUE SE CONSDIERE LA BASE Y QUE LOS FANTASMAS PUEDAN IR A DIFERENTES POSICIONES DE ESTA
        // Y QUE ADEMAS SE GUARDEN LAS COORDENADAS DE TODOS LOS NODOS SITUADOS AHI

        // waypoints
        currentWaypointIndex = 0;
        nodeToReach          = waypoints[currentWaypointIndex].GetNode();

        // guardamos el nodo en el que estamos
        currentNode = grid.GetNodeContainingPosition(transform.position);
        initialNode = currentNode;

        //Debug.LogError(currentNode == initialNode, gameObject);

        pathCalculated = false;
        // usamos su posicion para colocarnos bien
        grid.AdjustPosition(this.gameObject, currentNode);

        // creamos la lista para el camino
        pathToFollow = new List <Node>();            // si inicializamos eta variable en el start no sra accesible desde otras funciones que no sean de unity (CONJETURA)

        // guardamos el color inicial
        initialColor = ghostRenderer.material.color;
    }
    // funcion que dibuja el inspector
    public override void OnInspectorGUI()
    {
        //base.OnInspectorGUI();      // dibuajmos el inspector tal y como lo teniamos

        DrawDefaultInspector();     // con esto llammos a la funcion de OnINspectorGUI de la base

        if (GUILayout.Button("Generate Grid Reference", GUILayout.Width(240)))
        {
            Debug.Log("Grid Creada");
            MyGrid grid = target as MyGrid;// target es una variable inerna que contiene el elemento que estamos pintadno ene l inspector (en este caso seria el gameobject que contiene el cidogo)

            // ahora ccon el codigo siguiente podremos generar la grid incuso antes de el moemnto de start

            grid.GenerateGrid();
        }

        if (GUILayout.Button("Order elements of the scene", GUILayout.Width(300)))
        {
            MyGrid grid = target as MyGrid;// target es una variable inerna que contiene el elemento que estamos pintadno ene l inspector (en este caso seria el gameobject que contiene el cidogo)

            grid.GenerateGrid();

            // funcion que colocara todos los elementos del juego en su posicion

            //Scene scene = SceneManager.GetActiveScene();
            //scene.GetRootGameObjects(allObjects);


            //// iterate root objects and do something
            //for (int i = 0; i < allObjects.Count; ++i)
            //{
            //    GameObject gameObject = allObjects[i];

            //    if (gameObject.tag == "BigBall" || gameObject.tag == "Ball")
            //    {
            //        PunctuableItem pItem = gameObject.GetComponent<PunctuableItem>();

            //        pItem.grid.AdjustPosition(gameObject, pItem.currentNode);
            //    }

            //}

            // iteramos por todos los gameobjets de la escena y dependeindod el tipo que sean lalmamaos a una u otra funcion
            //foreach (GameObject gO in Resources.FindObjectsOfTypeAll(typeof(GameObject)) as GameObject[])
            //{
            //    if (gO.tag == "BigBall" || gO.tag == "Ball")
            //    {
            //        PunctuableItem pItem = gO.GetComponent<PunctuableItem>();

            //        pItem.grid.AdjustPosition(gO, pItem.currentNode);
            //    }


            //}

            // iteramos por todos los nodos del grid y llamamos a una funcion que nos dara el go del nodo . despues usaremos este go y lo pasaremos como parametero a grid adjsut positin
            foreach (Node node in grid.GetGrid())
            {
                GameObject go = grid.GetObjectOfNode(node);
                Debug.Log("hemos entrado en el foreach");
                // si hay algo ajustamos su posicion

                // ajustamos su posicion teniendo en cuenta que el objeto que colocaremos es el que hemos encontrado buscando en la posicion del nodo y que el nodo actual de este objeto es ese mismo nodo
                if (go != null && go.transform.tag != "OrderExeption")
                {
                    grid.AdjustPosition(go, node);
                }

                //grid.AdjustPosition(go, go.GetComponent<>)
            }
        }


        // VALORES QUE RELLENAREMOS DESDE EL INSPECTOR PARA CALUCLAR EL CAMINO
        EditorGUILayout.LabelField("Prueba del algrotimo de path finding");
        startingPoint.x = EditorGUILayout.FloatField("startingpoint x", startingPoint.x);
        startingPoint.y = EditorGUILayout.FloatField("startingPoint.y", startingPoint.y);
        endPoint.x      = EditorGUILayout.FloatField("endPoint.x", endPoint.x);
        endPoint.y      = EditorGUILayout.FloatField("endPoint.y", endPoint.y);

        // boton de debug para calcular caminos
        if (GUILayout.Button("Calculate path between nodes", GUILayout.Width(240)))
        {
            MyGrid myGrid = target as MyGrid;
            // antes de asignar el grid lo generamos
            myGrid.GenerateGrid();

            Node [,] grid = myGrid.GetGrid();

            myGrid.FindPath(grid[(int)startingPoint.x, (int)startingPoint.y], grid[(int)endPoint.x, (int)endPoint.y]);
        }
    }