Exemplo n.º 1
0
        /// <summary>
        /// Gets the buffer then draws it to a <see cref="RenderTarget"/>.
        /// </summary>
        /// <param name="target">The <see cref="RenderTarget"/> to draw to.</param>
        /// <param name="camera">The <see cref="ICamera2D"/> to use when drawing.</param>
        /// <returns>True if the buffer was successfully drawn to the <paramref name="target"/>; otherwise false.</returns>
        protected bool DrawBufferToTarget(RenderTarget target, ICamera2D camera)
        {
            // Get the buffer
            var bufferImage = GetBuffer(camera);

            if (bufferImage == null)
            {
                return(false);
            }

            // Set up the sprite
            _drawToTargetSprite.Image    = bufferImage;
            _drawToTargetSprite.Width    = bufferImage.Width;
            _drawToTargetSprite.Height   = bufferImage.Height;
            _drawToTargetSprite.Position = target.ConvertCoords(0, 0).Round();
            _drawToTargetSprite.SubRect  = new IntRect(0, 0, (int)bufferImage.Width, (int)bufferImage.Height);
            PrepareDrawToTargetSprite(_drawToTargetSprite, target);

            // Draw to the target
            HandleDrawBufferToTarget(bufferImage, _drawToTargetSprite, target, camera);

            return(true);
        }
        /// <summary>
        /// Gets the buffer then draws it to a <see cref="RenderTarget"/>.
        /// </summary>
        /// <param name="target">The <see cref="RenderTarget"/> to draw to.</param>
        /// <param name="camera">The <see cref="ICamera2D"/> to use when drawing.</param>
        /// <returns>True if the buffer was successfully drawn to the <paramref name="target"/>; otherwise false.</returns>
        protected bool DrawBufferToTarget(RenderTarget target, ICamera2D camera)
        {
            // Get the buffer
            var bufferImage = GetBuffer(camera);
            if (bufferImage == null)
                return false;

            // Set up the sprite
            _drawToTargetSprite.Image = bufferImage;
            _drawToTargetSprite.Width = bufferImage.Width;
            _drawToTargetSprite.Height = bufferImage.Height;
            _drawToTargetSprite.Position = target.ConvertCoords(0, 0).Round();
            _drawToTargetSprite.SubRect = new IntRect(0, 0, (int)bufferImage.Width, (int)bufferImage.Height);
            PrepareDrawToTargetSprite(_drawToTargetSprite, target);

            // Draw to the target
            HandleDrawBufferToTarget(bufferImage, _drawToTargetSprite, target, camera);

            return true;
        }
Exemplo n.º 3
0
        public void Draw(RenderTarget rt, int layer)
        {
            Vector2f origin = rt.ConvertCoords(0, 0);
            Shape fog = Shape.Rectangle(new FloatRect(origin.X, origin.Y, rt.DefaultView.Size.X, rt.DefaultView.Size.Y), new Color(100, 149, 237, 150));

            int layerIndex = 0;
            foreach (List<Cube> cubeList in cubeLists) {

                if (layerIndex > layer)
                    break;

                foreach (Cube c in cubeList)
                    c.Draw(rt);

                foreach (Player p in playerList)
                    if (p.Layer == layerIndex)
                        p.Draw(rt);

                if (layerIndex < layer)
                    rt.Draw(fog);

                layerIndex++;
            }
        }
