示例#1
0
文件: BEnemy.cs 项目: rubohex/V1Rus
    /// <summary>
    /// La funcion se encarga de crear el camino que seguira el enemigo a partir de los waypoints y si el camino es cerrado o no
    /// </summary>
    private void CreatePath()
    {
        // Añadimos la posicion actual como inicial en el camino
        path.Add(transform.position);

        // Para cada waypoint calculamos su camino al siguiente
        for (int i = 0; i < wayPoints.Length - 1; i++)
        {
            // Aplicando el A estrella obtenemos un camino
            List <int> waypointPath = board.AStarAlgorithm(board.PositionToIndex(wayPoints[i].position), board.PositionToIndex(wayPoints[i + 1].position));

            // Añadimos todos estos indices al final de nuestro path
            foreach (int index in waypointPath)
            {
                path.Add(board.IndexToPosition(index, gameObject));
            }
        }

        if (closedPath)
        {
            // Aplicando el A estrella obtenemos un camino
            List <int> waypointPath = board.AStarAlgorithm(board.PositionToIndex(wayPoints[wayPoints.Length - 1].position), board.PositionToIndex(wayPoints[0].position));

            // Añadimos todos estos indices al final de nuestro path
            foreach (int index in waypointPath)
            {
                path.Add(board.IndexToPosition(index, gameObject));
            }

            // Si el camino es cerrado eliminamos el ultimo punto ya que es el inicial
            path.RemoveAt(path.Count - 1);
        }
    }
示例#2
0
文件: BPlayer.cs 项目: rubohex/V1Rus
    public void SetupPlayer(BGameManager manager, DPlayerInfo playerInfo, List <int> endIndex)
    {
        // Cargamos los datos basicos del jugador
        rotateLeft   = playerInfo.rotateLeft;
        rotateRight  = playerInfo.rotateRight;
        move         = playerInfo.move;
        rotationTime = playerInfo.rotationTime;
        moveTime     = playerInfo.moveTime;
        recogerCable = playerInfo.recogerCable;

        // Cargamos el manager del nivel
        gameManager = manager;

        // Obtenemos el tablero
        board = gameManager.GetActiveBoard();

        // Actualizamos los Ap que tenemos para el nivel
        Ap = maxAP = board.GetBoardAp();

        // Colocamos al jugador en la casilla de salida y guardamos su indice
        tileIndex = board.PositionToIndex(transform.position);

        // Guardamos los indices finales
        this.endIndex = endIndex;

        // Inicializa el camino
        RestartPath();

        // Temporal
        textAp      = GameObject.Find("TextApPrueba").GetComponent <Text>();
        textAp.text = "AP: " + Ap;
    }
示例#3
0
文件: BPlayer.cs 项目: rubohex/V1Rus
    void FixedUpdate()
    {
        if (canPlay)
        {
            // Elegimos el rayo que vamos a usar para el raycast
            cameraRay = Camera.main.ScreenPointToRay(Input.mousePosition);

            // Hacemos el raycast y vemos si hemos golpeado alguna casilla
            if (Physics.Raycast(cameraRay, out cameraHit) && !EventSystem.current.IsPointerOverGameObject() && !isMoving)
            {
                if (cameraHit.collider.name.Contains("Plataforma"))
                {
                    actualHit = board.PositionToIndex(cameraHit.point);

                    if (board.isTile(actualHit))
                    {
                        if (previousHit != actualHit)
                        {
                            // Vaciamos el camino anterior
                            RestartPath();

                            // Calculamos el camino
                            path.AddRange(board.AStarAlgorithm(path[path.Count - 1], actualHit, false));

                            // Dibujamos el camino
                            DrawPath();

                            // Guardamos el indice de la casilla cambiada
                            previousHit = actualHit;
                        }
                    }
                    else if (previousHit != -1)
                    {
                        // Cambiamos el material de la anterior casillas
                        board.RemoveMaterial(path[path.Count - 1], selectedMaterial);
                        path.ForEach(tile => board.RemoveMaterial(tile, cursorMaterial));
                        previousHit = -1;
                        path.Clear();
                    }
                }
            }
            else if (previousHit != -1 && path.Count > 1)
            {
                board.RemoveMaterial(path[path.Count - 1], selectedMaterial);
                path.ForEach(tile => board.RemoveMaterial(tile, cursorMaterial));
                previousHit = -1;
                path.Clear();
            }
        }
    }
示例#4
0
文件: BPuerta.cs 项目: rubohex/V1Rus
    /// <summary>
    /// Establece los bordes de la puerta de forma automática
    /// </summary>
    /// <param name="abierta">Estado de abierta</param>
    private void setEdges(bool abierta)
    {
        Vector3 posCentro = transform.position;
        Vector3 posPuerta = transform.Find("Cube/Suelo").transform.position;
        Vector3 dirPuerta = (posPuerta - posCentro).normalized;


        dirPuerta = setClean(dirPuerta);

        int indexSuelo     = boardScript.PositionToIndex(this.transform.position);
        int indexSigPuerta = boardScript.PositionToIndex(this.transform.position + dirPuerta);

        int edge = Convert.ToInt32(abierta);

        int dir = indexSigPuerta - indexSuelo;

        if (active)
        {
            if (dir == 1)
            {
                boardScript.UpdateWallsEdges(indexSuelo, rightEdge: edge);
            }
            else if (dir == -1)
            {
                boardScript.UpdateWallsEdges(indexSuelo, leftEdge: edge);
            }
            else if (dir > 1)
            {
                boardScript.UpdateWallsEdges(indexSuelo, upEdge: edge);
            }
            else if (dir < -1)
            {
                boardScript.UpdateWallsEdges(indexSuelo, downEdge: edge);
            }
        }
    }
示例#5
0
文件: BEnemy.cs 项目: rubohex/V1Rus
    public void SetupEnemy(BGameManager gameManager)
    {
        // Guardamos el gameManager
        this.gameManager = gameManager;

        // Obtenemos el tablero
        board = gameManager.GetActiveBoard();

        // Obtenemos el vector hacia arriba del tablero
        boardUP = board.GetBoardUp();

        // Posicion inicial del jugador en el waypoint 0
        transform.position = board.GetEnemySpawnPos(wayPoints[0].position, GetEnemyBounds().size);

        // Obtenemos el camino que tendra que recorrer el enemigo
        CreatePath();

        // Rotacion inicial mirando hacia el waypoint 1
        transform.rotation = Quaternion.LookRotation(path[1] - path[0], boardUP);

        // Activamos la colision
        GetComponent <CapsuleCollider>().enabled = true;

        // Obtenemos el indice del tablero en el que estamos
        boardIndex = board.PositionToIndex(transform.position);

        // Obtenemos el indice del array de waypoints en el que estamos
        pathIndex = 0;

        // Iniciamos la variable del pathDirection
        pathDirection = 1;

        // Definimos que el enemigo no se esta moviendo
        isMoving = false;

        // Definimos que la partida no se ha acabado todavia
        gameOver = false;
    }