Esempio n. 1
0
    /// <summary>
    /// Gets all tiles of a specific set type.
    /// </summary>
    /// <param name="allTiles"></param>
    /// <param name="type"></param>
    /// <returns></returns>
    protected virtual DualStore <TileDetails, GameObject> GetTileSetType(DualStore <TileDetails, GameObject> allTiles, TileSetType type)
    {
        DualStore <TileDetails, GameObject> thisTileset = new DualStore <TileDetails, GameObject>();

        foreach (KeyValuePair <TileDetails, GameObject> kv in allTiles.KeyValuePairs)
        {
            if (kv.Key.Type == type)
            {
                thisTileset.Add(kv.Key, kv.Value);
            }
        }

        return(thisTileset);
    }
Esempio n. 2
0
    /// <summary>
    /// Retrieves the tileset from all the different tilesets.
    /// </summary>
    /// <param name="allTiles"></param>
    /// <returns></returns>
    protected virtual DualStore <TileDetails, GameObject> GetTileset(DualStore <TileDetails, GameObject> allTiles)
    {
        //choose a tileset to play on.
        int    tileSetNo = UnityEngine.Random.Range(0, TileSets.Count);
        string tileSet   = TileSets[tileSetNo];

        DualStore <TileDetails, GameObject> thisTileset = new DualStore <TileDetails, GameObject>();

        foreach (KeyValuePair <TileDetails, GameObject> kv in allTiles.KeyValuePairs)
        {
            if (kv.Key.TileSet == tileSet)
            {
                thisTileset.Add(kv.Key, kv.Value);
            }
        }

        return(thisTileset);
    }
Esempio n. 3
0
    public override void OnStartServer()
    {
        if (!isServer)
        {
            return;
        }
        int seed = UnityEngine.Random.seed;

        rand = new System.Random(seed);

        //splits all the objects into something I can search with.
        DualStore <TileDetails, GameObject> gameObjects = new DualStore <TileDetails, GameObject>();

        foreach (GameObject obj in TileTypes)
        {
            TileDetails details = obj.GetComponent <TileDetails>();
            gameObjects.Add(details, obj);
        }


        gameObjects = GetTileset(gameObjects);

        Dictionary <TileSetType, TileLevel> tilesByTileSetType = new Dictionary <TileSetType, TileLevel>();

        foreach (TileSetType type in Enum.GetValues(typeof(TileSetType)))
        {
            TileLevel level = new TileLevel(seed);
            DualStore <TileDetails, GameObject> tileSetTiles = GetTileSetType(gameObjects, type);

            foreach (TileType ttype in Enum.GetValues(typeof(TileType)))
            {
                level.AssignTiles(ttype, GetTileTypes(tileSetTiles, ttype));
            }

            tilesByTileSetType.Add(type, level);
        }


        SpawnTiles(tilesByTileSetType);
    }
Esempio n. 4
0
    public override void OnStartServer()
    {
        if (!isServer) return;
        int seed = UnityEngine.Random.seed; 
        rand = new System.Random(seed); 

        //splits all the objects into something I can search with. 
        DualStore<TileDetails, GameObject> gameObjects = new DualStore<TileDetails, GameObject>(); 

        foreach(GameObject obj in TileTypes)
        {
            TileDetails details = obj.GetComponent<TileDetails>();
            gameObjects.Add(details, obj); 
        }


        gameObjects = GetTileset(gameObjects);

        Dictionary<TileSetType, TileLevel> tilesByTileSetType = new Dictionary<TileSetType, TileLevel>(); 

        foreach(TileSetType type in Enum.GetValues(typeof(TileSetType)))
        {
            TileLevel level = new TileLevel(seed);
            DualStore<TileDetails, GameObject> tileSetTiles = GetTileSetType(gameObjects, type); 

            foreach(TileType ttype in Enum.GetValues(typeof(TileType)))
            {
                level.AssignTiles(ttype, GetTileTypes(tileSetTiles, ttype)); 
            }

            tilesByTileSetType.Add(type, level); 
        }


        SpawnTiles(tilesByTileSetType); 
	}
