当前位置: 首页>>代码示例>>C#>>正文


C# Framework.Rectangle类代码示例

本文整理汇总了C#中Microsoft.Xna.Framework.Rectangle的典型用法代码示例。如果您正苦于以下问题:C# Rectangle类的具体用法?C# Rectangle怎么用?C# Rectangle使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Rectangle类属于Microsoft.Xna.Framework命名空间,在下文中一共展示了Rectangle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MapTile

        public MapTile(Texture2D texture, int type, int x, int y, int size)
        {
            this.TileTexture = texture;

            // Changes which column of the sprite sheet the game uses to draw
            int blockX = size * SpriteSheetXOffset;
            this.TileColour = Color.White;
            switch (type)
            {
                case 0: break;
                case 1: this.RectSlice = new Rectangle(blockX, size * 1, size, size); this.IsSolid = true; break;
                case 2: this.RectSlice = new Rectangle(blockX, size * 2, size, size); this.IsSolid = true; this.IsSpring = true; break;
                case 3: this.RectSlice = new Rectangle(blockX, size * 3, size, size); this.IsSolid = true; break;
                case 4: this.RectSlice = new Rectangle(blockX, size * 4, size, size); this.IsSolid = true; break;
                case 5: this.RectSlice = new Rectangle(blockX, size * 5, size, size); this.IsSolid = true; break;
                case 6: this.RectSlice = new Rectangle(blockX, size * 6, size, size); this.IsSolid = true; break;
                case 7:
                    this.RectSlice = new Rectangle(blockX, size * 7, size, size); this.IsSolid = false;
                    this.TileColour = new Color(255, 255, 255, 20);
                    this.IsWater = true;
                    break;
                default: this.RectSlice = new Rectangle(blockX, size * 0, size, size); this.IsSolid = true; break;
            }
            this.Width = size;
            this.Height = size;
            this.PositionRect = new Rectangle(x, y, this.Width, this.Height);
        }
开发者ID:colincapurso,项目名称:Game-Engine-XNA,代码行数:27,代码来源:MapTile.cs

示例2: GetCorrectionVector

        public static Tuple<Direction, Direction, Vector2> GetCorrectionVector(this Rectangle rect, Rectangle target)
        {
            Vector2 vector = new Vector2();
            Direction directionX = Direction.Unknown;
            Direction directionY = Direction.Unknown;

            float x1 = Math.Abs(rect.Right - target.Left);
            float x2 = Math.Abs(rect.Left - target.Right);
            float y1 = Math.Abs(rect.Bottom - target.Top);
            float y2 = Math.Abs(rect.Top - target.Bottom);

            if (x1 < x2)
            {
                vector.X = x1;
                directionX = Direction.Left;
            }
            else if (x1 > x2)
            {
                vector.X = x2;
                directionX = Direction.Right;
            }

            if (y1 < y2)
            {
                vector.Y = y1;
                directionY = Direction.Up;
            }
            else if (y1 > y2)
            {
                vector.Y = y2;
                directionY = Direction.Down;
            }

            return new Tuple<Direction, Direction, Vector2>(directionX, directionY, vector);
        }
开发者ID:zunath,项目名称:MMXEngine,代码行数:35,代码来源:RectangleExtensions.cs

示例3: Update

        public void Update(GameTime gameTime)
        {
            position.X += Velocidade * direcao;

            Rect = new Rectangle((int)position.X, (int)position.Y, sprite.Width, sprite.Height);

            #region Movimentacao
            //position.X = MathHelper.Clamp((float)position.X, 0, viewportRect.Width - sprite.Width);

            if (position.X >= Game1.viewportRect.Width - sprite.Width)
            {
                position.X = Game1.viewportRect.Width - sprite.Width - 1;
                NaveFilho.direcao *= -1;
            }

            if (position.X <= 0)
            {
                position.X = +1;
                NaveFilho.direcao *= -1;
            }

            #endregion

            if (boolVermelhidao)
            {

                Vermelhidao(gameTime);
            }
        }
开发者ID:vitormartins1,项目名称:project-meteor,代码行数:29,代码来源:NaveFilho.cs

示例4: Scrolling

 public Scrolling(Texture2D texture, Rectangle rect, Vector2 Pos, float s)
 {
     this.texture = texture;
     this.rectangle = rect;
     this.Position = Pos;
     this.ObjectSpeed = s;
 }
开发者ID:glocklueng,项目名称:STM32F4_RF,代码行数:7,代码来源:Background.cs

示例5: Bolt

        protected bool leftToRight = false; // Final boss can fire bolts left and right

        #endregion Fields

        #region Constructors

        public Bolt(Texture2D textureImage, Point sheetSize, Vector2 position, int millisecondsPerFrame, bool leftToRight, Rectangle window, ExplosionManager explosionManager)
            : base(textureImage, sheetSize,  position, Vector2.Zero, millisecondsPerFrame, window, explosionManager,null)
        {
            this.health = 100f;
            this.leftToRight = leftToRight;
            this.energyToLose = health / (sheetSize.Y * sheetSize.X);
        }
