예제 #1
0
    public Transform Spawn(Chararcter character, ICoordenate at = null)
    {
        GameTile target = at != null?hexGrid.GetTileByCoordenates(at) : hexGrid.GetRandomTile(GroundType.Walkable);

        character.Begin();
        target.occupier      = character.id;
        character.steppingOn = target;
        return(Instantiate(character.transform, target.transform.position, Quaternion.identity));
    }
예제 #2
0
 public GameTile GetTileByCoordenates(ICoordenate coordenates)
 {
     if (coordenates.x < 0 || coordenates.y < 0 ||
         coordenates.x >= width || coordenates.y >= height)
     {
         // Debug.Log("Skipping edge " + coordenates.x + "," + coordenates.y);
         return(null);
     }
     return(System.Array.Find(cells, (cell) => {
         return cell.self.x == coordenates.x && cell.self.y == coordenates.y;
     }));
 }
예제 #3
0
    void CreateGrowth(int index)
    {
        IGrowth growthAtHand = growths[index];

        if (growthAtHand.height > height || growthAtHand.width > width)
        {
            Debug.LogError("Growth at index " + index + "Has dimensions that are larger than the map's");
            return;
        }

        // var setting
        // random first style far enough in the south to be able to grow
        int startY = rnd.Next(0, height - growthAtHand.height);
        int startX = rnd.Next(0, width - growthAtHand.width);

        ICoordenate     coor      = new ICoordenate(startX, startY);
        List <GameTile> goneTiles = new List <GameTile>();
        GameTile        goingTile = GetTileByCoordenates(coor);

        goneTiles.Add(goingTile);

        // random first style can be set
        Terraform(goingTile.id, growthAtHand.growthNature);

        // then go randomly up based on height
        for (int i = 0; i < growthAtHand.height; i++)
        {
            int upper = rnd.Next(1, 4);
            switch (upper)
            {
            case (1):
                goingTile = GetNeighborTile("north", goingTile.id);
                break;

            case (2):
                goingTile = GetNeighborTile("northEast", goingTile.id);
                break;

            case (3):
                goingTile = GetNeighborTile("northWest", goingTile.id);
                break;
            }
            if (goingTile == null)
            {
                break;
            }
            // transform all of them
            Terraform(goingTile.id, growthAtHand.growthNature);
            // and add each tile in this line to the list of gone
            goneTiles.Add(goingTile);
        }

        // for every width, have one round of growth
        for (int i = 0; i < growthAtHand.width; i++)
        {
            // list to iterate through but not keep growing
            List <GameTile> iterationTiles = goneTiles;
            for (int j = 0; j < iterationTiles.Count; j++)
            {
                // random dir now
                goingTile = GetRandomNeighborTile(iterationTiles[j].id);
                // if we couldn't get a tile, oh well
                if (goingTile == null)
                {
                    break;
                }

                // otherwise add it to the count
                goneTiles.Add(goingTile);

                // random skip chance applies here
                int skipChance = rnd.Next(1, 11);
                if (growthAtHand.skipChance < skipChance)
                {
                    // only terraform if not skipped
                    Terraform(goingTile.id, growthAtHand.growthNature);
                }
            }
        }

        growthsTileCollection[index] = goneTiles;
    }