Ejemplo n.º 1
0
        public void Draw(SpriteBatch spriteBatch)
        {
            /*spriteBatch.Draw(base.Texture, new Rectangle((int)UpperLeftCorner.X, (int)UpperLeftCorner.Y, 4, 4), Color.White);
             * spriteBatch.Draw(base.Texture, new Rectangle((int)UpperRightCorner.X, (int)UpperRightCorner.Y, 4, 4), Color.White);
             * spriteBatch.Draw(base.Texture, new Rectangle((int)LowerLeftCorner.X, (int)LowerLeftCorner.Y, 4, 4), Color.White);
             * spriteBatch.Draw(base.Texture, new Rectangle((int)LowerRightCorner.X, (int)LowerRightCorner.Y, 4, 4), Color.White);
             */
            Vector2 vector1 = LowerLeftCorner, vector2 = LowerRightCorner;

            float angle = (float)Math.Atan2((double)(UpperLeftCorner.Y - LowerLeftCorner.Y), (double)UpperLeftCorner.X - LowerLeftCorner.X);

            //spriteBatch.Draw(Texture, new Rectangle(X, Y, Width, Height), null, Color.White, Rotation, new Vector2(Texture.Width / 2, Texture.Height / 2), SpriteEffects.None, 0f);

            line.ClearVectors();
            line.AddVector(vector1);
            line.AddVector(vector2);
            line.Render(spriteBatch, Rotation);

            while (Vector2.Distance(vector1, UpperLeftCorner) > .5f)
            {
                Vector2 adjustment = new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle));
                vector1 += adjustment;
                vector2 += adjustment;

                line.ClearVectors();
                line.AddVector(vector1);
                line.AddVector(vector2);
                line.Render(spriteBatch, Rotation);
            }

            /*line.ClearVectors();
             * line.AddVector(new Vector2(UpperLeftCorner.X, UpperLeftCorner.Y));
             * line.AddVector(new Vector2(UpperRightCorner.X, UpperRightCorner.Y));
             * line.Render(spriteBatch, Rotation);*/
        }
Ejemplo n.º 2
0
        public void Draw(SpriteBatch spriteBatch)
        {
            if (Bits.Count > 0)
            {
                BaseObject frontBit = Bits[0], endBit = Bits[Bits.Count - 1];
                for (int i = 0; i < size; i++)
                {
                    line.ClearVectors();
                    line.AddVector(new Vector2(endBit.X + i, endBit.Y));
                    line.AddVector(new Vector2(frontBit.X + i, frontBit.Y));
                    line.Render(spriteBatch, angle);

                    line.ClearVectors();
                    line.AddVector(new Vector2(endBit.X, endBit.Y + i));
                    line.AddVector(new Vector2(frontBit.X, frontBit.Y + i));
                    line.Render(spriteBatch, angle);

                    line.ClearVectors();
                    line.AddVector(new Vector2(endBit.X + size, endBit.Y + i));
                    line.AddVector(new Vector2(frontBit.X + size, frontBit.Y + i));
                    line.Render(spriteBatch, angle);

                    line.ClearVectors();
                    line.AddVector(new Vector2(endBit.X + i, endBit.Y + size));
                    line.AddVector(new Vector2(frontBit.X + i, frontBit.Y + size));
                    line.Render(spriteBatch, angle);
                }
                spriteBatch.Draw(frontBit.Texture, frontBit, Color.White);
                //spriteBatch.Draw(frontBit.Texture, new Rectangle((int)frontBit.CenterPoint.X, (int)frontBit.CenterPoint.Y, frontBit.Width, frontBit.Height), null, Color.White, frontBit.Rotation, frontBit.TextureCenterOrigin, SpriteEffects.None, 0f);
            }
        }