Esempio n. 5
0
    /// <summary>
    /// Creates an instantites the tiles.
    /// </summary>
    /// <param name="map"></param>
    /// <param name="dividerLevel"></param>
    /// <param name="availiableTile"></param>
    protected virtual void GenerateElevators(TileType[,] map, int dividerLevel, Dictionary <TileSetType, TileLevel> availiableTile)
    {
        List <Vector2> leftEnds  = new List <Vector2>();
        List <Vector2> rightEnds = new List <Vector2>();

        for (int xdx = 0; xdx < map.GetLength(0); xdx++)
        {
            for (int ydx = 0; ydx < map.GetLength(1); ydx++)
            {
                TileType type = map[xdx, ydx];

                if (type == TileType.LeftEnd)
                {
                    leftEnds.Add(new Vector2(xdx, ydx));
                }
                else if (type == TileType.RightEnd)
                {
                    rightEnds.Add(new Vector2(xdx, ydx));
                }
            }
        }

        DualStore <Vector2, Vector2> veritcal = new DualStore <Vector2, Vector2>();

        foreach (Vector2 vec in rightEnds)
        {
            int xdx = (int)vec.x + 1;
            //int ydx = (int)vec.y;

            for (int ydx = (int)vec.y - 1; ydx > 0; ydx--)
            {
                if (map[xdx, ydx] != TileType.None)
                {
                    veritcal.Add(new Vector2(xdx, vec.y), new Vector2(xdx, ydx + 1));
                    ydx = -1;
                }
                else if (map[xdx - 1, ydx] == TileType.RightEnd)
                {
                    veritcal.Add(new Vector2(xdx, vec.y), new Vector2(xdx, ydx));
                    ydx = -1;
                }
                else if (map[xdx + 1, ydx] == TileType.LeftEnd)
                {
                    veritcal.Add(new Vector2(xdx, vec.y), new Vector2(xdx, ydx));
                    ydx = -1;
                }
            }
        }

        foreach (Vector2 vec in leftEnds)
        {
            int xdx = (int)vec.x - 1;
            //int ydx = (int)vec.y;

            for (int ydx = (int)vec.y - 1; ydx > 0; ydx--)
            {
                if (map[xdx, ydx] != TileType.None)
                {
                    veritcal.Add(new Vector2(xdx, vec.y), new Vector2(xdx, ydx + 1));
                    ydx = -1;
                }
                else if (map[xdx - 1, ydx] == TileType.RightEnd)
                {
                    veritcal.Add(new Vector2(xdx, vec.y), new Vector2(xdx, ydx));
                    ydx = -1;
                }
                else if (map[xdx + 1, ydx] == TileType.LeftEnd)
                {
                    veritcal.Add(new Vector2(xdx, vec.y), new Vector2(xdx, ydx));
                    ydx = -1;
                }
            }
        }

        foreach (KeyValuePair <Vector2, Vector2> kv in veritcal.KeyValuePairs)
        {
            TileSetType level = kv.Value.y > dividerLevel ? TileSetType.upperLevels : TileSetType.lowerLevels;

            GameObject obj = availiableTile[level].GetTileType(TileType.Platform);


            var tile = (GameObject)Instantiate(obj, new Vector3(kv.Key.x * Tilesize, kv.Key.y * Tilesize), new Quaternion());
            ElevatorMovement move = tile.GetComponent(typeof(ElevatorMovement)) as ElevatorMovement;
            move.EndPos   = new Vector2(kv.Value.x * Tilesize, kv.Value.y * Tilesize);
            move.StartPos = new Vector2(kv.Key.x * Tilesize, kv.Key.y * Tilesize);
            move.moveDir  = MovementDirection.updown;
            //ElevatorMovement move = tile.GetComponent<ElevatorMovement>();

            Debug.Log(tile);
            NetworkServer.Spawn(tile);
        }

        DualStore <Vector2, Vector2> horizontal = new DualStore <Vector2, Vector2>();

        foreach (Vector2 vec in rightEnds)
        {
            int ydx = (int)vec.y;

            for (int xdx = (int)vec.x + 1; xdx < map.GetLength(0) - 1; xdx++)
            {
                if (map[xdx, ydx] != TileType.None)
                {
                    horizontal.Add(new Vector2(vec.x, vec.y), new Vector2(xdx - 1, ydx));
                    xdx = map.GetLength(0);
                }
            }
        }

        foreach (KeyValuePair <Vector2, Vector2> kv in horizontal.KeyValuePairs)
        {
            TileSetType level = kv.Value.y > dividerLevel ? TileSetType.upperLevels : TileSetType.lowerLevels;

            GameObject obj = availiableTile[level].GetTileType(TileType.Platform);


            var tile = (GameObject)Instantiate(obj, new Vector3(kv.Key.x * Tilesize, kv.Key.y * Tilesize), new Quaternion());
            ElevatorMovement move = tile.GetComponent(typeof(ElevatorMovement)) as ElevatorMovement;
            move.EndPos   = new Vector2(kv.Value.x * Tilesize, kv.Value.y * Tilesize);
            move.StartPos = new Vector2(kv.Key.x * Tilesize, kv.Key.y * Tilesize);
            move.moveDir  = MovementDirection.leftright;
            //ElevatorMovement move = tile.GetComponent<ElevatorMovement>();

            Debug.Log(tile);
            NetworkServer.Spawn(tile);
        }
    }
