Beispiel #1
0
        public static void GenerateMap(out HexList4D <HexBackgroundComponent> background,
                                       out HexList4D <HexForegroundComponent> foreground, int radius, int seed)
        {
            Random.InitState(seed);
            background = new HexList4D <HexBackgroundComponent>();
            foreground = new HexList4D <HexForegroundComponent>();
            HexBackgroundComponent backgroundHex = new HexBackgroundComponent();
            HexForegroundComponent foregroundHex = new HexForegroundComponent();

            background.Fill(radius);
            foreground.Fill(radius);
            foreground.Add(0, 0, new HexForegroundComponent()
            {
                ForegroundType = ForegroundTypes.Spawn,
                IsNew          = false
            });
            GenerateBackgroundStructure(background, radius, BackroundTypes.Water, BackroundTypes.Grass, 70, 1f, 0.1f);
            GenerateBackgroundStructure(background, radius, BackroundTypes.Swamp, BackroundTypes.Grass, 50, 1f, 0.2f);
            GenerateBackgroundStructure(background, radius, BackroundTypes.Forest, BackroundTypes.Grass, 30, 1f, 0.03f);
            GenerateForegroundStructure(foreground, radius, ForegroundTypes.Obstacle, ForegroundTypes.Empty, 50, 100, 1f, 0.2f);
            GenerateForegroundStructure(foreground, radius, ForegroundTypes.Obstacle, ForegroundTypes.Empty, 50, 70, 1f, 0.4f);
            GenerateForegroundStructure(foreground, radius, ForegroundTypes.Diamond, ForegroundTypes.Empty, 10, 100, 0f, 0f);
            GenerateForegroundStructure(foreground, radius, ForegroundTypes.Diamond, ForegroundTypes.Obstacle, 10, 100, 1f, 0.3f);
            GenerateForegroundStructure(foreground, radius, ForegroundTypes.Enemy, ForegroundTypes.Empty, 100, 100, 0.01f, 0.01f);
        }
Beispiel #2
0
        private void HideBack(CubeCoords coords)
        {
            if (!_map.MapB.ExistAt(coords))
            {
                return;
            }
            HexBackgroundComponent hexComponent = _map.MapB[coords.x, coords.y];

            if (hexComponent.Parent == null)
            {
                return;
            }
            _map.PoolB.Recycle(hexComponent.Parent);
            hexComponent.Parent = null;
        }
Beispiel #3
0
        private static void GenerateRecursiveB(HexList4D <HexBackgroundComponent> background,
                                               BackroundTypes type, BackroundTypes badType, CubeCoords coords, float chance, float diffChange)
        {
            background.Add(coords, new HexBackgroundComponent()
            {
                BackgroundType = type,
                IsNew          = false
            });
            FastList <CubeCoords> neighbours = background.NeighboursOf(coords);

            for (int j = 0; j < neighbours.Count; j++)
            {
                HexBackgroundComponent hexComponent = background[neighbours[j].x, neighbours[j].y];
                if (hexComponent.BackgroundType == badType && Random.Range(0f, 1f) < chance)
                {
                    GenerateRecursiveB(background, type, badType, neighbours[j], chance - diffChange, diffChange);
                }
            }
        }
Beispiel #4
0
        public void RenderHexBackground(CubeCoords coords)
        {
            if (!_map.MapB.ExistAt(coords) || _map.MapB[coords.x, coords.y].IsNew)
            {
                MapGenRandomNeighbours.GenerateHex(coords, _map.MapB, _map.MapF);
            }
            HexBackgroundComponent hexComponent = _map.MapB[coords.x, coords.y];

            if (hexComponent.Parent != null)
            {
                return;                                          //_poolBackground.Recycle(hexComponent.Parent);
            }
            hexComponent.Parent = _map.PoolB.Get();
            hexComponent.Parent.PoolTransform.localPosition = HexMath.Hex2Pix(coords, HexSize);
            switch (hexComponent.BackgroundType)
            {
            case BackroundTypes.Grass:
                hexComponent.Parent.PoolTransform.GetComponent <SpriteRenderer>().sprite = Grass;
                hexComponent.SpeedDown = 1;
                break;

            case BackroundTypes.Water:
                hexComponent.Parent.PoolTransform.GetComponent <SpriteRenderer>().sprite = Water;
                hexComponent.SpeedDown = 0.1f;
                break;

            case BackroundTypes.Swamp:
                hexComponent.Parent.PoolTransform.GetComponent <SpriteRenderer>().sprite = Swamp;
                hexComponent.SpeedDown = 0.02f;
                break;

            case BackroundTypes.Forest:
                hexComponent.Parent.PoolTransform.GetComponent <SpriteRenderer>().sprite = Forest;
                hexComponent.SpeedDown = 0.5f;
                break;

            default:
                throw new Exception("Null ground type");
            }
            hexComponent.Parent.PoolTransform.gameObject.SetActive(true);
        }