public StatusLine(StatusLineType type)
 {
     _belowLine = GameGraphics.GetTexture("red_bar");
     if (type == StatusLineType.Green)
         _topLine = GameGraphics.GetTexture("green_bar");
     else _topLine = GameGraphics.GetTexture("yellow_bar");
 }
        public FarmBase(string identifier, GameWorld gameWorldRef, GamePlayer playerRef, Point location)
        {
            Texture = GameGraphics.GetTexture(identifier);
            Location = location;
            _gameWorldRef = gameWorldRef;
            PlayerRef = playerRef;
            MapRef = _gameWorldRef.Map;

            _drawDepth = 1.0f - TileEngineInfo.HeightRowDepthMod;

            _rowOffset = (MapRef.MapCellAt(location).OnOddRow) ? TileInfo.OddRowXOffset : 0;

            FarmOrigin =
               new Vector2((Location.X * TileInfo.TileStepX) + _rowOffset + Texture.AlignmentOffset.X,
                   Location.Y * TileInfo.TileStepY - Texture.AlignmentOffset.Y);
        }
        protected CreatureBase(string animationIdentifier, 
            int frameWidth, int frameHeight, int frames,
            GameWorld gameWorldRef, GamePlayer playerRef, Vector2 position, float animationSpeed)
        {
            PlayerRef = playerRef;
            GameWorldRef = gameWorldRef;
            _mapRef = gameWorldRef.Map ;

            // walking animation is unified in all creatures
            #region setting appropriate walking animation
            AnimationSet = GameGraphics.GetTexture(animationIdentifier);
            Animation = new SpriteAnimation(AnimationSet.SourceTexture);

            Animation.AddAnimation("Walk_E", 0, frameHeight * 0, frameWidth, frameHeight, frames, animationSpeed);
            Animation.AddAnimation("Walk_N", 0, frameHeight * 1, frameWidth, frameHeight, frames, animationSpeed);
            Animation.AddAnimation("Walk_NE", 0, frameHeight * 2, frameWidth, frameHeight, frames, animationSpeed);
            Animation.AddAnimation("Walk_NW", 0, frameHeight * 3, frameWidth, frameHeight, frames, animationSpeed);
            Animation.AddAnimation("Walk_S", 0, frameHeight * 4, frameWidth, frameHeight, frames, animationSpeed);
            Animation.AddAnimation("Walk_SE", 0, frameHeight * 5, frameWidth, frameHeight, frames, animationSpeed);
            Animation.AddAnimation("Walk_SW", 0, frameHeight * 6, frameWidth, frameHeight, frames, animationSpeed);
            Animation.AddAnimation("Walk_W", 0, frameHeight * 7, frameWidth, frameHeight, frames, animationSpeed);

            Animation.AddAnimation("Idle_E", 3 * frameWidth, frameHeight * 0, frameWidth, frameHeight, 1, 0.2f);
            Animation.AddAnimation("Idle_N", 3 * frameWidth, frameHeight * 1, frameWidth, frameHeight, 1, 0.2f);
            Animation.AddAnimation("Idle_NE", 3 * frameWidth, frameHeight * 2, frameWidth, frameHeight, 1, 0.2f);
            Animation.AddAnimation("Idle_NW", 3 * frameWidth, frameHeight * 3, frameWidth, frameHeight, 1, 0.2f);
            Animation.AddAnimation("Idle_S", 3 * frameWidth, frameHeight * 4, frameWidth, frameHeight, 1, 0.2f);
            Animation.AddAnimation("Idle_SE", 3 * frameWidth, frameHeight * 5, frameWidth, frameHeight, 1, 0.2f);
            Animation.AddAnimation("Idle_SW", 3 * frameWidth, frameHeight * 6, frameWidth, frameHeight, 1, 0.2f);
            Animation.AddAnimation("Idle_W", 3 * frameWidth, frameHeight * 7, frameWidth, frameHeight, 1, 0.2f);

            CurrentAnimation = "Idle_SE";

            Animation.IsAnimating = true;

            #endregion

            Position = position;
            _currentMoveDir = Vector2.Zero;
            _previousMovDir = Vector2.Zero;
            Distination = position;

            HealthStatusLine = new StatusLine(StatusLineType.Green);
            _healthStatusLineOffset = new Vector2(-13, -50);

            Actions = new ActionManager();
        }
        public Tree(string Identifier, GameWorld gameWorldRef, Point Location)
        {
            this.texture = GameGraphics.GetTexture(Identifier);
            _gameWorldRef = gameWorldRef;
            this.Location = Location;
            this.MapRef = _gameWorldRef.Map;

             rowOffset = (MapRef.MapCellAt(Location).OnOddRow) ? TileInfo.OddRowXOffset : 0;
             depth = MapRef.MapCellAt(Location).DrawDepth;

            // make tree place unwalkable..
            MapRef.MapCellAt(Location).Walkable = false;
            // add tree shadow to base tiles of the occupied cell..
            MapRef.MapCellAt(Location).AddTopperTile("tree_shadow");
            Position = new Vector2((Location.X * TileInfo.TileStepX) + rowOffset + texture.AlignmentOffset.X,
                Location.Y * TileInfo.TileStepY - texture.AlignmentOffset.Y);
            SelectionBox = new Rectangle((int)Position.X, (int)Position.Y, texture.SourceRectangle.Width, texture.SourceRectangle.Height);
        }
        public int GetSlopeMapHeight(Point localPixel, Texture slopeMap)
        {
            if (slopeMap == null) return 0;

            Color[] slopeColor = new Color[1];

            slopeMap.SourceTexture.GetData(
                0,
                new Rectangle(localPixel.X + slopeMap.SourceRectangle.X, localPixel.Y + slopeMap.SourceRectangle.Y, 1, 1),
                slopeColor,
                0,
                1);

            int offset = (int)(((float)(255 - slopeColor[0].R) / 255f) * TileInfo.HeightTileOffset);

            return offset;
        }
        protected BuildingBase(string identifier, GameWorld gameWorldRef, GamePlayer playerRef, Point location)
        {
            Texture = GameGraphics.GetTexture(identifier);
            Location = location;
            GameWorldRef = gameWorldRef;
            MapRef = gameWorldRef.Map;
            PlayerRef = playerRef;

            var rowOffset = (MapRef.MapCellAt(location).OnOddRow) ? TileInfo.OddRowXOffset : 0;

            BuildingOrigin =
                new Vector2((location.X * TileInfo.TileStepX) + rowOffset + Texture.AlignmentOffset.X,
                    location.Y * TileInfo.TileStepY - Texture.AlignmentOffset.Y);

            #region Build Segments of the texture..
            var imgSegmentsF = new List<Rectangle>();
            var imgSegmentsB = new List<Rectangle>();

            var segWidth = TileInfo.TileWidth / 2; // seg_width = 32

            var doubleDivision = (Texture.SourceRectangle.Width / 2.0) / segWidth;
            var intDivision = (double)((int)doubleDivision);
            // check if image width not devided by half of tile width (32)
            const double epsilon = 0.01f;
            var isOverloaded = (!(Math.Abs(doubleDivision - intDivision) < epsilon));

            int height = Texture.SourceRectangle.Height;
            int mid = Texture.SourceRectangle.Width / 2;

            int forwardIndexer = mid;
            int backwardIndexer = mid - segWidth;

            for (int i = 0; i < intDivision; i++)
            {
                var rectForward = new Rectangle(forwardIndexer, Texture.SourceRectangle.Y, segWidth, height);
                var rectBackward = new Rectangle(backwardIndexer, Texture.SourceRectangle.Y, segWidth, height);

                imgSegmentsB.Add(rectBackward);
                imgSegmentsF.Add(rectForward);

                forwardIndexer += segWidth;
                backwardIndexer -= segWidth;
            }

            // next, using latest value of forward_indexer
            if (isOverloaded)
            {
                var leftSegWidth = mid - (int)intDivision * segWidth;
                var lastRectRight = new Rectangle(/**/forwardIndexer/**/, Texture.SourceRectangle.Y, leftSegWidth, height);
                var lastRectLeft = new Rectangle(Texture.SourceRectangle.X, Texture.SourceRectangle.Y, leftSegWidth, height);

                imgSegmentsB.Add(lastRectLeft);
                imgSegmentsF.Add(lastRectRight);
            }

            // setting depths of segments..
            var indexer = location;
            _imgSegmentsDepths = new List<SegDepth>();

            // first forward and backward segments have same depth as cell at this building's Location
            var depth = MapRef.MapCellAt(location).DrawDepth;
            _imgSegmentsDepths.Add(new SegDepth(imgSegmentsF[0], depth));
            _imgSegmentsDepths.Add(new SegDepth(imgSegmentsB[0], depth));

            // moving to the tiles on the right..
            for (var i = 1; i < imgSegmentsF.Count; i++)
            {
                indexer = indexer.WalkTo(Direction.NE);
                depth = MapRef.MapCellAt(indexer).DrawDepth;
                _imgSegmentsDepths.Add(new SegDepth(imgSegmentsF[i], depth));
            }

            //resetting
            indexer = location;

            // moving to the tiles on the left..
            for (int i = 1; i < imgSegmentsB.Count; i++)
            {
                indexer = indexer.WalkTo(Direction.NW);
                depth = MapRef.MapCellAt(indexer).DrawDepth;
                _imgSegmentsDepths.Add(new SegDepth(imgSegmentsB[i], depth));
            }

            // constructing an ordered version of the img_segments_depths list..
            ImgSegmentsDepthsOrdered = new List<SegDepth>();
            for (int i = _imgSegmentsDepths.Count - 1; i >= _imgSegmentsDepths.Count - (imgSegmentsB.Count - 1); i--)
            {
                ImgSegmentsDepthsOrdered.Add(_imgSegmentsDepths[i]);
            }
            ImgSegmentsDepthsOrdered.Add(_imgSegmentsDepths[1]);
            ImgSegmentsDepthsOrdered.Add(_imgSegmentsDepths[0]);

            for (int i = 2; i < (imgSegmentsF.Count - 1) + 2; i++)
            {
                ImgSegmentsDepthsOrdered.Add(_imgSegmentsDepths[i]);
            }

            ///
            /// now, img_segments_depths_ordered is constructed properly
            /// so that it can be used to access and / or modify the segments of
            /// the building in the child classes of this class
            ///

            #endregion

            #region Generating Built Units Locations and idle animations
            BuiltUnitsLocations = new List<Vector2>();
            var cells = new List<Point>();
            var index = Location;
            index = index.WalkTo(Direction.S).WalkTo(Direction.NE)
                .WalkTo(Direction.NE).WalkTo(Direction.NE);
            cells.Add(index);
            index = index.WalkTo(Direction.SW);
            cells.Add(index);
            index = index.WalkTo(Direction.SW);
            cells.Add(index);
            index = index.WalkTo(Direction.SW);
            cells.Add(index);
            index = index.WalkTo(Direction.NW);
            cells.Add(index);
            index = index.WalkTo(Direction.NW);
            cells.Add(index);
            index = index.WalkTo(Direction.NW);
            cells.Add(index);
            _builtUnitIndex = 0;
            foreach (var point in cells)
            {
                BuiltUnitsLocations.Add(MapRef.MapCellAt(point).CenterPosition);
            }

            // setting initial idle animations to look away from building
            InitialIdleAnimation = new List<string>();
            InitialIdleAnimation.Add("Idle_SE");
            InitialIdleAnimation.Add("Idle_SE");
            InitialIdleAnimation.Add("Idle_SE");
            InitialIdleAnimation.Add("Idle_S");
            InitialIdleAnimation.Add("Idle_SW");
            InitialIdleAnimation.Add("Idle_SW");
            InitialIdleAnimation.Add("Idle_S");
            InitialIdleAnimation.Add("Idle_SW");
            InitialIdleAnimation.Add("Idle_SW");
            #endregion
        }