Esempio n. 6
0
    /// <summary>
    /// Retrieves the tileset from all the different tilesets. 
    /// </summary>
    /// <param name="allTiles"></param>
    /// <returns></returns>
    protected virtual DualStore<TileDetails, GameObject> GetTileset(DualStore<TileDetails, GameObject> allTiles)
    {
        //choose a tileset to play on. 
        int tileSetNo = UnityEngine.Random.Range(0, TileSets.Count);
        string tileSet = TileSets[tileSetNo];

        DualStore<TileDetails, GameObject> thisTileset = new DualStore<TileDetails, GameObject>();

        foreach (KeyValuePair<TileDetails, GameObject> kv in allTiles.KeyValuePairs)
        {
            if (kv.Key.TileSet == tileSet)
            {
                thisTileset.Add(kv.Key, kv.Value);
            }
        }

        return thisTileset; 
    }
Esempio n. 7
0
    /// <summary>
    /// Creates an instantites the tiles. 
    /// </summary>
    /// <param name="map"></param>
    /// <param name="dividerLevel"></param>
    /// <param name="availiableTile"></param>
    protected virtual void GenerateElevators(TileType[,] map, int dividerLevel, Dictionary<TileSetType, TileLevel> availiableTile)
    {
        List<Vector2> leftEnds = new List<Vector2>();
        List<Vector2> rightEnds = new List<Vector2>(); 

        for (int xdx = 0; xdx < map.GetLength(0); xdx++)
        {
            for (int ydx = 0; ydx < map.GetLength(1); ydx++)
            {
                TileType type = map[xdx, ydx]; 

                if (type == TileType.LeftEnd)
                {
                    leftEnds.Add(new Vector2(xdx, ydx)); 
                }
                else if (type == TileType.RightEnd)
                {
                    rightEnds.Add(new Vector2(xdx, ydx)); 
                }
            }
        }

        DualStore<Vector2, Vector2> veritcal = new DualStore<Vector2, Vector2>(); 

        foreach (Vector2 vec in rightEnds)
        {
            int xdx = (int)vec.x + 1;
            //int ydx = (int)vec.y; 

            for (int ydx = (int)vec.y - 1; ydx > 0; ydx--)
            {
                if (map[xdx, ydx] != TileType.None)
                {
                    veritcal.Add(new Vector2(xdx, vec.y), new Vector2(xdx, ydx + 1));
                    ydx = -1; 
                }
                else if (map[xdx - 1, ydx] == TileType.RightEnd)
                {
                    veritcal.Add(new Vector2(xdx, vec.y), new Vector2(xdx, ydx));
                    ydx = - 1; 
                }
                else if (map[xdx + 1, ydx] == TileType.LeftEnd)
                {
                    veritcal.Add(new Vector2(xdx, vec.y), new Vector2(xdx, ydx));
                    ydx = -1; 
                }
            }
        }

        foreach (Vector2 vec in leftEnds)
        {
            int xdx = (int)vec.x - 1;
            //int ydx = (int)vec.y; 

            for (int ydx = (int)vec.y - 1; ydx > 0; ydx--)
            {
                if (map[xdx, ydx] != TileType.None)
                {
                    veritcal.Add(new Vector2(xdx, vec.y), new Vector2(xdx, ydx + 1));
                    ydx = -1;
                }
                else if (map[xdx - 1, ydx] == TileType.RightEnd)
                {
                    veritcal.Add(new Vector2(xdx, vec.y), new Vector2(xdx, ydx));
                    ydx = -1;
                }
                else if (map[xdx + 1, ydx] == TileType.LeftEnd)
                {
                    veritcal.Add(new Vector2(xdx, vec.y), new Vector2(xdx, ydx));
                    ydx = -1;
                }
            }
        }

        foreach (KeyValuePair<Vector2, Vector2> kv in veritcal.KeyValuePairs)
        {
            TileSetType level = kv.Value.y > dividerLevel ? TileSetType.upperLevels : TileSetType.lowerLevels;

            GameObject obj = availiableTile[level].GetTileType(TileType.Platform);
            

            var tile = (GameObject)Instantiate(obj, new Vector3(kv.Key.x * Tilesize, kv.Key.y * Tilesize), new Quaternion());
            ElevatorMovement move = tile.GetComponent(typeof(ElevatorMovement)) as ElevatorMovement;
            move.EndPos = new Vector2(kv.Value.x * Tilesize, kv.Value.y * Tilesize);
            move.StartPos = new Vector2(kv.Key.x * Tilesize, kv.Key.y * Tilesize);
            move.moveDir = MovementDirection.updown; 
            //ElevatorMovement move = tile.GetComponent<ElevatorMovement>();
            
            Debug.Log(tile);
            NetworkServer.Spawn(tile);
        }

        DualStore<Vector2, Vector2> horizontal = new DualStore<Vector2, Vector2>();

        foreach (Vector2 vec in rightEnds)
        {
            int ydx = (int)vec.y; 

            for (int xdx = (int)vec.x + 1; xdx < map.GetLength(0) - 1; xdx++)
            {
                if (map[xdx, ydx] != TileType.None)
                {
                    horizontal.Add(new Vector2(vec.x, vec.y), new Vector2(xdx - 1, ydx));
                    xdx = map.GetLength(0); 
                }
            }


           
        }

        foreach (KeyValuePair<Vector2, Vector2> kv in horizontal.KeyValuePairs)
        {
            TileSetType level = kv.Value.y > dividerLevel ? TileSetType.upperLevels : TileSetType.lowerLevels;

            GameObject obj = availiableTile[level].GetTileType(TileType.Platform);


            var tile = (GameObject)Instantiate(obj, new Vector3(kv.Key.x * Tilesize, kv.Key.y * Tilesize), new Quaternion());
            ElevatorMovement move = tile.GetComponent(typeof(ElevatorMovement)) as ElevatorMovement;
            move.EndPos = new Vector2(kv.Value.x * Tilesize, kv.Value.y * Tilesize);
            move.StartPos = new Vector2(kv.Key.x * Tilesize, kv.Key.y * Tilesize);
            move.moveDir = MovementDirection.leftright; 
            //ElevatorMovement move = tile.GetComponent<ElevatorMovement>();

            Debug.Log(tile);
            NetworkServer.Spawn(tile);
        }

    }
Esempio n. 8
0
    /// <summary>
    /// Gets all tiles of a specific set type. 
    /// </summary>
    /// <param name="allTiles"></param>
    /// <param name="type"></param>
    /// <returns></returns>
    protected virtual DualStore<TileDetails, GameObject> GetTileSetType (DualStore<TileDetails, GameObject> allTiles, TileSetType type)
    {
        DualStore<TileDetails, GameObject> thisTileset = new DualStore<TileDetails, GameObject>();

        foreach (KeyValuePair<TileDetails, GameObject> kv in allTiles.KeyValuePairs)
        {
            if (kv.Key.Type == type)
            {
                thisTileset.Add(kv.Key, kv.Value);
            }
        }

        return thisTileset;
    }