Ejemplo n.º 1
0
        private GameObject spawnAndPopulateTile(CubeCoord pos)
        {
            var go = spawnTile(pos);

            _populator.Populate(pos, go);
            return(go);
        }
Ejemplo n.º 2
0
 public List <GameObject> GetNeighborTiles(CubeCoord coord)
 {
     return(CubeCoord.Neighbors
            .Select(c => c + coord)
            .Where(_knownTiles.ContainsKey)
            .Select(c => _knownTiles[c])
            .ToList());
 }
Ejemplo n.º 3
0
 public static IEnumerator <CubeCoord> ShuffledRings(CubeCoord center, int startRing = 0, int maxRings = -1)
 {
     for (var i = 0; i < maxRings || maxRings == -1; ++i)
     {
         foreach (var coord in Ring(center, startRing + i).ToList().Shuffled())
         {
             yield return(coord);
         }
     }
 }
Ejemplo n.º 4
0
        public void Populate(CubeCoord coord, GameObject tileObject)
        {
            var techTree  = Global.FindTechTree();
            var structure = Util.chooseWeighted(_weights, techTree.Structures);

            var tileScript = tileObject.GetComponent <TileScript>();

            tileScript.Init(coord, techTree);
            tileScript.AssignStructure(structure);
        }
Ejemplo n.º 5
0
 public static IEnumerator <CubeCoord> Spiral(CubeCoord center, int startRing = 0, int maxRings = -1)
 {
     for (var i = 0; i < maxRings || maxRings == -1; ++i)
     {
         var coords = Ring(center, startRing + i);
         while (coords.MoveNext())
         {
             yield return(coords.Current);
         }
     }
 }
Ejemplo n.º 6
0
        void Start()
        {
            _renderer  = TilePrefab.GetComponentInChildren <MeshRenderer>();
            _populator = GetComponent <TilePopulator>();
            spawnOrigin();
            var spiralCoords = CubeCoord.ShuffledRings(CubeCoord.ORIGIN, 1, initialRings);

            enqueue(() => SpawnAll(spiralCoords, 0.5f, 0.1f));
            //StartCoroutine(SpawnAll(CubeCoord.Spiral(CubeCoord.ORIGIN, 1).Take(40), 0.5f, 0.1f));
            //StartCoroutine(SpawnAll(CubeCoord.Ring(CubeCoord.ORIGIN, 2), 0.1f, 2f));
            //StartCoroutine(SpawnEdgeTiles());
        }
Ejemplo n.º 7
0
        private GameObject spawnTile(CubeCoord pos)
        {
            var objectScale = TilePrefab.transform.localScale;
            var tileSize    = _renderer.bounds.size;

            tileSize.Scale(objectScale);

            var instance = Instantiate(TilePrefab, transform, true);

            instance.name = $"{pos}";
            var worldPos = pos.ToWorld(0, tileSize);

            instance.transform.position = worldPos;
            _knownTiles[pos]            = instance;
            return(instance);
        }
Ejemplo n.º 8
0
        public static IEnumerator <CubeCoord> Ring(CubeCoord center, int radius)
        {
            if (radius == 0)
            {
                yield return(center);
            }
            else
            {
                var cube = (center + (WEST * radius));
                foreach (var direction in Neighbors)
                {
                    for (var i = 0; i < radius; ++i)
                    {
                        yield return(cube);

                        cube += direction;
                    }
                }
            }
        }
Ejemplo n.º 9
0
        public void SpawnNewAroundAsync(CubeCoord coord)
        {
            var enumerator = CubeCoord.ShuffledRings(coord, 1, 3).WhereNot(_knownTiles.ContainsKey);

            enqueue(() => SpawnAll(enumerator, 0f, 0.2f));
        }
Ejemplo n.º 10
0
 public double Distance(CubeCoord b) => (this - b).Length;