Esempio n. 1
0
    private LevelGraphPath createPath(Vector2 position, GameObject go, TileState state)
    {
        LevelGraphPath path = new LevelGraphPath();

        path.Position   = position;
        path.GameObject = go;
        path.State      = state;

        colorizePath(path);

        if (Math.Abs(position.IntX()) % 2 == 1)
        {
            go.transform.localRotation = Quaternion.AngleAxis(90.0f, new Vector3(0, 0, 1));
        }

        return(path);
    }
    /**
     * Public methods
     */
    void Start()
    {
        if (this.UseDynamicData)
        {
            this.CompletedTiles = ProgressData.CompletedTiles;
            this.CurrentPosition = ProgressData.MostRecentTile;
        }
        _grid = new LevelGraphTile[this.Size, this.Size];
        _paths = new LevelGraphPath[this.Size * 2 - 1, this.Size * 2 - 1];
        _halfSize = this.Size / 2;

        // Check if all bosses defeated
        _allBossesDefeated = true;
        for (int i = 0; i < this.BossTiles.Length; ++i)
        {
            bool contains = false;
            for (int j = 0; j < this.CompletedTiles.Length; ++j)
            {
                if (this.CompletedTiles[j].X == this.BossTiles[i].X && this.CompletedTiles[j].Y == this.BossTiles[i].Y)
                {
                    contains = true;
                    break;
                }
            }

            if (!contains)
            {
                _allBossesDefeated = false;
                break;
            }
        }

        // Setup boxes
        for (int x = -_halfSize; x < _grid.GetLength(0) - _halfSize; ++x)
        {
            for (int y = -_halfSize; y < _grid.GetLength(1) - _halfSize; ++y)
            {
                // Skip middle of all sides
                if ((x == 0 && Math.Abs(y) == _halfSize) || (y == 0 && Math.Abs(x) == _halfSize))
                    continue;

                GameObject go = Instantiate(BoxPrefab) as GameObject;
                go.transform.parent = this.transform;
                go.transform.localPosition = new Vector3(this.GridSpaceDistance * x, this.GridSpaceDistance * y, 0);
                Vector2 position = new Vector2(x, y);
                
                TileState state = TileState.Locked;
                List<TileTrait> traits = new List<TileTrait>();

                if (_allBossesDefeated && x == 0 && y == 0)
                {
                    state = TileState.Available;
                    traits.Add(TileTrait.Boss);
                }
                else
                {
                    foreach (IntegerVector tile in this.CompletedTiles)
                    {
                        if (tile.X == x && tile.Y == y)
                        {
                            state = TileState.Complete;
                            break;
                        }
                        else if (neighborsTile(position, tile))
                        {
                            state = TileState.Available;
                        }
                    }
                }

                // If no completed tiles, the center should be available
                if (this.CompletedTiles.Length == 0 && x == 0 && y == 0)
                    state = TileState.Available;

                if (state != TileState.Complete)
                {
                    foreach (Vector2 tile in this.BossTiles)
                    {
                        if (Mathf.RoundToInt(tile.x) == x && Mathf.RoundToInt(tile.y) == y)
                        {
                            traits.Add(TileTrait.Boss);
                            break;
                        }
                    }

                    if (ProgressData.IsMiniBoss(position))
                    {
                        traits.Add(TileTrait.Miniboss);
                    }
                }

                _grid[x + _halfSize, y + _halfSize] = createTile(position, go, state, traits.ToArray());
            }
        }

        // Setup paths
        for (int x = 0; x < _grid.GetLength(0); ++x)
        {
            for (int y = 0; y < _grid.GetLength(1); ++y)
            {
                if (_grid[x, y] == null)
                    continue;

                TileState state = _grid[x, y].State;

                if (state == TileState.Complete || state == TileState.Available)
                {
                    bool northCompleted = y < _grid.GetLength(1) - 1 && _paths[x * 2, y * 2 + 1] == null && (_grid[x, y + 1] != null && _grid[x, y + 1].State == TileState.Complete);
                    bool northAvailable = y < _grid.GetLength(1) - 1 && state != TileState.Available && !northCompleted && _paths[x * 2, y * 2 + 1] == null && (_grid[x, y + 1] != null && _grid[x, y + 1].State == TileState.Available);
                    bool eastCompleted = x < _grid.GetLength(0) - 1 && _paths[x * 2 + 1, y * 2] == null && (_grid[x + 1, y] != null && _grid[x + 1, y].State == TileState.Complete);
                    bool eastAvailable = x < _grid.GetLength(0) - 1 && state != TileState.Available && !eastCompleted && _paths[x * 2 + 1, y * 2] == null && (_grid[x + 1, y] != null && _grid[x + 1, y].State == TileState.Available);

                    if (northCompleted || northAvailable)
                    {
                        GameObject go = Instantiate(this.LinePrebab);
                        go.transform.parent = this.transform;
                        go.transform.localPosition = new Vector3(this.GridSpaceDistance * (x - _halfSize), this.GridSpaceDistance * (y - _halfSize) + this.GridSpaceDistance / 2.0f, 0);
                        TileState pathState = state == TileState.Complete && northCompleted ? TileState.Complete : TileState.Available;
                        _paths[x * 2, y * 2 + 1] = createPath(new Vector2((x - _halfSize) * 2, (y - _halfSize) * 2 + 1), go, pathState);
                    }

                    if (eastCompleted || eastAvailable)
                    {
                        GameObject go = Instantiate(this.LinePrebab);
                        go.transform.parent = this.transform;
                        go.transform.localPosition = new Vector3(this.GridSpaceDistance * (x - _halfSize) + this.GridSpaceDistance / 2.0f, this.GridSpaceDistance * (y - _halfSize), 0);
                        TileState pathState = state == TileState.Complete && eastCompleted ? TileState.Complete : TileState.Available;
                        _paths[x * 2 + 1, y * 2] = createPath(new Vector2((x - _halfSize) * 2 + 1, (y - _halfSize) * 2), go, pathState);
                    }
                }
            }
        }

        // Initialize current tile
        moveCurrentTile(this.CurrentPosition);
    }
 private void colorizePath(LevelGraphPath path)
 {
     path.GameObject.GetComponent<LevelSelectColorizer>().UpdateColor(path.State == TileState.Complete ? this.PlayerColor : this.AvailableColor);
 }
    private LevelGraphPath createPath(Vector2 position, GameObject go, TileState state)
    {
        LevelGraphPath path = new LevelGraphPath();
        path.Position = position;
        path.GameObject = go;
        path.State = state;

        colorizePath(path);

        if (Math.Abs(position.IntX()) % 2 == 1)
            go.transform.localRotation = Quaternion.AngleAxis(90.0f, new Vector3(0, 0, 1));

        return path;
    }
