Esempio n. 1
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);
        }
Esempio n. 2
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);
        }