Пример #1
0
 public bool ExistAt(CubeCoords coords)
 {
     return(ExistAt(coords.x, coords.y));
 }
Пример #2
0
 public FastList <CubeCoords> NeighboursOf(CubeCoords coords)
 {
     return(NeighboursOf(coords.x, coords.y));
 }
Пример #3
0
 public void ClearAt(CubeCoords coords)
 {
     ClearAt(coords.x, coords.y);
 }
Пример #4
0
 public void Add(CubeCoords coords, T item)
 {
     Add(coords.x, coords.y, item);
 }
Пример #5
0
 public static Vector2 Hex2Pix(CubeCoords coords, float hexSize)
 {
     return(Hex2Pix(coords.x, coords.y, hexSize));
 }
Пример #6
0
        public static void GenerateHex(CubeCoords coords,
                                       HexList4D <HexBackgroundComponent> background, HexList4D <HexForegroundComponent> foreground)
        {
            FastList <CubeCoords> neighbours = background.NeighboursOf(coords);
            int grass  = 0;
            int water  = 0;
            int swamp  = 0;
            int forest = 0;

            for (int i = 0; i < neighbours.Count; i++)
            {
                switch (background[neighbours[i].x, neighbours[i].y].BackgroundType)
                {
                case BackroundTypes.Grass:
                    grass++;
                    break;

                case BackroundTypes.Water:
                    water++;
                    break;

                case BackroundTypes.Swamp:
                    swamp++;
                    break;

                case BackroundTypes.Forest:
                    forest++;
                    break;

                default:
                    break;
                }
            }
            int            max = Mathf.Max(grass, water, swamp, forest);
            BackroundTypes TypeB;

            if (Random.Range(0f, 1f) > 0.3f)
            {
                if (max == grass)
                {
                    TypeB = BackroundTypes.Grass;
                }
                else if (max == water)
                {
                    TypeB = BackroundTypes.Water;
                }
                else if (max == swamp)
                {
                    TypeB = BackroundTypes.Swamp;
                }
                else
                {
                    TypeB = BackroundTypes.Forest;
                }
            }
            else
            {
                Array values = Enum.GetValues(typeof(BackroundTypes));
                TypeB = (BackroundTypes)values.GetValue((int)Mathf.Round(Random.Range(0f, 1f) * (values.Length - 1)));
            }
            background.Add(coords, new HexBackgroundComponent()
            {
                BackgroundType = TypeB,
                Parent         = null,
                SpeedDown      = 1f,
                IsNew          = false
            });
            //foreground
            neighbours = foreground.NeighboursOf(coords);
            int empty    = 0;
            int obstacle = 0;
            int enemy    = 0;
            int diamond  = 0;

            for (int i = 0; i < neighbours.Count; i++)
            {
                switch (foreground[neighbours[i].x, neighbours[i].y].ForegroundType)
                {
                case ForegroundTypes.Empty:
                    empty++;
                    break;

                case ForegroundTypes.Obstacle:
                    obstacle++;
                    break;

                case ForegroundTypes.Enemy:
                    enemy++;
                    break;

                case ForegroundTypes.Diamond:
                    diamond++;
                    break;

                default:
                    break;
                }
            }
            max = Mathf.Max(empty, obstacle, enemy, diamond);
            ForegroundTypes typeF;

            if (Random.Range(0f, 1f) > 0.2f)
            {
                if (max == obstacle)
                {
                    typeF = ForegroundTypes.Obstacle;
                }
                else if (max == enemy)
                {
                    typeF = ForegroundTypes.Empty;
                }
                else if (max == diamond)
                {
                    typeF = ForegroundTypes.Empty;
                }
                else
                {
                    typeF = ForegroundTypes.Empty;
                }
            }
            else
            {
                Array values = Enum.GetValues(typeof(ForegroundTypes));
                typeF = (ForegroundTypes)values.GetValue((int)Mathf.Round(Random.Range(0f, 1f) * (values.Length - 1)));
                if (typeF == ForegroundTypes.Spawn)
                {
                    typeF = ForegroundTypes.Diamond;
                }
            }
            foreground.Add(coords, new HexForegroundComponent()
            {
                ForegroundType = typeF,
                Parent         = null,
                IsNew          = false
            });
        }
Пример #7
0
        private static void GenerateRecursiveF(HexList4D <HexForegroundComponent> background,
                                               ForegroundTypes type, ForegroundTypes badType, CubeCoords coords, int value, float chance, float diffChange)
        {
            background.Add(coords, new HexForegroundComponent()
            {
                ForegroundType = type,
                IsNew          = false,
                Value          = value
            });
            FastList <CubeCoords> neighbours = background.NeighboursOf(coords);

            for (int j = 0; j < neighbours.Count; j++)
            {
                HexForegroundComponent hexComponent = background[neighbours[j].x, neighbours[j].y];
                if (hexComponent.ForegroundType == badType && Random.Range(0f, 1f) < chance)
                {
                    GenerateRecursiveF(background, type, badType, neighbours[j], value, chance - diffChange, diffChange);
                }
            }
        }