Beispiel #1
0
        public void Run()
        {
            //todo move into IEnumerator
            CubeCoords playerCoords = HexMath.Pix2Hex(_player.Transform.localPosition.x, _player.Transform.localPosition.y, HexSize);

            if (_map.LastCoords.x != playerCoords.x || _map.LastCoords.y != playerCoords.y)
            {
                UnrenderRing(_map.LastCoords, Fow + 1);
                RenderRing(playerCoords, Fow);
                _map.LastCoords = playerCoords;
            }

            for (int i = 0; i < _collisionEvents.EntitiesCount; i++)
            {
                CubeCoords coords = HexMath.Pix2Hex(_collisionEvents.Components1[i].ObstacleTransform.position, HexSize);
            }
            for (int i = 0; i < _triggerForegroundEvents.EntitiesCount; i++)
            {
                CubeCoords             coords       = HexMath.Pix2Hex(_triggerForegroundEvents.Components1[i].ObstacleTransform.position, HexSize);
                HexForegroundComponent hexComponent = _map.MapF[coords.x, coords.y];
                switch (hexComponent.ForegroundType)
                {
                case ForegroundTypes.Diamond:
                    _player.Exp += hexComponent.Value;
                    RemoveFore(hexComponent, coords);
                    break;

                default:
                    break;
                }
            }
        }
Beispiel #2
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 #3
0
        private void RenderHexForeground(CubeCoords coords)
        {
            if (!_map.MapF.ExistAt(coords) || _map.MapF[coords.x, coords.y].IsNew)
            {
                return;
            }
            HexForegroundComponent foregroundHexComponent = _map.MapF[coords.x, coords.y];

            if (foregroundHexComponent.ForegroundType == ForegroundTypes.Empty)
            {
                return;
            }
            if (foregroundHexComponent.Parent != null)
            {
                return;                                                    //_poolForeground.Recycle(foregroundHexComponent.Parent);
            }
            foregroundHexComponent.Parent = _map.PoolF.Get();
            foregroundHexComponent.Parent.PoolTransform.localPosition = HexMath.Hex2Pix(coords, HexSize);
            switch (foregroundHexComponent.ForegroundType)
            {
            case ForegroundTypes.Empty:
                foregroundHexComponent.Parent.PoolTransform.GetComponent <SpriteRenderer>().sprite = null;
                foregroundHexComponent.Parent.PoolTransform.GetComponent <Collider2D>().enabled    = false;
                return;

            case ForegroundTypes.Enemy:
                foregroundHexComponent.Parent.PoolTransform.GetComponent <SpriteRenderer>().sprite = Enemy;
                foregroundHexComponent.Parent.PoolTransform.GetComponent <Collider2D>().enabled    = true;
                foregroundHexComponent.Parent.PoolTransform.GetComponent <Collider2D>().isTrigger  = false;
                break;

            case ForegroundTypes.Obstacle:
                foregroundHexComponent.Parent.PoolTransform.GetComponent <SpriteRenderer>().sprite = Obstacle;
                foregroundHexComponent.Parent.PoolTransform.GetComponent <Collider2D>().enabled    = true;
                foregroundHexComponent.Parent.PoolTransform.GetComponent <Collider2D>().isTrigger  = false;
                break;

            case ForegroundTypes.Diamond:
                foregroundHexComponent.Parent.PoolTransform.GetComponent <SpriteRenderer>().sprite = Diamond;
                foregroundHexComponent.Parent.PoolTransform.GetComponent <Collider2D>().enabled    = true;
                foregroundHexComponent.Parent.PoolTransform.GetComponent <Collider2D>().isTrigger  = true;
                break;

            case ForegroundTypes.Spawn:
                //spawn point, dunno why
                foregroundHexComponent.Parent.PoolTransform.GetComponent <SpriteRenderer>().sprite = null;
                foregroundHexComponent.Parent.PoolTransform.GetComponent <Collider2D>().enabled    = false;
                break;

            default:
                throw new Exception("Null object type");
            }
            foregroundHexComponent.Parent.PoolTransform.gameObject.SetActive(true);
        }
Beispiel #4
0
        private void HideFore(CubeCoords coords)
        {
            if (!_map.MapF.ExistAt(coords))
            {
                return;
            }
            HexForegroundComponent foregroundHexComponent = _map.MapF[coords.x, coords.y];

            if (foregroundHexComponent.Parent == null)
            {
                return;
            }
            _map.PoolF.Recycle(foregroundHexComponent.Parent);
            foregroundHexComponent.Parent = null;
        }
Beispiel #5
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);
                }
            }
        }
Beispiel #6
0
 private void RemoveFore(HexForegroundComponent hexComponent, CubeCoords coords)
 {
     _map.PoolF.Recycle(hexComponent.Parent);
     _map.MapF.ClearAt(coords);
 }