Esempio n. 1
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);
        }
Esempio n. 2
0
 public bool IsOffScreen(Viewport viewport, Camera camera)
 {
     if (camera == null)
         return (X < 0 - Width || X > viewport.Width || Y < 0 - Height || Y > viewport.Height);
     else
     {
         Vector2 screenPosition = Vector2.Transform(PrecisePosition, camera.get_transformation(viewport));
         return (screenPosition.X < 0 - Width || screenPosition.X > viewport.Width ||
             screenPosition.Y < 0 - Height || screenPosition.Y > viewport.Height);
     }
 }
Esempio n. 3
0
File: Rts.cs Progetto: nubington/rts
        public Rts(EventHandler callback, Lidgren.Network.NetPeer netpeer, short myTeam)
            : base(callback)
        {
            netPeer = netpeer;
            iAmServer = netPeer is NetServer;

            Game1.Game.DebugMonitor.Position = Direction.NorthEast;
            //Game1.Game.Graphics.SynchronizeWithVerticalRetrace = false;
            //Game1.Game.IsFixedTimeStep = false;
            //Game1.Game.Graphics.ApplyChanges();
            //GameTimer.Restart();

            //map = new Map(@"Content/map1.muh");
            map = new Map("C:\\rts maps\\map2.muh");
            pathFinder = new PathFinder(map);
            map.InstantiateMapResources();
            //Player.Me.Team = myTeam;
            Player.Me = Player.Players[myTeam];

            actualMapWidth = map.Width * map.TileSize;
            actualMapHeight = map.Height * map.TileSize;

            Unit.UnitCollisionSweeper.Thread.Suspend();
            Unit.UnitCollisionSweeper.Thread.Resume();
            Rts.pathFinder.ResumeThread();

            uiViewport = GraphicsDevice.Viewport;
            worldViewport = GraphicsDevice.Viewport;
            minimapViewport = new Viewport(minimapBorderSize, uiViewport.Height - minimapSize - minimapBorderSize, minimapSize, minimapSize);
            //minimapViewport = new Viewport(0, 0, minimapSize, minimapSize);
            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));
            button4 = new BaseObject(new Rectangle(10, 106, 25, 25));
            button5 = new BaseObject(new Rectangle(10, 133, 25, 25));

            if (!contentLoaded)
            {
                pauseFont = Content.Load<SpriteFont>("spritefonts/pausefont");
                fpsFont = Content.Load<SpriteFont>("spritefonts/fpsfont");
                unitInfoUnitNameFont = Content.Load<SpriteFont>("spritefonts/UnitInfoUnitNameFont");
                unitInfoHpFont = Content.Load<SpriteFont>("spritefonts/UnitInfoHpFont");
                unitInfoKillCountFont = Content.Load<SpriteFont>("spritefonts/UnitInfoKillCountFont");
                resourceCountFont = Content.Load<SpriteFont>("spritefonts/ResourceCountFont");
                bigFont = Content.Load<SpriteFont>("spritefonts/BigMessage");
                //brownGuyTexture = Content.Load<Texture2D>("unit textures/browncircleguy");
                //brownGuySelectingTexture = Content.Load<Texture2D>("unit textures/browncircleguyselected2");
                //brownGuySelectedTexture = Content.Load<Texture2D>("unit textures/browncircleguyselecting2");
                greenTeamIndicatorTexture = Content.Load<Texture2D>("unit textures/green team indicator");
                redTeamIndicatorTexture = Content.Load<Texture2D>("unit textures/red team indicator");
                buttonTexture = Content.Load<Texture2D>("titlebutton1");
                moveCommandShrinkerTexture = Content.Load<Texture2D>("greencircle2");
                attackMoveCommandShrinkerTexture = Content.Load<Texture2D>("redcircle2");
                //normalCursorTexture = Content.Load<Texture2D>("greencursor2");
                //attackCommandCursorTexture = Content.Load<Texture2D>("crosshair");
                normalCursor = Util.LoadCustomCursor(@"Content/cursors/SC2-cursor.cur");
                attackCursor = Util.LoadCustomCursor(@"Content/cursors/SC2-target-none.cur");
                boulder1Texture = Content.Load<Texture2D>("boulder1");
                tree1Texture = Content.Load<Texture2D>("tree2");
                rallyFlagTexture = Content.Load<Texture2D>("redflag");
                redCircleTexture = Content.Load<Texture2D>("redcircle");
                transparentTexture = Content.Load<Texture2D>("transparent");
                transparentGrayTexture = Content.Load<Texture2D>("transparentgray");
                transparentBlackTexture = Content.Load<Texture2D>("transparentblack");
                whiteBoxTexture = Content.Load<Texture2D>("whitebox");
                cogWheelTexture = Content.Load<Texture2D>("cogwheel");
                rtsMusic = Content.Load<Song>("music/58 - Weapons Factory");
                errorSoundEffect = Content.Load<SoundEffect>("sounds/Error");
                //Unit.BulletTexture = Content.Load<Texture2D>("bullet");
                Unit.Explosion1Textures = Util.SplitTexture(Content.Load<Texture2D>("explosionsheet1"), 45, 45);
                Structure.Explosion1Textures = Util.SplitTexture(Content.Load<Texture2D>("explosionsheet1"), 45, 45);
                contentLoaded = true;
            }

            winForm = (Form)Form.FromHandle(Game1.Game.Window.Handle);
            //Cursor.Clip = new System.Drawing.Rectangle(winForm.Location, winForm.Size);
            winForm.Cursor = normalCursor;

            initializeMapTexture();
            initializeCommandCardArea();
            initializeSelectionInfoArea();
            line.Alpha = .75f;

            VisionUpdater = new VisionUpdater(map, Rts.pathFinder, Player.Me.Team);

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

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

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

            MediaPlayer.Play(rtsMusic);
            MediaPlayer.Volume = MusicVolume;
            MediaPlayer.IsRepeating = true;

            /*new TownHall(map.StartingPoints[myTeam], myTeam);
            camera.Pos = new Vector2(map.StartingPoints[myTeam].X * map.TileSize, map.StartingPoints[myTeam].Y * map.TileSize);
            Player.Me.MaxSupply += StructureType.TownHall.Supply;*/
            initializeStartingPoints();

            //new Barracks(new Point(10, 14), 2);
            //new Roks(new Point(3, 3));
            //new Roks(new Point(3, 30));

            Player.Me.Roks = 25;

            clampCameraToMap();

            initialHandShake();
        }
