Ejemplo n.º 1
0
        public GameObject CreateDecor(Main main)
        {
            GameObject    parent    = new GameObject("Decor");
            int           count     = UnityEngine.Random.Range(minCount, maxCount + 1);
            LocationTiles tempTiles = new LocationTiles(main.Tiles);

            for (int i = 0; i < count; i++)
            {
                Point <int> point = tempTiles.GetFreeRandomPoint(1, 1, 0, 0, 0);
                if (point == null)
                {
                    Debug.Log("no more place for decor");
                    break;
                }

                Sprite     sprite = Sprites[UnityEngine.Random.Range(0, Sprites.Length)];
                GameObject decor  = new GameObject("Decor " + sprite.name);

                float scale = main.SourceGraphicsScale;
                decor.AddComponent <SpriteRenderer>().sprite = sprite;
                decor.transform.SetParent(parent.transform, true);
                decor.transform.localScale    = new Vector3(scale * (UnityEngine.Random.value > 0.5f ? 1 : -1), scale, 1);
                decor.transform.localPosition = new Vector3(point.x * main.TileSize + main.TileSize / 2, point.y * main.TileSize + main.TileSize / 2 + scale * sprite.bounds.size.y / 2, 0);
                decor.GetComponent <SpriteRenderer>().sortingOrder = LocationSortOrders.GetLocationObjectSortOrder(point.y * main.TileSize + main.TileSize / 2);
                tempTiles.Set(point.x, point.y, TileType.Forbidden);
            }
            return(parent);
        }
Ejemplo n.º 2
0
        private GameObject TryGenerateHouse(Main main)
        {
            int         width  = UnityEngine.Random.Range(minHouseWidth, maxHouseWidth);
            int         height = UnityEngine.Random.Range(minHouseHeight, maxHouseHeight) + 1;      //+1 for roof
            Point <int> point  = main.Tiles.GetFreeRandomPoint(width, height, maxInvisibleHorizontal, maxInvisibleVertical, emptyBorder);

            if (point == null)
            {
                Debug.Log("Cannot find place for house (" + width + ", " + height + ")");
                return(null);
            }

            GameObject house = new GameObject("House (" + width + ", " + height + ")");

            {
                int sortOrder = LocationSortOrders.GetLocationObjectSortOrder(point.y * main.TileSize);

                GameObject walls = TiledSprite.Create(wallTiles);
                walls.GetComponent <TiledSprite> ()
                .SetTiles(width, height - 1)
                .SetTileSize(main.TileSize, main.TileSize)
                .SetSortOrder(sortOrder);
                walls.transform.SetParent(house.transform, true);

                GameObject roof = TiledSprite.Create(roofTiles);
                roof.GetComponent <TiledSprite> ()
                .SetTiles(width, 1)
                .SetTileSize(main.TileSize, main.TileSize)
                .SetSortOrder(sortOrder);
                roof.transform.SetParent(house.transform, true);
                roof.transform.localPosition = new Vector3(0, (height - 1) * main.TileSize, 0);

                GameObject shadow = TiledSprite.Create(shadowTiles);
                shadow.GetComponent <TiledSprite> ()
                .SetTiles(width, 1)
                .SetTileSize(main.TileSize, main.TileSize)
                .SetSortOrder(sortOrder + 1);
                shadow.transform.SetParent(house.transform, true);
                shadow.transform.localPosition = new Vector3(0, (height - 2) * main.TileSize, 0);

                GameObject grass = TiledSprite.Create(groundToWallTiles);
                grass.GetComponent <TiledSprite> ()
                .SetTiles(width, 1)
                .SetTileSize(main.TileSize, main.TileSize)
                .SetSortOrder(sortOrder + 1);
                grass.transform.SetParent(house.transform, true);
            }

            main.Tiles.SetRect(point.x, point.y, width, height, TileType.House, true);
            house.transform.localPosition = new Vector3(point.x * main.TileSize, point.y * main.TileSize);
            return(house);
        }
Ejemplo n.º 3
0
        public GameObject CreateCharacters(Main main)
        {
            GameObject parent = new GameObject("Npcs");
            int        count  = UnityEngine.Random.Range(minimum, maximum + 1);

            for (int i = 0; i < count + 1; i++)
            {
                Point <int> point = main.Tiles.GetRandomTile(TileIsAvailable);
                if (point == null)
                {
                    Debug.Log("no more place for character");
                    break;
                }

                bool       isPlayer     = i == 0;
                GameObject toInstaniate = isPlayer ? Player : NPCs[UnityEngine.Random.Range(0, NPCs.Length)];
                Vector3    position     = new Vector3(point.x * main.TileSize + main.TileSize * UnityEngine.Random.value, point.y * main.TileSize + main.TileSize * UnityEngine.Random.value, 0);
                GameObject instance     = Instantiate(toInstaniate, position, Quaternion.identity) as GameObject;
                instance.GetComponentInChildren <SpriteRenderer>().sortingOrder = LocationSortOrders.GetLocationObjectSortOrder(instance.transform.localPosition.y);
                instance.transform.SetParent(parent.transform, true);
            }

            return(parent);
        }