Exemplo n.º 4
0
        public override void Render(RenderTarget target)
        {
            //Setting view to camera position
            View view = target.GetView();
            view.Center = new Vector2f((int) CameraPosition.X, (int) CameraPosition.Y);
            target.SetView(view);

            var screenBounds = new FloatRect
            {
                Left = view.Center.X - (view.Size.X / 2),
                Top = view.Center.Y - (view.Size.Y / 2),
                Width = view.Size.X,
                Height = view.Size.Y
            };

            //Drawing map/tiles
            map.Render(target, screenBounds, Fog);

            RenderRallypoints(target);

            //Draw selected unit circles
            const float selectCircleRadius = 20;
            var selectedCircle = new CircleShape(selectCircleRadius);
            selectedCircle.OutlineColor = new Color(100, 255, 100, 200);
            selectedCircle.OutlineThickness = 5;
            selectedCircle.FillColor = new Color(0, 0, 0, 0);
            selectedCircle.Origin = new Vector2f(selectCircleRadius, selectCircleRadius);

            if (selectedUnits != null)
            {
                foreach (EntityBase entityBase in selectedUnits)
                {
                    selectedCircle.Position = entityBase.Position;
                    target.Draw(selectedCircle);
                }
            }

            var debugHPText = new Text();
            debugHPText.Scale = new Vector2f(.6f, .6f);
            debugHPText.Color = new Color(255, 255, 255, 100);
            var readOnly = new Dictionary<ushort, EntityBase>(entities);

            foreach (EntityBase entityBase in readOnly.Values)
            {
                if (entityBase.GetBounds().Intersects(screenBounds))
                {
                    if (Fog != null)
                    {
                        var coords = map.ConvertCoords(entityBase.Position);
                        entityBase.Render(target, Fog.Grid[(int) coords.X, (int) coords.Y].CurrentState);
                        if (Fog.Grid[(int)coords.X, (int)coords.Y].CurrentState == FOWTile.TileStates.CurrentlyViewed)
                        {
                            entityBase.HasBeenViewed = true;
                        }

                        debugHPText.Color = new Color(255, 255, 255, 200);
                        debugHPText.DisplayedString = "HP: " + entityBase.Health.ToString();
                        debugHPText.Origin = new Vector2f(debugHPText.GetGlobalBounds().Width/2,
                                                          debugHPText.GetGlobalBounds().Height);
                        debugHPText.Position = entityBase.Position;

                        target.Draw(debugHPText);
                        if (entityBase is BuildingBase)
                        {
                            var buildingCast = (BuildingBase) entityBase;
                            if (buildingCast.IsProductingUnit)
                            {
                                debugHPText.Color = new Color(255, 255, 0, 100);
                                debugHPText.DisplayedString = buildingCast.UnitBuildCompletePercent.ToString();
                                debugHPText.Position += new Vector2f(0, 50);
                                target.Draw(debugHPText);
                            }
                        }
                    }
                }
            }

            var readOnlyEffect = new List<EffectBase>(Effects);
            foreach (EffectBase effectBase in readOnlyEffect)
            {
                effectBase.Render(target);
            }

            if (releaseSelect)
            {
                var rect = new FloatRect(controlBoxP1.X, controlBoxP1.Y, controlBoxP2.X - controlBoxP1.X,
                                         controlBoxP2.Y - controlBoxP1.Y);
                var rectangle = new RectangleShape(new Vector2f(rect.Width, rect.Height));
                rectangle.Position = new Vector2f(rect.Left, rect.Top);
                rectangle.FillColor = new Color(100, 200, 100, 100);
                target.Draw(rectangle);
            }

            //Draw Alerts
            const int ALERTXOFFSET = 10;
            const int ALERTYMULTIPLE = 60;
            const int ALERTYOFFSET = 20;
            for (int i = 0; i < alerts.Count; i++)
            {
                HUDAlert alert = alerts[i];

                Sprite sprite = null;
                switch (alert.Type)
                {
                    case HUDAlert.AlertTypes.CreatedUnit:
                        sprite = alertHUDUnitCreated;
                        break;
                    case HUDAlert.AlertTypes.UnitUnderAttack:
                        sprite = alertHUDAlert;
                        break;
                    case HUDAlert.AlertTypes.UnitCreated:
                        sprite = alertHUDUnitCreated;
                        break;
                    case HUDAlert.AlertTypes.BuildingCompleted:
                        sprite = alertHUDBuildingCreated;
                        break;
                    default:
                        break;
                }

                if (sprite != null)
                {
                    sprite.Position = target.ConvertCoords(new Vector2i(ALERTXOFFSET, ALERTYOFFSET + ALERTYMULTIPLE*i));
                    sprite.Color = new Color(255, 255, 255, (byte) alert.Alpha);
                    target.Draw(sprite);
                }
            }

            //Draw bottom GUI
            bottomHUDGUI.Position = target.ConvertCoords(new Vector2i(0, 0));
            target.Draw(bottomHUDGUI);

            //Draw minimap
            miniMap.Render();
            miniMap.MapSprite.Position = target.ConvertCoords(new Vector2i((int)MINIMAPPOSX, (int)MINIMAPPOSY));
            target.Draw(miniMap.MapSprite);

            //Draw unit stats HUD

            if (selectedUnits != null)
            {
                if (selectedUnits.Length == 1)
                {
                    var hpText = new Text(selectedUnits[0].Health + "/" + selectedUnits[0].MaxHealth);
                    hpText.Position = target.ConvertCoords(new Vector2i(500, (int) target.Size.Y - 50));
                    hpText.Scale = new Vector2f(.7f, .7f);
                    target.Draw(hpText);

                    EntityBase priorUnit = prioritySelectedUnit();

                    Sprite unitAvatar = avatarWorker;

                    switch (priorUnit.Type)
                    {
                        case Entity.EntityType.Unit:
                            break;
                        case Entity.EntityType.Building:
                            break;
                        default:
                        case Entity.EntityType.Worker:
                            unitAvatar = avatarWorker;
                            break;
                        case Entity.EntityType.Resources:
                            break;
                        case Entity.EntityType.HomeBuilding:
                            break;
                        case Entity.EntityType.SupplyBuilding:
                            break;
                    }

                    if (unitAvatar != null)
                    {
                        unitAvatar.Position = hpText.Position - new Vector2f(50, 175);
                        target.Draw(unitAvatar);
                    }
                }
                else if (selectedUnits.Length > 1)
                {
                    const byte MAXROWCOUNT = 8;

                    byte XCount = 0, YCount = 0, IterateCount = 0;
                    for (int i = 0; i < selectedUnits.Length; i++)
                    {
                        Sprite boxSprite = hudBoxUnit;
                        if (selectedUnits[i] is BuildingBase)
                        {
                            boxSprite = hudBoxBuilding;
                        }
                        else if (selectedUnits[i] is UnitBase)
                        {
                            boxSprite = hudBoxUnit;
                        }

                        if (boxSprite != null)
                        {
                            const float XOFFSET = 300;
                            const float YOFFSET = 545;
                            const float XMULTIPLY = 55;
                            const float YMULTIPLY = 55;

                            boxSprite.Position = new Vector2f(XOFFSET + (XCount*XMULTIPLY), YOFFSET + (YCount*YMULTIPLY));
                            boxSprite.Position =
                                target.ConvertCoords(new Vector2i((int) boxSprite.Position.X, (int) boxSprite.Position.Y));
                            target.Draw(boxSprite);
                        }

                        XCount++;
                        if (XCount == MAXROWCOUNT)
                        {
                            XCount = 0;
                            YCount++;
                        }
                    }
                }
            }

            //Draw Control Groups
            const int CONTROLBOXXOFFSET = 310;
            const int CONTROLBOXYOFFSET = 505;
            const int CONTROLBOXXMULTIPLY = 55;

            int counter = 0;
            var controlNumberText = new Text("0");

            foreach (var controlGroup in controlGroups.Values)
            {
                if (controlGroup != null && controlGroup.Count > 0)
                {
                    controlNumberText.DisplayedString = (counter + 1).ToString();
                    controlNumberText.Scale = new Vector2f(.4f, .4f);
                    controlNumberText.Origin = new Vector2f((controlNumberText.GetGlobalBounds().Width/2),
                                                            (controlNumberText.GetGlobalBounds().Height/2));

                    hudControlBox.Position =
                        target.ConvertCoords(new Vector2i(CONTROLBOXXOFFSET + CONTROLBOXXMULTIPLY*counter,
                                                          CONTROLBOXYOFFSET));
                    controlNumberText.Position = hudControlBox.Position + new Vector2f(0, 24);
                    target.Draw(hudControlBox);
                    target.Draw(controlNumberText);

                    controlNumberText.DisplayedString = controlGroup.Count.ToString();
                    controlNumberText.Position = hudControlBox.Position + new Vector2f(0, 5);
                    controlNumberText.Scale = new Vector2f(.7f, .7f);
                    target.Draw(controlNumberText);
                }
                counter++;
            }

            if (myPlayer != null)
            {
                debugHPText.Origin = new Vector2f(0, 0);
                debugHPText.Scale = new Vector2f(.5f, .5f);
                debugHPText.Position = target.ConvertCoords(new Vector2i(0, 0));
                debugHPText.DisplayedString = "APL: " + myPlayer.Apples.ToString();
                target.Draw(debugHPText);

                debugHPText.Position += new Vector2f(100, 0);
                debugHPText.DisplayedString = "GLU: " + myPlayer.Glue.ToString();
                target.Draw(debugHPText);

                debugHPText.Position += new Vector2f(100, 0);
                debugHPText.DisplayedString = "WOD: " + myPlayer.Wood.ToString();
                target.Draw(debugHPText);

                debugHPText.Position += new Vector2f(100, 0);
                debugHPText.DisplayedString = "SUP: " + myPlayer.UsedSupply.ToString() + "/" + myPlayer.Supply;
                target.Draw(debugHPText);
            }

            if (CurrentStatus == StatusState.WaitingForPlayers)
            {
                var shape = new RectangleShape(new Vector2f(target.Size.X, target.Size.Y));
                shape.Position = target.ConvertCoords(new Vector2i(0, 0));
                shape.FillColor = new Color(0, 0, 0, 200);
                target.Draw(shape);

                var text = new Text("Waiting for Players...");
                text.Position = target.ConvertCoords(new Vector2i((int) target.Size.X/2, (int) target.Size.Y/2));
                text.Origin = new Vector2f(text.GetGlobalBounds().Width/2, text.GetGlobalBounds().Height/2);
                text.Color = new Color(255, 255, 255, 100);
                target.Draw(text);
            }

            if (CurrentStatus == StatusState.Completed)
            {
                var text = new Text("Game Completed...");
                text.Position = target.ConvertCoords(new Vector2i((int) target.Size.X/2, 10));
                text.Origin = new Vector2f(text.GetGlobalBounds().Width/2, 0);
                text.Color = new Color(255, 255, 255, 100);
                target.Draw(text);
            }

            viewBounds.Position = target.ConvertCoords(new Vector2i(0, 0));
            target.Draw(viewBounds);
        }
Exemplo n.º 5
0
        public override void Render(RenderTarget target)
        {
            var renderName = new Text(PlayerName);
            renderName.Position = target.ConvertCoords(new Vector2i(10, 10));
            renderName.Scale = new Vector2f(.6f, .6f);
            target.Draw(renderName);

            var gameName = new Text("MY LITTLE GLUE FACTORY");
            gameName.Scale = new Vector2f(1, 1);
            gameName.Origin = new Vector2f(gameName.GetGlobalBounds().Width/2, gameName.GetGlobalBounds().Height/2);
            gameName.Position = target.ConvertCoords(new Vector2i((int) target.Size.X/2, 10));
            target.Draw(gameName);

            for(var i = 0; i < options.Count; i++)
            {
                if(selectedOption == i)
                {
                    target.Draw(options[i][1]);
                }
                else
                {
                    target.Draw(options[i][0]);
                }
            }
        }