Ejemplo n.º 3
0
        public static void Draw(SpriteBatch spriteBatch, Camera camera)
        {
            if (!enabled || !selecting)
            {
                return;
            }

            /*selectBoxLine.ClearVectors();
             * selectBoxLine.AddVector(selectBox.UpperLeftCorner);
             * selectBoxLine.AddVector(selectBox.UpperRightCorner);
             * selectBoxLine.Render(spriteBatch);
             *
             * selectBoxLine.ClearVectors();
             * selectBoxLine.AddVector(selectBox.UpperLeftCorner);
             * selectBoxLine.AddVector(selectBox.LowerLeftCorner);
             * selectBoxLine.Render(spriteBatch);
             *
             * selectBoxLine.ClearVectors();
             * selectBoxLine.AddVector(selectBox.LowerLeftCorner);
             * selectBoxLine.AddVector(selectBox.LowerRightCorner);
             * selectBoxLine.Render(spriteBatch);
             *
             * selectBoxLine.ClearVectors();
             * selectBoxLine.AddVector(selectBox.UpperRightCorner);
             * selectBoxLine.AddVector(selectBox.LowerRightCorner);
             * selectBoxLine.Render(spriteBatch);
             */
            //

            selectBoxLine.ClearVectors();
            selectBoxLine.AddVector(new Vector2(drawBox.X, drawBox.Y));
            selectBoxLine.AddVector(new Vector2(drawBox.X + drawBox.Width, drawBox.Y));
            selectBoxLine.Render(spriteBatch);

            selectBoxLine.ClearVectors();
            selectBoxLine.AddVector(new Vector2(drawBox.X, drawBox.Y));
            selectBoxLine.AddVector(new Vector2(drawBox.X, drawBox.Y + drawBox.Height));
            selectBoxLine.Render(spriteBatch);

            selectBoxLine.ClearVectors();
            selectBoxLine.AddVector(new Vector2(drawBox.X, drawBox.Y + drawBox.Height));
            selectBoxLine.AddVector(new Vector2(drawBox.X + drawBox.Width, drawBox.Y + drawBox.Height));
            selectBoxLine.Render(spriteBatch);

            selectBoxLine.ClearVectors();
            selectBoxLine.AddVector(new Vector2(drawBox.X + drawBox.Width, drawBox.Y));
            selectBoxLine.AddVector(new Vector2(drawBox.X + drawBox.Width, drawBox.Y + drawBox.Height));
            selectBoxLine.Render(spriteBatch);
        }
Ejemplo n.º 4
0
        public override void Draw(GameTime gameTime)
        {
            if (!enabled || lines.Count == 0)
            {
                return;
            }

            boxVectors = new Vector2[4];

            int biggestLineX = 0;

            foreach (string line in lines)
            {
                int lineX = (int)font.MeasureString(line).X;
                if (lineX > biggestLineX)
                {
                    biggestLineX = lineX;
                }
            }
            int lineSizeY = (int)font.MeasureString(lines[0]).Y;

            spriteBatch.Begin();

            int spacing = 2;

            if (position == Direction.North)
            {
            }
            else if (position == Direction.NorthEast)
            {
                int posX = Game.GraphicsDevice.Viewport.Width - biggestLineX;
                int posY = 2;

                for (int i = 0; i < lines.Count; i++)
                {
                    string line = lines[i];

                    if (i == 0)
                    {
                        boxVectors[0] = new Vector2(posX - 6, posY);
                        boxVectors[1] = new Vector2(Game.GraphicsDevice.Viewport.Width, posY);
                    }
                    else if (i == lines.Count - 1)
                    {
                        boxVectors[3] = new Vector2(posX - 6, posY + lineSizeY);
                        boxVectors[2] = new Vector2(Game.GraphicsDevice.Viewport.Width, posY + lineSizeY);
                    }

                    spriteBatch.DrawString(font, line, new Vector2((int)(Game.GraphicsDevice.Viewport.Width - biggestLineX - 2), posY), Color.Black);
                    posY += (int)lineSizeY + spacing;
                }
            }
            else if (position == Direction.East)
            {
            }
            else if (position == Direction.SouthEast)
            {
                int posX = Game.GraphicsDevice.Viewport.Width - biggestLineX;
                int posY = Game.GraphicsDevice.Viewport.Height - lineSizeY * lines.Count - 2;

                for (int i = 0; i < lines.Count; i++)
                {
                    string line = lines[i];

                    if (i == 0)
                    {
                        boxVectors[0] = new Vector2(posX - 5, posY);
                        boxVectors[1] = new Vector2(Game.GraphicsDevice.Viewport.Width - 1, posY);
                    }
                    if (i == lines.Count - 1)
                    {
                        boxVectors[2] = new Vector2(Game.GraphicsDevice.Viewport.Width - 1, posY + lineSizeY);
                        boxVectors[3] = new Vector2(posX - 5, posY + lineSizeY);
                    }

                    spriteBatch.DrawString(font, line, new Vector2((int)(Game.GraphicsDevice.Viewport.Width - biggestLineX - 2), posY), Color.Black);
                    posY += lineSizeY;
                }
            }
            else if (position == Direction.South)
            {
            }
            else if (position == Direction.SouthWest)
            {
            }
            else if (position == Direction.West)
            {
            }
            else if (position == Direction.NorthWest)
            {
            }

            if (drawBox)
            {
                boxLine.ClearVectors();
                foreach (Vector2 v in boxVectors)
                {
                    boxLine.AddVector(v);
                }
                boxLine.AddVector(boxVectors[0]);
                boxLine.Render(spriteBatch);
            }

            spriteBatch.End();

            lines.Clear();

            base.Draw(gameTime);
        }
