Example #1
0
    private void updateRangeMazeIfNeeds()
    {
        if (player.cell != null)
        {
            if (player.cell.colPos > cell.colPos - range &&
                player.cell.colPos < cell.colPos + range &&
                player.cell.rowPos > cell.rowPos - range &&
                player.cell.rowPos < cell.rowPos + range)
            {
                var waveMaze1 = MazeCell.Clone <MazeCell[, ]>(maze);
                var current   = MazeCell.Clone(cell);
                var end       = MazeCell.Clone(player.cell);

                var endCell   = waveMaze1[end.rowPos, end.colPos];
                var mazeCells = createMap(waveMaze1, waveMaze1[current.rowPos, current.colPos], endCell, 1);
                var start     = "";

                for (int i = 0; i < mazeCells.Length / mazeCells.GetLength(0); i++)
                {
                    start += "{ ";
                    for (int j = 0; j < mazeCells.GetLength(0); j++)
                    {
                        if (mazeCells[i, j].waveCounter < 10)
                        {
                            start += "0";
                        }
                        start += (mazeCells[i, j].waveCounter + " ");
                    }
                    start += " }\n";
                }

//                print(start);

                var way = new MazeCell[endCell.waveCounter - 1];

                findWay(waveMaze1, endCell, way);

                if (way.Length > 1)
                {
                    var newPos = new Vector3(way[1].colPos * CellWidth + CellWidth / 2f, -2, way[1].rowPos * CellHeight + CellHeight / 2f);
                    var dif    = newPos - transform.position;

                    if (dif.x < 0)
                    {
                        transform.rotation = Quaternion.Euler(new Vector3(0f, -90f, 0f));;
                    }

                    if (dif.x > 0)
                    {
                        transform.rotation = Quaternion.Euler(new Vector3(0f, 90f, 0f));;
                    }



                    if (dif.z < 0)
                    {
                        transform.rotation = Quaternion.Euler(new Vector3(0f, 180f, 0f));;
                    }

                    if (dif.z > 0)
                    {
                        transform.rotation = Quaternion.Euler(new Vector3(0f, 0f, 0f));;
                    }


                    transform.position = newPos;
                    cell = way[1];
                }
                else
                {
                    enemyState = EnemyState.ATTACK;
                }



                var str = "";

                for (int i = 0; i < way.Length; i++)
                {
                    str += "{ " + way[i].rowPos + " " + way[i].colPos + " } ";
                }


//                print(str);
            }
            else
            {
                enemyState = EnemyState.IDLE;
            }
        }
    }