开发者ID:urgamedev,项目名称:code-monogame,代码行数:13,代码来源:Bolt.cs

示例6: MouseClicked

        public void MouseClicked(int x, int y, ref GameType gameType)
        {
            mouseClick = new Rectangle(x, y, 10, 10);

            if (mouseClick.Intersects(Bouton_host))
            {
                c = new Client();
                Thread t = new Thread(new ThreadStart(Program2.Mainq));
                t.Start();
                t.IsBackground = true;
            }
            if (mouseClick.Intersects(Bouton_Exit))
            {
                Game1.GetGame().Exit();
            }
            else if (mouseClick.Intersects(Bouton_Options))
            {
                gameType = GameType.Menu_Option_Type;
            }
            else if (mouseClick.Intersects(Bouton_Multi))
            {
                gameType = GameType.Menu_Play_Multi_Type2;
            }
            else if (mouseClick.Intersects(Bouton_Play))
            {
                gameType = GameType.Menu_Play_Type;
            }
            else if (mouseClick.Intersects(Bouton_Solo))
            {
                gameType = GameType.Menu_Play_Solo_Type;
            }
        }
开发者ID:Greflop,项目名称:Final,代码行数:32,代码来源:Menu_Play_Multi.cs

示例7: Notification

 public Notification(GameFacet facet, string filename, Rectangle location)
     : base(facet)
 {
     this.filename = filename;
     this.location = location;
     alpha = 255;
 }
开发者ID:Cheezmeister,项目名称:Chromathud,代码行数:7,代码来源:Notification.cs

示例8: Draw

        public void Draw(GameTime gameTime, SpriteBatch spriteBatch, Vector2 position, SpriteEffects spriteEffects)
        {
            if (Animation == null)
            {
                throw new NotSupportedException("No animation is currently playing.");
            }

            time += (float)gameTime.ElapsedGameTime.TotalSeconds;
            while (time > Animation.frameTime)
            {
                time -= Animation.frameTime;

                if (Animation.isLooping)
                {
                    frameIndex = (frameIndex + 1) % Animation.FrameCount;

                }
                else
                {
                    frameIndex = Math.Min(frameIndex + 1, Animation.FrameCount - 1);
                }
            }

            Rectangle source = new Rectangle(FrameIndex * Animation.FrameWidth, 0, Animation.FrameWidth, Animation.FrameHeight);

            spriteBatch.Draw(animation.texture, position, source, Color.White, 0.0f, Vector2.Zero, 0.5f, SpriteEffects.None, 0.0f);
        }
开发者ID:WINPROG20152016,项目名称:Penaranda_TapTitanXNA,代码行数:27,代码来源:AnimationPlayer.cs

示例9: Draw

        public override void Draw(GameTime gameTime)
        {
            SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
            SpriteFont font = ScreenManager.TopScoresFont;

            ScreenManager.FadeBackBufferToBlack(TransitionAlpha * 2 / 3);

            Viewport viewport = ScreenManager.GraphicsDevice.Viewport;
            Vector2 viewportSize = new Vector2(viewport.Width, viewport.Height);
            Vector2 messageSize = font.MeasureString(message);
            Vector2 messagePosition = (viewportSize - messageSize) / 2;

            const int hPad = 32;
            const int vPad = 16;
            Rectangle backgroundRectangle = new Rectangle((int)messagePosition.X - hPad,
                                                          (int)messagePosition.Y - vPad,
                                                          (int)messageSize.X + hPad * 2,
                                                          (int)messageSize.Y + vPad * 2);

            Color color = Color.White * TransitionAlpha;

            spriteBatch.Begin();
            spriteBatch.Draw(questionFrameTex, backgroundRectangle, color);
            spriteBatch.DrawString(font, message, messagePosition, color);
            spriteBatch.End();
        }
开发者ID:decwong,项目名称:DEPW,代码行数:26,代码来源:QuestionScreen.cs

示例10: Update

        public override void Update()
        {
            // Bounding Box
            rectangle = new Rectangle
            (
                (int)Position.X,
                (int)Position.Y,
                (int)Size.X,
                (int)Size.Y
            );

            KeyboardState keyboardState = Keyboard.GetState();
            if (Keyboard.GetState().IsKeyDown(Keys.D))
            {
                Position += movingVector;
                body.ApplyLinearImpulse(movingImpulse);
            }
            else if (Keyboard.GetState().IsKeyDown(Keys.A))
            {
                Position -= movingVector;
                body.ApplyLinearImpulse(-movingImpulse);
            }
            if (Keyboard.GetState().IsKeyDown(Keys.W) && !prevKeyboardState.IsKeyDown(Keys.W))
            {
                if ((DateTime.Now - previousJump).TotalSeconds >= jumpInterval)
                {
                    jumpEffect.Play();
                    body.ApplyLinearImpulse(jumpingImpulse);
                    previousJump = DateTime.Now;
                }
            }

            prevKeyboardState = keyboardState;
        }