Esempio n. 4
0
        public static void Update(Viewport viewport, Camera camera)
        {
            if (!enabled)
                return;

            //Vector2 halfOfViewPort = new Vector2(Game1.Game.GraphicsDevice.Viewport.Width / 2f, Game1.Game.GraphicsDevice.Viewport.Height / 2f);
            //Vector2 mousePosition = new Vector2(Mouse.GetState().X, Mouse.GetState().Y) + (cameraOffset);

            Vector2 mousePosition = new Vector2(Mouse.GetState().X, Mouse.GetState().Y);

            Vector2 mouseWorldPosition = Vector2.Transform(mousePosition, Matrix.Invert(camera.get_transformation(viewport)));

            if (Mouse.GetState().LeftButton == ButtonState.Released)
            {
                selecting = false;
                return;
            }
            else if (selecting == false)// && graphics.GraphicsDevice.Viewport.Bounds.Contains(new Point(Mouse.GetState().X, Mouse.GetState().Y)))
            {
                selecting = true;
                selectPoint1 = selectPoint2 = new Rectangle((int)mouseWorldPosition.X, (int)mouseWorldPosition.Y, 1, 1);
                drawPoint1 = drawPoint2 = new Rectangle((int)mousePosition.X, (int)mousePosition.Y, 1, 1);
            }
            else
            {
                selectPoint2 = new Rectangle((int)mouseWorldPosition.X, (int)mouseWorldPosition.Y, 1, 1);
                drawPoint2 = new Rectangle((int)mousePosition.X, (int)mousePosition.Y, 1, 1);
            }

            /*selectBox.X = selectPoint1.X;
            selectBox.Y = selectPoint1.Y;
            selectBox.Width = (int)Vector2.Distance(new Vector2(selectPoint1.X, 0), new Vector2(selectPoint2.X, 0));
            selectBox.Height = (int)Vector2.Distance(new Vector2(0, selectPoint1.Y), new Vector2(0, selectPoint2.Y));
            selectBox.Rotation = camera.Rotation + (float)Math.PI;*/

            selectBox.Rectangle = Rectangle.Union(selectPoint1, selectPoint2);
            selectBox.Rotation = camera.Rotation + (float)Math.PI;
            drawBox = Rectangle.Union(drawPoint1, drawPoint2);
        }
