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


C# Rectangle.IntersectsWith方法代码示例

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


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

示例1: Step

        public override void Step()
        {
            _area = new Rectangle(Position, Width, Font.LineHeight * Lines + BorderWidth * 2f);

            if (Input.IsPressed(Button.MouseLeft))
            {
                //focus if on the textbox
                if (_area.IntersectsWith(Input.MousePosition))
                    Focus();
                else //defocus if not
                    Defocus();
            }

            _drawString = Text.ToString();

            //add caret if focused
            if (_hasFocus)
            {
                if (_cursorBlinkStep < Game.StepsPerSecond / 2f)
                {
                    _cursorActive = true;
                    _drawString += '|';
                }
                else
                    _cursorActive = false;

                if (++_cursorBlinkStep > Game.StepsPerSecond)
                    _cursorBlinkStep -= Game.StepsPerSecond;
            }

            //trim
            int charsTrimmed;
            _drawString = Font.WrapString(_drawString, Width - BorderWidth * 2f, Lines, out charsTrimmed);

            if (charsTrimmed > 1)
            {
                if (_cursorActive)
                    charsTrimmed--;

                Text.Remove(Text.Length - charsTrimmed + 1, charsTrimmed - 1);
            }

            //only throw event when the text was manually changed and the key was accepted
            if (Text.ToString() != _lastTextString)
            {
                if (TextChanged != null)
                    TextChanged(this, new TextChangedEventArgs(Text.ToString()));

                _cursorBlinkStep = 0f;

                _lastTextString = Text.ToString();
            }
        }
开发者ID:villermen,项目名称:hatless-engine,代码行数:53,代码来源:TextBox.cs

示例2: checkCollision

        private void checkCollision(float x1, float y1, float x2, float y2)
        {
            Rectangle myRect = new Rectangle((int)x2-16, (int)y2-16, 32, 32);
            Rectangle myRect_x = new Rectangle((int)x2 - 16, (int)y1 - 16, 32, 32);
            Rectangle myRect_y = new Rectangle((int)x1 - 16, (int)y2 - 16, 32, 32);

            foreach (Rectangle rect in this.game.GetCurrentLevel().GetRectangles())
            {
                if (myRect.IntersectsWith(rect))
                {
                    if (myRect_x.IntersectsWith(rect))
                    {
                        this.x = x1;
                    }
                    if (myRect_y.IntersectsWith(rect))
                    {
                        this.y = y1;
                    }
                }
            }
        }
开发者ID:remy22,项目名称:OpenGL-CSharp-Game,代码行数:21,代码来源:Player.cs

示例3: IntersectTest

 public void IntersectTest(int x, int y, int width, int height)
 {
     Rectangle rect = new Rectangle(x, y, width, height);
     Rectangle expectedRect = Rectangle.Intersect(rect, rect);
     rect.Intersect(rect);
     Assert.Equal(expectedRect, rect);
     Assert.False(rect.IntersectsWith(expectedRect));
 }
开发者ID:jemmy655,项目名称:corefx,代码行数:8,代码来源:RectangleTests.cs

示例4: contents_at_XY

    public int contents_at_XY(int xx, int yy)
    {
        Rectangle rr = new Rectangle(xx, yy, 1, 1);  // Trust in the generational garbage collector...highly optimized for uses such as this...
        int id = 0;
        foreach (KeyValuePair<int, object[]> kvp in content_regions) {
            // Using a SortedList<>, for iteration in ascending order by key.
            // The key is also the "rendering order", so that
            // multiple overlapping content regions (which are allowed, and indeed ordinary)
            // result in the element with the highest rendering order over-writing
            // those from earlier content regions.
            //
            // TODO: Something different will be desired for layers which support multiple objects per tile,
            //       presumably adding elements into a list of objects present...
            //       -- Supporting that will likely want a new class which is IGridIterable ...
            //
            int key = kvp.Key;
            IGridIterable grid = (IGridIterable) kvp.Value[0];
            int pos_x          = (int) kvp.Value[1];
            int pos_y          = (int) kvp.Value[2];

            Rectangle rect = new Rectangle(pos_x, pos_y, grid.width, grid.height);  // Yes, trust in the garbage collector...
            // At some future time, if and when content is created
            // that involves tens of thousands (or more) of content regions,
            // then it might be warranted to look into using
            // fancier data structures such as (Interval Tree, other)
            // to make testing for intersecting content regions more efficient...
            if (rr.IntersectsWith(rect)) {
                int grid_rel_x = xx - pos_x;
                int grid_rel_y = yy - pos_y;
                int val = grid.contents_at_XY(grid_rel_x, grid_rel_y);
                if (val != 0) { id = val; }
            }
        } // foreach

        // If we get here, then zero content regions overlapped,
        // so return the NULL object (or the default_terrain, if implemented)
        if (id != 0) { return id; }
        return 127;  // TODO: return "default object" for this map (will be an instance member/property, an object ID which could be 0)
    }
开发者ID:sglasby,项目名称:HRAOS,代码行数:39,代码来源:MapCompositedLayer.cs