开发者ID:rolandKulcsar,项目名称:Crate-Game,代码行数:34,代码来源:Player.cs

示例11: GetNodeSourceRects

        public static Rectangle[] GetNodeSourceRects(NodePiece nodePiece)
        {
            int x = textureOffsetX;
            int y = textureOffsetY;
            Rectangle[] nodeSourceRects = new Rectangle[3];

            // locate the "Type" sprite, make it the first entry in the return array.
            x += PieceWidth + texturePaddingX;
            y += Array.IndexOf(PieceTypes, nodePiece.Type) * (PieceHeight + texturePaddingY);

            nodeSourceRects[0] = new Rectangle(x, y, PieceWidth, PieceHeight);

            // locate the "State" sprite, make it the second entry in the return array.
            y = textureOffsetY;
            y += (Array.IndexOf(PieceStates, nodePiece.State) + StateSpriteOffset) * (PieceHeight + texturePaddingY);

            nodeSourceRects[1] = new Rectangle(x, y, PieceWidth, PieceHeight);

            // locate the "SecurityRating" sprite, make it the third entry in the return array.
            x += PieceWidth + texturePaddingX;

            y = textureOffsetY;
            y += Array.IndexOf(PieceStates, nodePiece.SecurityRating) * (PieceHeight + texturePaddingY); // WRONG

            nodeSourceRects[2] = new Rectangle(x, y, PieceWidth, PieceHeight);

            return nodeSourceRects;
        }
开发者ID:TensAndTwenties,项目名称:Ruin,代码行数:28,代码来源:GamePiece.cs

示例12: Board

		public Board(Game game, int posX = 224, int posY = 64, int width = 384, int height = 384)
			: base(game) {
			State = EBoardState.Initialize;
			Score = 0;

			Bounds = new Rectangle(posX, posY, width, height);
		}
开发者ID:GodLesZ,项目名称:svn-dump,代码行数:7,代码来源:Board.cs

示例13: ArtilleryTower

        public ArtilleryTower(World world, Rectangle towerBase)
            : base(world, towerBase)
        {
            textureMM = world.texMMartillery;
            texture = world.texTowerArty;
            name = "Artillery Tower";
            fireSound = "artillery";
            volleyMode = true;
            range = 1250;
            dmg = 15;
            sDmg = 15;
            firingRate = 250.0f;
            pAcceleration = 0;
            imprecision = 40;
            maxMissiles = 30;
            missileInterval = 50;
            homing = false;
            pSpeed = 8.5f;
            sRange = 115;
            mmColor = Color.Orange;

            cost = 125;

            defaultRange = range;
            defaultFiringRate = firingRate;
            defaultDmg = dmg;
            baseDamage = defaultDmg;
        }
开发者ID:kinaesthesia,项目名称:KDefTower,代码行数:28,代码来源:ArtilleryTower.cs

示例14: Paddle

        public Paddle(ContentManager theContent, string theAssetName, Input theInput, PaddlePosition thePosition)
            : base(theContent, theAssetName)
        {
            SourceRectangle = new Rectangle(0, 0, 1, 1);
            Scale = new Vector2(10.0f, 100.0f);
            mColor = Color.SlateBlue;

            mPaddlePosition = thePosition;
            switch (thePosition)
            {
                case PaddlePosition.Left:
                    {
                        Boundary = new Rectangle(140, 185, 10, 833);
                        break;
                    }

                case PaddlePosition.Right:
                    {
                        Boundary = new Rectangle(1130, 185, 10, 833);
                        break;
                    }
            }

            Position = Center(Boundary);

            mInput = theInput;
        }
开发者ID:Gevil,项目名称:Projects,代码行数:27,代码来源:Paddle.cs

示例15: DrawRectangle

 /// <summary>
 /// Draw a rectangle.
 /// </summary>
 /// <param name="rectangle">The rectangle to draw.</param>
 /// <param name="color">The draw color.</param>
 public void DrawRectangle(Rectangle rectangle, Color color)
 {
     this.Draw(this.WhiteTexture, new Rectangle(rectangle.Left, rectangle.Top, rectangle.Width, 1), color);
     this.Draw(this.WhiteTexture, new Rectangle(rectangle.Left, rectangle.Bottom, rectangle.Width, 1), color);
     this.Draw(this.WhiteTexture, new Rectangle(rectangle.Left, rectangle.Top, 1, rectangle.Height), color);
     this.Draw(this.WhiteTexture, new Rectangle(rectangle.Right, rectangle.Top, 1, rectangle.Height + 1), color);
 }
开发者ID:dotKokott,项目名称:MathFighter,代码行数:12,代码来源:ExtendedSpriteBatch.cs


注:本文中的Microsoft.Xna.Framework.Rectangle类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。