Esempio n. 5
0
    /**
     * Public methods
     */
    void Start()
    {
        if (this.UseDynamicData)
        {
            this.CompletedTiles  = ProgressData.CompletedTiles;
            this.CurrentPosition = ProgressData.MostRecentTile;
        }
        _grid     = new LevelGraphTile[this.Size, this.Size];
        _paths    = new LevelGraphPath[this.Size * 2 - 1, this.Size * 2 - 1];
        _halfSize = this.Size / 2;

        // Check if all bosses defeated
        _allBossesDefeated = true;
        for (int i = 0; i < this.BossTiles.Length; ++i)
        {
            bool contains = false;
            for (int j = 0; j < this.CompletedTiles.Length; ++j)
            {
                if (this.CompletedTiles[j].X == this.BossTiles[i].X && this.CompletedTiles[j].Y == this.BossTiles[i].Y)
                {
                    contains = true;
                    break;
                }
            }

            if (!contains)
            {
                _allBossesDefeated = false;
                break;
            }
        }

        // Setup boxes
        for (int x = -_halfSize; x < _grid.GetLength(0) - _halfSize; ++x)
        {
            for (int y = -_halfSize; y < _grid.GetLength(1) - _halfSize; ++y)
            {
                // Skip middle of all sides
                if ((x == 0 && Math.Abs(y) == _halfSize) || (y == 0 && Math.Abs(x) == _halfSize))
                {
                    continue;
                }

                GameObject go = Instantiate(BoxPrefab) as GameObject;
                go.transform.parent        = this.transform;
                go.transform.localPosition = new Vector3(this.GridSpaceDistance * x, this.GridSpaceDistance * y, 0);
                Vector2 position = new Vector2(x, y);

                TileState        state  = TileState.Locked;
                List <TileTrait> traits = new List <TileTrait>();

                if (_allBossesDefeated && x == 0 && y == 0)
                {
                    state = TileState.Available;
                    traits.Add(TileTrait.Boss);
                }
                else
                {
                    foreach (IntegerVector tile in this.CompletedTiles)
                    {
                        if (tile.X == x && tile.Y == y)
                        {
                            state = TileState.Complete;
                            break;
                        }
                        else if (neighborsTile(position, tile))
                        {
                            state = TileState.Available;
                        }
                    }
                }

                // If no completed tiles, the center should be available
                if (this.CompletedTiles.Length == 0 && x == 0 && y == 0)
                {
                    state = TileState.Available;
                }

                if (state != TileState.Complete)
                {
                    foreach (Vector2 tile in this.BossTiles)
                    {
                        if (Mathf.RoundToInt(tile.x) == x && Mathf.RoundToInt(tile.y) == y)
                        {
                            traits.Add(TileTrait.Boss);
                            break;
                        }
                    }

                    if (ProgressData.IsMiniBoss(position))
                    {
                        traits.Add(TileTrait.Miniboss);
                    }
                }

                _grid[x + _halfSize, y + _halfSize] = createTile(position, go, state, traits.ToArray());
            }
        }

        // Setup paths
        for (int x = 0; x < _grid.GetLength(0); ++x)
        {
            for (int y = 0; y < _grid.GetLength(1); ++y)
            {
                if (_grid[x, y] == null)
                {
                    continue;
                }

                TileState state = _grid[x, y].State;

                if (state == TileState.Complete || state == TileState.Available)
                {
                    bool northCompleted = y < _grid.GetLength(1) - 1 && _paths[x * 2, y * 2 + 1] == null && (_grid[x, y + 1] != null && _grid[x, y + 1].State == TileState.Complete);
                    bool northAvailable = y < _grid.GetLength(1) - 1 && state != TileState.Available && !northCompleted && _paths[x * 2, y * 2 + 1] == null && (_grid[x, y + 1] != null && _grid[x, y + 1].State == TileState.Available);
                    bool eastCompleted  = x < _grid.GetLength(0) - 1 && _paths[x * 2 + 1, y * 2] == null && (_grid[x + 1, y] != null && _grid[x + 1, y].State == TileState.Complete);
                    bool eastAvailable  = x < _grid.GetLength(0) - 1 && state != TileState.Available && !eastCompleted && _paths[x * 2 + 1, y * 2] == null && (_grid[x + 1, y] != null && _grid[x + 1, y].State == TileState.Available);

                    if (northCompleted || northAvailable)
                    {
                        GameObject go = Instantiate(this.LinePrebab);
                        go.transform.parent        = this.transform;
                        go.transform.localPosition = new Vector3(this.GridSpaceDistance * (x - _halfSize), this.GridSpaceDistance * (y - _halfSize) + this.GridSpaceDistance / 2.0f, 0);
                        TileState pathState = state == TileState.Complete && northCompleted ? TileState.Complete : TileState.Available;
                        _paths[x * 2, y * 2 + 1] = createPath(new Vector2((x - _halfSize) * 2, (y - _halfSize) * 2 + 1), go, pathState);
                    }

                    if (eastCompleted || eastAvailable)
                    {
                        GameObject go = Instantiate(this.LinePrebab);
                        go.transform.parent        = this.transform;
                        go.transform.localPosition = new Vector3(this.GridSpaceDistance * (x - _halfSize) + this.GridSpaceDistance / 2.0f, this.GridSpaceDistance * (y - _halfSize), 0);
                        TileState pathState = state == TileState.Complete && eastCompleted ? TileState.Complete : TileState.Available;
                        _paths[x * 2 + 1, y * 2] = createPath(new Vector2((x - _halfSize) * 2 + 1, (y - _halfSize) * 2), go, pathState);
                    }
                }
            }
        }

        // Initialize current tile
        moveCurrentTile(this.CurrentPosition);
    }
Esempio n. 6
0
 private void colorizePath(LevelGraphPath path)
 {
     path.GameObject.GetComponent <LevelSelectColorizer>().UpdateColor(path.State == TileState.Complete ? this.PlayerColor : this.AvailableColor);
 }