Esempio n. 5
0
File: Rts.cs Progetto: nubington/rts
        public Rts(EventHandler callback)
            : base(callback)
        {
            Game1.Game.DebugMonitor.Position = Direction.NorthEast;
            Game1.Game.IsMouseVisible = true;
            //Game1.Game.Graphics.SynchronizeWithVerticalRetrace = false;
            //Game1.Game.IsFixedTimeStep = false;
            //Game1.Game.Graphics.ApplyChanges();
            GameTimer.Restart();

            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));
            button4 = new BaseObject(new Rectangle(10, 106, 25, 25));
            button5 = new BaseObject(new Rectangle(10, 133, 25, 25));

            if (!contentLoaded)
            {
                pauseFont = Content.Load<SpriteFont>("spritefonts/pausefont");
                fpsFont = Content.Load<SpriteFont>("spritefonts/fpsfont");
                unitInfoUnitNameFont = Content.Load<SpriteFont>("spritefonts/UnitInfoUnitNameFont");
                unitInfoHpFont = Content.Load<SpriteFont>("spritefonts/UnitInfoHpFont");
                unitInfoKillCountFont = Content.Load<SpriteFont>("spritefonts/UnitInfoKillCountFont");
                //brownGuyTexture = Content.Load<Texture2D>("unit textures/browncircleguy");
                //brownGuySelectingTexture = Content.Load<Texture2D>("unit textures/browncircleguyselected2");
                //brownGuySelectedTexture = Content.Load<Texture2D>("unit textures/browncircleguyselecting2");
                greenTeamIndicatorTexture = Content.Load<Texture2D>("unit textures/green team indicator");
                redTeamIndicatorTexture = Content.Load<Texture2D>("unit textures/red team indicator");
                buttonTexture = Content.Load<Texture2D>("titlebutton1");
                moveCommandTexture = Content.Load<Texture2D>("greencircle2");
                //normalCursorTexture = Content.Load<Texture2D>("greencursor2");
                //attackCommandCursorTexture = Content.Load<Texture2D>("crosshair");
                normalCursor = Util.LoadCustomCursor(@"Content/cursors/SC2-cursor.cur");
                attackCursor = Util.LoadCustomCursor(@"Content/cursors/SC2-target-none.cur");
                boulder1Texture = Content.Load<Texture2D>("boulder1");
                tree1Texture = Content.Load<Texture2D>("tree2");
                redCircleTexture = Content.Load<Texture2D>("redcircle");
                transparentTexture = Content.Load<Texture2D>("transparent");
                transparentGrayTexture = Content.Load<Texture2D>("transparentgray");
                transparentBlackTexture = Content.Load<Texture2D>("transparentblack");
                whiteBoxTexture = Content.Load<Texture2D>("whitebox");
                rtsMusic = Content.Load<Song>("sounds/crossingthosehills");
                //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;

            VisionUpdater = new VisionUpdater(map, Unit.PathFinder, myTeam);

            initializeMapTexture();
            initializeCommandCardArea();
            initializeSelectionInfoArea();

            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<RtsObject>();

            MediaPlayer.Play(rtsMusic);
            MediaPlayer.Volume = .25f;
            MediaPlayer.IsRepeating = true;
        }