Ejemplo n.º 5
0
        public override void Draw(SpriteBatch spriteBatch)
        {
            Game1.Game.DebugMonitor.AddLine("camera position: " + camera.Pos);
            Game1.Game.DebugMonitor.AddLine("camera zoom: " + camera.Zoom);
            Game1.Game.DebugMonitor.AddLine("camera rotation: " + camera.Rotation);
            Game1.Game.DebugMonitor.AddLine("pathfinding usage: " + pathFindingPercentage.ToString("F1") + "%");

            GraphicsDevice.Clear(Color.Gray);

            spriteBatch.End();
            GraphicsDevice.Viewport = worldViewport;
            spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, camera.get_transformation(worldViewport));

            drawMap(spriteBatch);

            // units
            foreach (BaseObject unit in Unit.Units)
                spriteBatch.Draw(unit.Texture, new Rectangle((int)unit.CenterPoint.X, (int)unit.CenterPoint.Y, unit.Width, unit.Height), null, Color.White, unit.Rotation, unit.TextureCenterOrigin, SpriteEffects.None, 0f);

            // selection rings
            foreach (Unit unit in SelectingUnits)
                //drawSelectionRing(unit, spriteBatch, Color.Green);
                drawSelectingRing(unit, spriteBatch);
            foreach (Unit unit in SelectedUnits)
                //drawSelectionRing(unit, spriteBatch, Color.Khaki);
                drawSelectedRing(unit, spriteBatch);

            // unit animations
            foreach (UnitAnimation a in UnitAnimation.UnitAnimations)
                spriteBatch.Draw(a, new Rectangle(a.Rectangle.Center.X, a.Rectangle.Center.Y, a.Rectangle.Width, a.Rectangle.Height), null, Color.White, a.Rotation, new Vector2(((Texture2D)a).Width / 2, ((Texture2D)a).Height / 2), SpriteEffects.None, 0f);

            foreach (Unit unit in Unit.Units)
            {
                if (unit.IsMoving)
                {
                    selectionRingLine.ClearVectors();
                    selectionRingLine.AddVector(unit.CenterPoint);
                    //foreach (Vector2 v in unit.WayPoints)
                    //    selectionRingLine.AddVector(v);
                    foreach (MoveCommand command in unit.Commands)
                    {
                        if (command is AttackCommand)
                            selectionRingLine.Colour = Color.Red;
                        else
                            selectionRingLine.Colour = Color.Green;

                        foreach (Vector2 v in command.WayPoints)
                            selectionRingLine.AddVector(v);

                        selectionRingLine.Render(spriteBatch);
                        selectionRingLine.ClearVectors();
                        selectionRingLine.AddVector(command.Destination);
                    }
                }
            }

            if (SelectedUnits.Count == 1)
            {
                PrimitiveLine line = new PrimitiveLine(GraphicsDevice, 1);
                line.Colour = Color.Black;
                lock (SelectedUnits[0].PotentialCollisionsLock)
                {
                    foreach (Unit unit in SelectedUnits[0].PotentialCollisions)
                    {
                        line.ClearVectors();
                        line.AddVector(SelectedUnits[0].CenterPoint);
                        line.AddVector(unit.CenterPoint);
                        line.Render(spriteBatch);
                    }
                }
                line.Colour = Color.Red;
                line.ClearVectors();
                line.AddVector(new Vector2(SelectedUnits[0].CurrentPathNode.Tile.X, SelectedUnits[0].CurrentPathNode.Tile.Y));
                line.AddVector(new Vector2(SelectedUnits[0].CurrentPathNode.Tile.X + SelectedUnits[0].CurrentPathNode.Tile.Width, SelectedUnits[0].CurrentPathNode.Tile.Y));
                line.AddVector(new Vector2(SelectedUnits[0].CurrentPathNode.Tile.X + SelectedUnits[0].CurrentPathNode.Tile.Width, SelectedUnits[0].CurrentPathNode.Tile.Y + SelectedUnits[0].CurrentPathNode.Tile.Height));
                line.AddVector(new Vector2(SelectedUnits[0].CurrentPathNode.Tile.X, SelectedUnits[0].CurrentPathNode.Tile.Y + SelectedUnits[0].CurrentPathNode.Tile.Height));
                line.AddVector(new Vector2(SelectedUnits[0].CurrentPathNode.Tile.X, SelectedUnits[0].CurrentPathNode.Tile.Y));
                line.Render(spriteBatch);
                line.Colour = Color.Black;
                foreach (MapTile tile in SelectedUnits[0].CurrentPathNode.Tile.Neighbors)
                {
                    line.ClearVectors();
                    line.AddVector(new Vector2(tile.X, tile.Y));
                    line.AddVector(new Vector2(tile.X + tile.Width, tile.Y));
                    line.AddVector(new Vector2(tile.X + tile.Width, tile.Y + tile.Height));
                    line.AddVector(new Vector2(tile.X, tile.Y + tile.Height));
                    line.AddVector(new Vector2(tile.X, tile.Y));
                    line.Render(spriteBatch);
                }
            }

            // bullets
            foreach (RtsBullet b in RtsBullet.RtsBullets)
                spriteBatch.Draw(b.Texture, b, Color.White);

            // move command shrinker things
            foreach (Shrinker shrinker in Shrinker.Shrinkers)
                spriteBatch.Draw(shrinker.Texture, shrinker, Color.White);
                //spriteBatch.Draw(shrinker.Texture, new Rectangle((int)shrinker.CenterPoint.X, (int)shrinker.CenterPoint.Y, shrinker.Width, shrinker.Height), null, Color.White, shrinker.Rotation, shrinker.TextureCenterOrigin, SpriteEffects.None, 0f);

            spriteBatch.End();
            spriteBatch.Begin();

            GraphicsDevice.Viewport = uiViewport;

            SelectBox.Draw(spriteBatch, camera);

            drawMinimap(spriteBatch);

            //pause and fps count
            Vector2 pauseStringSize = pauseFont.MeasureString("PAUSED");
            if (paused)
                spriteBatch.DrawString(pauseFont, "PAUSED", new Vector2(uiViewport.Width / 2 - pauseStringSize.X / 2, uiViewport.Height / 2 - pauseStringSize.Y / 2), Color.White);
            else
                frameCounter++;

            // fps message
            spriteBatch.DrawString(fpsFont, fpsMessage, new Vector2(8, 5), Color.Black);

            spriteBatch.Draw(buttonTexture, button1, Color.White);
            spriteBatch.DrawString(fpsFont, "1", new Vector2((int)(button1.X + button1.Width / 2 - fpsFont.MeasureString("1").X / 2), (int)(button1.Y + button1.Height / 2 - fpsFont.MeasureString("1").Y / 2)), Color.White);
            spriteBatch.Draw(buttonTexture, button2, Color.White);
            spriteBatch.DrawString(fpsFont, "10", new Vector2((int)(button2.X + button2.Width / 2 - fpsFont.MeasureString("10").X / 2), (int)(button2.Y + button2.Height / 2 - fpsFont.MeasureString("10").Y / 2)), Color.White);
            spriteBatch.Draw(buttonTexture, button3, Color.White);
            spriteBatch.DrawString(fpsFont, "FS", new Vector2((int)(button3.X + button3.Width / 2 - fpsFont.MeasureString("FS").X / 2), (int)(button3.Y + button3.Height / 2 - fpsFont.MeasureString("FS").Y / 2)), Color.White);

            // cursor
            /*if (usingAttackCommand)
                spriteBatch.Draw(attackCommandCursorTexture, new Rectangle(mouseState.X - attackCommandCursorSize / 2, mouseState.Y - attackCommandCursorSize / 2, attackCommandCursorSize, attackCommandCursorSize), Color.White);
            else
                spriteBatch.Draw(normalCursorTexture, new Rectangle(mouseState.X, mouseState.Y, attackCommandCursorSize, attackCommandCursorSize), Color.White);*/
        }