Ejemplo n.º 1
0
        public override void Initialize()
        {
            spriteBatch = new SpriteBatch(Game.GraphicsDevice);

            lines = new List <string>();

            boxLine        = new PrimitiveLine(Game.GraphicsDevice, 1);
            boxLine.Colour = Color.Black;
            boxVectors     = new Vector2[4];

            base.Initialize();
        }
Ejemplo n.º 2
0
        public Rts(EventHandler callback)
            : base(callback)
        {
            Game1.Game.DebugMonitor.Position = Direction.NorthEast;
            //Game1.Game.IsMouseVisible = false;
            //Game1.Game.Graphics.SynchronizeWithVerticalRetrace = false;
            //Game1.Game.IsFixedTimeStep = false;
            //Game1.Game.Graphics.ApplyChanges();

            map = new Map(@"Content/map1.txt");
            Unit.Map = map;
            actualMapWidth = map.Width * map.TileSize;
            actualMapHeight = map.Height * map.TileSize;

            Unit.UnitCollisionSweeper.Thread.Suspend();
            Unit.UnitCollisionSweeper.Thread.Resume();
            Unit.PathFinder.ResumeThread();

            uiViewport = GraphicsDevice.Viewport;
            worldViewport = GraphicsDevice.Viewport;
            worldViewport.Height -= (minimapSize + minimapBorderSize * 2);
            GraphicsDevice.Viewport = worldViewport;

            camera = new Camera();
            camera.Pos = new Vector2(worldViewport.Width / 2, worldViewport.Height / 2);

            button1 = new BaseObject(new Rectangle(10, 25, 25, 25));
            button2 = new BaseObject(new Rectangle(10, 52, 25, 25));
            button3 = new BaseObject(new Rectangle(10, 79, 25, 25));

            if (!contentLoaded)
            {
                pauseFont = Content.Load<SpriteFont>("Battle1BillStatusFont");
                fpsFont = Content.Load<SpriteFont>("TitleFont1");
                brownGuyTexture = Content.Load<Texture2D>("browncircleguy");
                brownGuySelectingTexture = Content.Load<Texture2D>("browncircleguyselected2");
                brownGuySelectedTexture = Content.Load<Texture2D>("browncircleguyselecting2");
                buttonTexture = Content.Load<Texture2D>("titlebutton1");
                moveCommandTexture = Content.Load<Texture2D>("greencircle2");
                //normalCursorTexture = Content.Load<Texture2D>("greencursor2");
                //attackCommandCursorTexture = Content.Load<Texture2D>("crosshair");
                normalCursor = Util.LoadCustomCursor(@"Content/SC2-cursor.cur");
                attackCursor = Util.LoadCustomCursor(@"Content/SC2-target-none.cur");
                boulder1Texture = Content.Load<Texture2D>("boulder1");
                tree1Texture = Content.Load<Texture2D>("tree2");
                redCircleTexture = Content.Load<Texture2D>("redcircle");
                transparentTexture = Content.Load<Texture2D>("transparent");
                rtsMusic = Content.Load<Song>("rtsmusic");
                Unit.BulletTexture = Content.Load<Texture2D>("bullet");
                Unit.Explosion1Textures = Util.SplitTexture(Content.Load<Texture2D>("explosionsheet1"), 45, 45);
                contentLoaded = true;
            }

            winForm = (Form)Form.FromHandle(Game1.Game.Window.Handle);
            winForm.Cursor = normalCursor;

            initializeMinimap();

            SelectBox.InitializeSelectBoxLine(GraphicsDevice, Color.Green);
            InitializeSelectionRingLine(GraphicsDevice, Color.Yellow);

            minimapScreenIndicatorBoxLine = new PrimitiveLine(GraphicsDevice, 1);
            minimapScreenIndicatorBoxLine.Colour = Color.White;

            for (int i = 0; i < HotkeyGroups.Length; i++)
                HotkeyGroups[i] = new List<Unit>();

            MediaPlayer.Play(rtsMusic);
            MediaPlayer.Volume = .25f;
            MediaPlayer.IsRepeating = true;
        }
Ejemplo n.º 3
0
 public static void InitializeLine(GraphicsDevice graphicsDevice)
 {
     line        = new PrimitiveLine(graphicsDevice, 1);
     line.Colour = Color.Red;
 }
Ejemplo n.º 4
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);*/
        }
Ejemplo n.º 5
0
 public static void InitializeSelectionRingLine(GraphicsDevice graphicsDevice, Color color)
 {
     selectionRingLine = new PrimitiveLine(graphicsDevice, 1);
     selectionRingLine.Colour = color;
 }
Ejemplo n.º 6
0
 public static void InitializeSelectBoxLine(GraphicsDevice graphicsDevice, Color color)
 {
     selectBoxLine        = new PrimitiveLine(graphicsDevice, 1);
     selectBoxLine.Colour = color;
 }
Ejemplo n.º 7
0
        public override void Initialize()
        {
            spriteBatch = new SpriteBatch(Game.GraphicsDevice);

            lines = new List<string>();

            boxLine = new PrimitiveLine(Game.GraphicsDevice, 1);
            boxLine.Colour = Color.Black;
            boxVectors = new Vector2[4];

            base.Initialize();
        }
Ejemplo n.º 8
0
 public static void InitializeLine(GraphicsDevice graphicsDevice)
 {
     line = new PrimitiveLine(graphicsDevice, 1);
     line.Colour = Color.Red;
 }