示例5: UpdateControls

        protected virtual void UpdateControls()
        {
            if (game.KeyInput.IsKeyPress(Key.Down))
            {
                actualItem++;

                if (actualItem >= items.Count)
                    actualItem = 0; // první položka v menu
            }
            else if (game.KeyInput.IsKeyPress(Key.Up))
            {
                actualItem--;

                if (actualItem < 0)
                    actualItem = (sbyte)(items.Count - 1); // poslední položka v menu
            }
            else if (game.KeyInput.IsKeyPress(Key.Enter) || game.KeyInput.IsKeyPress(Key.Right))
            {
                switch (items[actualItem].Text)
                {
                    case "Exit":
                        game.Exit();
                        break;

                    default:
                        submenu = actualItem;
                        break;
                }
            }

            int y = game.Height - 190;

            foreach (MenuItem item in items)
            {
                Rectangle rect = new Rectangle(20, y, 140, 35);

                if (rect.IntersectsWith(new Rectangle(game.Mouse.X, game.Mouse.Y, 1, 1)))
                {
                    actualItem = (sbyte)items.IndexOf(item);

                    if (game.MouseInput.IsMouseDown(MouseButton.Left))
                    {
                        submenu = actualItem;
                        break;
                    }
                }
                y += 35;
            }
        }
开发者ID:mimic2300,项目名称:WormsGL,代码行数:49,代码来源:GameMenu.cs

示例6: GetTiles

        public IEnumerable<TileBase> GetTiles(
            Rectangle bounds,
            [NotNull] IEnumerable<TileBase> existingTiles)
        {
            TileSet tiles = new TileSet();
            Queue<TileBase> openTiles = new Queue<TileBase>();
            List<TileBase> removeTiles = new List<TileBase>();

            Rectangle tileBounds;

            foreach (TileBase tile in existingTiles)
            {
                // if tile is in bounds
                // TODO The width and height must also be >= 1px
                tileBounds = tile.GetApproximateBounds();
                if (bounds.IntersectsWith(tileBounds))
                {
                    tiles.Add(tile);

                    if (tile.GetOpenEdgeParts().Any())
                        openTiles.Enqueue(tile);
                }
                else
                    removeTiles.Add(tile);
            }

            foreach (TileBase tile in removeTiles)
                tile.RemoveAdjacent();

            if (tiles.Count < 1)
            {
                TileBase tile = Tiles[0];
                Debug.Assert(tile != null, "tile != null");

                // TODO The width and height must also be >= 1px
                tileBounds = tile.GetApproximateBounds();
                if (!bounds.IntersectsWith(tileBounds))
                {
                    tile = new TileInstance(
                        (Tile) tile,
                        tile.Label,
                        tile.Transform * Matrix3x2.CreateTranslation(bounds.Center - tileBounds.Center));
                }

                // add initial tile to tiles
                tiles.Add(tile);

                // add initial tile to end of openTiles
                openTiles.Enqueue(tile);
            }

            // while there are tiles with no neighbour
            while (openTiles.Count > 0)
            {
                TileBase tile = openTiles.Dequeue();

                // for each edgePart with no neighbour
                foreach (EdgePart edgePart in tile.GetOpenEdgeParts())
                {
                    TileBase newTile = CreateNewTile(tile, edgePart);

                    tiles.Add(newTile);

                    // if newTile is in bounds
                    // TODO The width and height must also be >= 1px
                    tileBounds = newTile.GetApproximateBounds();
                    if (bounds.IntersectsWith(tileBounds))
                    {
                        // add newTile to end of openTiles
                        openTiles.Enqueue(newTile);
                    }
                }
            }

            // Set the style for the new cells
            foreach (TileBase tile in tiles.Where(t => t.Style == null))
            {
                // set cell style from styleManager
                tile.Style = StyleManager.GetStyle(tile);
            }

            return tiles.ToArray();
        }
开发者ID:billings7,项目名称:EscherTilier,代码行数:83,代码来源:Tiling.cs

示例7: IntersectsWith

 public bool IntersectsWith(Rectangle clientRect)
 {
     return clientRect.IntersectsWith(left, top, right, bottom);
 }
开发者ID:prepare,项目名称:HTML-Renderer,代码行数:4,代码来源:2_MySkiaCanvas_CoordinateAndClip.cs

示例8: CheckCollisions

        private void CheckCollisions()
        {
            // Against pipes
              var birdRect = new Rectangle(birdActor.x, birdActor.y, birdActor.width, birdActor.height);
              foreach (var pipeActor in pipeActors)
              {
            var pipeRect = new Rectangle(pipeActor.x, pipeActor.y, pipeActor.width, pipeActor.height);

            if (birdRect.IntersectsWith(pipeRect))
            {
              core.StateManager.SetState(new GameOverState(core, birdActor, groundActor, pipeActors, scoreActor));
            }
              }

              // Against ground
              if (birdActor.y + birdActor.height >= groundActor.y - 5)
              {
            birdActor.OnGroundCollision();
            core.StateManager.SetState(new GameOverState(core, birdActor, groundActor, pipeActors, scoreActor));
              }
        }
开发者ID:kamilkk,项目名称:FlappyBird,代码行数:21,代码来源:ActionState.cs

示例9: MouseIsOver

 public bool MouseIsOver(int x, int y)
 {
     Rectangle From = new Rectangle(X, Y, TextureItem.RatioSize, TextureItem.RatioSize);
     Rectangle To = new Rectangle(x, y, 2, 2);
     if (To.IntersectsWith(From))
         return true;
     else
         return false;
 }
开发者ID:Geramy,项目名称:TFAGame,代码行数:9,代码来源:GameObject.cs

示例10: IsBumping

 public bool IsBumping(GameObject to)
 {
     if (to == null)
         return false;
     //X obj1 From
     //x Obj2 To
     Rectangle From = new Rectangle(X, Y, TextureItem.RatioSize, TextureItem.RatioSize);
     Rectangle To = new Rectangle(to.X, to.Y, TextureItem.RatioSize, TextureItem.RatioSize);
     if (From.IntersectsWith(To))
         return true;
     else
         return false;
 }
开发者ID:Geramy,项目名称:TFAGame,代码行数:13,代码来源:GameObject.cs


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