public void RenderRaster(Graphics g, Bitmap bitmap, RasterStyle style, BoundingRectangle viewBox, BoundingRectangle bitmapBounds, double scaleFactor)
        {
            ICoordinate minPoint = bitmapBounds.Min;
            ICoordinate maxPoint = bitmapBounds.Max;

            if (viewBox.Intersects(bitmapBounds))
            {
                Point minP = new Point((int)((minPoint.X - viewBox.MinX) * scaleFactor),
                                       (int)((viewBox.MaxY - minPoint.Y) * scaleFactor));

                Point maxP = new Point((int)((maxPoint.X - viewBox.MinX) * scaleFactor),
                           (int)((viewBox.MaxY - maxPoint.Y) * scaleFactor));

                g.InterpolationMode = style.InterpolationMode;

                Rectangle r = new Rectangle(minP.X, maxP.Y, maxP.X - minP.X, minP.Y - maxP.Y);

                using (ImageAttributes imageAttributes = new ImageAttributes())
                {
                    imageAttributes.SetColorMatrix(style.ColorAdjustmentMatrix,
                                                   ColorMatrixFlag.Default,
                                                   ColorAdjustType.Bitmap);

                    g.DrawImage(bitmap, r, 0, 0, bitmap.Width, bitmap.Height,
                                GraphicsUnit.Pixel, imageAttributes);
                }
            }
        }
        public void AssertThat_IntersectionWithSegment_ReturnsIntersection_WithSingleIntersect_OnTop()
        {
            var a = new BoundingRectangle(new Vector2(0, 0), new Vector2(10, 10));

            var i = a.Intersects(new LineSegment2(new Vector2(5, 5), new Vector2(10, 30)));

            Assert.IsNotNull(i);
            Assert.AreEqual(new Vector2(6, 10), i.Value.Position);
        }
Beispiel #3
0
 /// <summary>Проверка записи на нахождение границ фигуры в указанной области</summary>
 /// <param name="bounds">Границы области</param>
 /// <param name="record">Запись shape-файла</param>
 /// <returns></returns>
 protected static bool IsRecordInView(BoundingRectangle bounds, ShapeFileRecord record)
 {
     if (bounds != null && !bounds.IsEmpty())
     {
         if (!bounds.Intersects(
             new BoundingRectangle(PlanimetryEnvironment.NewCoordinate(record.MinX, record.MinY),
                                   PlanimetryEnvironment.NewCoordinate(record.MaxX, record.MaxY))))
             return false;
     }
     return true;
 }
        public void UnRotatedRectanglesCollideCorrectly()
        {
            var rect1 = new BoundingRectangle(new Vector2d(5, 3), new Size2d(10, 6));
            var rect2 = new BoundingRectangle(new Vector2d(5, 3), new Size2d(3, 3));

            Assert.True(rect1.Intersects(rect2));
            Assert.True(rect2.Intersects(rect1));

            rect2.Position += 3;
            Assert.True(rect1.Intersects(rect2));
            Assert.True(rect2.Intersects(rect1));

            rect2.Position++;
            Assert.True(rect1.Intersects(rect2));
            Assert.True(rect2.Intersects(rect1));

            rect2.Position++;
            Assert.False(rect1.Intersects(rect2));
            Assert.False(rect2.Intersects(rect1));
        }
        public void RotatedRectanglesCollideCorrectly()
        {
            var rect1 = new BoundingRectangle(new Vector2d(2.5, 2.5), new Size2d(4.24, 2.83))
            {
                Rotation = -Math.PI / 4
            };
            var rect2 = new BoundingRectangle(new Vector2d(9, 4), new Size2d(6, 4));

            Assert.False(rect1.Intersects(rect2));
            Assert.False(rect2.Intersects(rect1));

            rect2.Position.X -= 2;

            Assert.True(rect1.Intersects(rect2));
            Assert.True(rect2.Intersects(rect1));

            rect2.Rotation = Math.PI / 2;
            rect2.Position++;

            Assert.False(rect1.Intersects(rect2));
            Assert.False(rect2.Intersects(rect1));

            rect2.Rotation = Math.PI;
            rect2.Position--;

            Assert.True(rect1.Intersects(rect2));
            Assert.True(rect2.Intersects(rect1));

            rect2.Position.Y += 10;

            Assert.False(rect1.Intersects(rect2));
            Assert.False(rect2.Intersects(rect1));

            rect2.Position.Y -= 10;
            rect1.Position.X += 5;

            Assert.True(rect1.Intersects(rect2));
            Assert.True(rect2.Intersects(rect1));

            rect1.Position.X += 9;

            Assert.False(rect1.Intersects(rect2));
            Assert.False(rect2.Intersects(rect1));

            rect1.Rotation   = 0;
            rect1.Position.X = 12;
            rect2.Rotation   = Math.PI;

            Assert.True(rect1.Intersects(rect2));
            Assert.True(rect2.Intersects(rect1));
        }
Beispiel #6
0
        public void Collision(Collider c)
        {
            if (BoundingRectangle.Intersects(c.CollisionField))
            {
                PixelPosition = previousPosition;
            }

            if (MySuperProjectile.BoundingRectangle.Intersects(c.CollisionField))
            {
                MySuperProjectile.ProjectileState = SuperProjectile.PROJECTILE_STATE.EXPLODING;
            }
        }
Beispiel #7
0
        public void Update(GameTime gameTime)
        {
            float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;

            // Calculate tile position based on the side we are moving towards.
            float posX  = Position.X + localBounds.Width / 2 * (int)direction;
            int   tileX = (int)Math.Floor(posX / Tile.Width) - (int)direction;
            int   tileY = (int)Math.Floor(Position.Y / Tile.Height);

            if (waitTime > 0)
            {
                // Wait for some amount of time.
                waitTime = Math.Max(0.0f, waitTime - (float)gameTime.ElapsedGameTime.TotalSeconds);
                if (waitTime <= 0.0f)
                {
                    // Then turn around.
                    direction = (FaceDirection)(-(int)direction);
                }
            }
            else
            {
                //If we're about to run into a wall that isn't a MovableTile move in other direction.
                if (Level.GetCollision(tileX + (int)direction, tileY) == TileCollision.Impassable ||
                    Level.GetCollision(tileX + (int)direction, tileY) == TileCollision.Platform)
                {
                    velocity = new Vector2(0.0f, 0.0f);
                    waitTime = MaxWaitTime;
                }
                else
                {
                    // Move in the current direction.
                    velocity = new Vector2((int)direction * MoveSpeed * elapsed, 0.0f);
                    position = position + velocity;
                }
            }

            if (level.movableTiles.Count > 0)
            {
                //If we're about to run into a MovableTile move in other direction.
                foreach (var movableTile in level.movableTiles)
                {
                    if (BoundingRectangle != movableTile.BoundingRectangle)
                    {
                        if (BoundingRectangle.Intersects(movableTile.BoundingRectangle))
                        {
                            direction = (FaceDirection)(-(int)direction);
                            velocity  = new Vector2((int)direction * MoveSpeed * elapsed, 0.0f);
                        }
                    }
                }
            }
        }
Beispiel #8
0
 private static bool isRecordInView(BoundingRectangle bounds, ShapeFileRecord record)
 {
     if (bounds != null && !bounds.IsEmpty())
     {
         if (!bounds.Intersects(
                 new BoundingRectangle(PlanimetryEnvironment.NewCoordinate(record.MinX, record.MinY),
                                       PlanimetryEnvironment.NewCoordinate(record.MaxX, record.MaxY))))
         {
             return(false);
         }
     }
     return(true);
 }
Beispiel #9
0
        public void CollisionCheck(Paddle paddle)
        {
            if (BoundingRectangle.Intersects(paddle.BoundingRectangle))
            {
                if (BoundingRectangle.Left < paddle.BoundingRectangle.Left)
                {
                    Position.X = paddle.BoundingRectangle.Left - BoundingRectangle.Width / 2;
                }

                if (BoundingRectangle.Right > paddle.BoundingRectangle.Right)
                {
                    Position.X = paddle.BoundingRectangle.Right + BoundingRectangle.Width / 2;
                }

                Velocity.X = -Velocity.X;
            }
        }
Beispiel #10
0
        public void CollisionLock(Lock l)
        {
            if (BoundingRectangle.Intersects(l.BoundingRectangle) && l.Visible == true)
            {
                PixelPosition = previousPosition;
            }

            if (MySuperProjectile.BoundingRectangle.Intersects(l.BoundingRectangle) && MySuperProjectile.Visible == true && l.Visible == true)
            {
                MySuperProjectile.ProjectileState = SuperProjectile.PROJECTILE_STATE.EXPLODING;
            }

            if (l.open == true)
            {
                l.Visible = false;
            }
        }
Beispiel #11
0
        public void CollisionSentry(Sentry s)
        {
            if (BoundingRectangle.Intersects(s.BoundingRectangle))
            {
                PixelPosition = previousPosition;
            }

            if (MySuperProjectile.BoundingRectangle.Intersects(s.BoundingRectangle) && MySuperProjectile.Visible == true)
            {
                MySuperProjectile.ProjectileState = SuperProjectile.PROJECTILE_STATE.EXPLODING;
                s.Health -= 50;

                //if (s.Health <= 0)
                //{
                //    s.Visible = false;
                //}
            }
        }
Beispiel #12
0
        public bool IsOverlappingPlayer(int gridX, int gridY, Point size)
        {
            Rectangle pointRect = new Rectangle(gridX * Tile.Width, gridY * Tile.Height, size.X * Tile.Width, size.Y * Tile.Height);

            return(BoundingRectangle.Intersects(pointRect));
        }
Beispiel #13
0
            internal void QueryObjectsInRectangle <T>(BoundingRectangle box, IList <T> objects)
                where T : IIndexable
            {
                // если прямоугольник ячейки не пересекается
                // с запрашиваемым прямоугольником - считать нечего
                if (!box.Intersects(_fullRectangle))
                {
                    return;
                }

                // если прямоугольник ячейки целиком содержится в
                // запрашиваемом прямоугольнике - добавляем все объекты рекурсивно
                if (box.ContainsRectangle(this._fullRectangle))
                {
                    addAllObjectsRecursively(objects);
                    return;
                }

                // если прямоугольник объектов ячейки целиком содержится в
                // запрашиваемом прямоугольнике - добавляем все объекты этой ячейки
                if (_geometriesRectangle != null && box.ContainsRectangle(_geometriesRectangle))
                {
                    foreach (IIndexable obj in _objects)
                    {
                        objects.Add((T)obj);
                    }
                }
                else
                {
                    // иначе выполняем проверки на пересечение
                    // прямоугольников для каждого объекта
                    foreach (IIndexable obj in _objects)
                    {
                        if (box.Intersects(obj.BoundingRectangle))
                        {
                            objects.Add((T)obj);
                        }
                    }
                }

                // если дочерние узлы отсутствуют,
                // дальше считать нечего
                if (!HasChildren)
                {
                    return;
                }

                // разбираемся с детьми
                if (_leftUpChild != null)
                {
                    _leftUpChild.QueryObjectsInRectangle(box, objects);
                }

                if (_rightUpChild != null)
                {
                    _rightUpChild.QueryObjectsInRectangle(box, objects);
                }

                if (_rightDownChild != null)
                {
                    _rightDownChild.QueryObjectsInRectangle(box, objects);
                }

                if (_leftDownChild != null)
                {
                    _leftDownChild.QueryObjectsInRectangle(box, objects);
                }
            }
Beispiel #14
0
        public void HandleCollisions()
        {
            // 1. Haal de car-Rectangle op. Deze is op te halen via het veld: BoundingRectangle
            // 2. Zoek uit met welke tiles de Car in contact komt.
            // 3. Loop door deze tiles heen en controleer vervolgens welke collision-type deze tile heeft
            //      3b. Is deze tile passable?
            //      3c. Is deze tile NIET passable? dan is er een collision.
            //

            // this.BoundingRectangle wordt gebruikt om de tiles rondom de auto te vinden.

            int xLeftTile   = (int)Math.Floor((float)BoundingRectangle.Left / Tile.Width);
            int xRightTile  = (int)Math.Ceiling((float)BoundingRectangle.Right / Tile.Width) - 1;
            int yTopTile    = (int)Math.Floor((float)BoundingRectangle.Top / Tile.Height);
            int yBottomTile = (int)Math.Ceiling((float)BoundingRectangle.Bottom / Tile.Height) - 1;

            // Loop door de verticale tiles
            for (int y = yTopTile; y <= yBottomTile; ++y)
            {
                // En door de horizontale tiles
                for (int x = xLeftTile; x <= xRightTile; ++x)
                {
                    TileCollision collision       = track.GetCollisionOfTile(x, y); // Haal collision-type op van de current Tile
                    Rectangle     tileBoundingBox = new Rectangle(x * Tile.Width, y * Tile.Height, Tile.Width, Tile.Height);

                    if (!tileBoundingBox.Intersects(BoundingRectangle) || !BoundingRectangle.Intersects(tileBoundingBox))
                    {
                        break; // ?
                    }

                    switch (collision)
                    {
                    case TileCollision.Road:
                        isOnRoad     = true;
                        isOnGrass    = false;
                        isOnStrip    = false;
                        isOnPSFuel   = false;
                        isOnPSHealth = false;

                        /* Y: Could be used if we want Dirt on the map.
                         * isOnDirt = false;
                         */
                        break;

                    case TileCollision.Grass:
                        isOnRoad     = false;
                        isOnGrass    = true;
                        isOnStrip    = false;
                        isOnPSFuel   = false;
                        isOnPSHealth = false;

                        /* Y: Could be used if we want Dirt on the map.
                         * isOnDirt = false;
                         */
                        health -= 0.05f;
                        break;

                    case TileCollision.Strip:
                        isOnRoad     = false;
                        isOnGrass    = false;
                        isOnStrip    = true;
                        isOnPSFuel   = false;
                        isOnPSHealth = false;

                        /* Y: Could be used if we want Dirt on the map.
                         * isOnDirt = false;
                         */
                        health -= 0.05f;
                        break;

                    case TileCollision.PitstopStrip:
                        this.position.X = lastCheckpoint.BoundingRectangle.Location.X;
                        this.position.Y = lastCheckpoint.BoundingRectangle.Location.Y;
                        position.X     += lastCheckpoint.BoundingRectangle.Width / 2;
                        position.Y     += lastCheckpoint.BoundingRectangle.Height / 2;
                        break;

                    case TileCollision.PitstopFuel:
                        isOnRoad     = false;
                        isOnGrass    = false;
                        isOnStrip    = false;
                        isOnPSFuel   = true;
                        isOnPSHealth = false;

                        /* Y: Could be used if we want Dirt on the map.
                         * isOnDirt = false;
                         */
                        IncreaseFuel(1);
                        break;

                    case TileCollision.PitstopHealth:
                        isOnRoad     = false;
                        isOnGrass    = false;
                        isOnStrip    = false;
                        isOnPSFuel   = false;
                        isOnPSHealth = true;

                        /* Y: Could be used if we want Dirt on the map.
                         * isOnDirt = false;
                         */
                        IncreaseHealth(1);
                        break;

                    /* Y: Could be used if we want Dirt on the map.
                     * case TileCollision.Dirt:
                     *  isOnRoad = false;
                     *  isOnGrass = false;
                     *  isOnStrip = false;
                     *  isOnPSFuel = false;
                     *  isOnPSHealth = false;
                     *  isOnDirt = true;
                     *  break;
                     */

                    case TileCollision.Water:
                        this.position.X = lastCheckpoint.BoundingRectangle.Location.X;
                        this.position.Y = lastCheckpoint.BoundingRectangle.Location.Y;
                        position.X     += lastCheckpoint.BoundingRectangle.Width / 2;
                        position.Y     += lastCheckpoint.BoundingRectangle.Height / 2;
                        break;

                    case TileCollision.Solid:
                        this.position.X = lastCheckpoint.BoundingRectangle.Location.X;
                        this.position.Y = lastCheckpoint.BoundingRectangle.Location.Y;
                        position.X     += lastCheckpoint.BoundingRectangle.Width / 2;
                        position.Y     += lastCheckpoint.BoundingRectangle.Height / 2;
                        break;
                    }
                }
            }
        }
Beispiel #15
0
        public void Update(GameTime gameTime)
        {
            float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;
            float posX    = 0;
            float posY    = 0;
            int   tileX   = 0;
            int   tileY   = 0;


            // Calculate tile position based on the side we are moving towards.
            posX  = Position.X + localBounds.Width / 2 * (int)direction;
            tileX = (int)Math.Floor(posX / 64) - (int)direction;
            tileY = (int)Math.Floor(Position.Y / 48);


            if (isSmashBlock)
            {
                // Calculate tile position based on the side we are moving towards.
                posY  = Position.Y + localBounds.Height / 2 * (int)direction;
                tileX = (int)Math.Floor(Position.X / 64);
                tileY = (int)Math.Floor(posY / 48) - (int)direction;
            }

            if (waitTime > 0)
            {
                // Wait for some amount of time.
                waitTime = Math.Max(0.0f, waitTime - (float)gameTime.ElapsedGameTime.TotalSeconds);
                if (waitTime <= 0.0f)
                {
                    // Then turn around.
                    direction = (G.Globals.Enums.FaceDirection)(-(int)direction);
                }
            }
            else
            {
                if (isSmashBlock)
                {
                    if (Statics.Level.TileEngine.GetCollision(tileX, tileY + (int)direction) == TileCollision.Impassable ||
                        Statics.Level.TileEngine.GetCollision(tileX, tileY + (int)direction) == TileCollision.Platform)
                    {
                        velocity = new Vector2(0.0f, 0.0f);
                        waitTime = MaxWaitTime;
                    }
                }
                //If we're about to run into a wall that isn't a MovableTile move in other direction.
                if (!isSmashBlock && Statics.Level.TileEngine.GetCollision(tileX + (int)direction, tileY) == TileCollision.Impassable ||
                    Statics.Level.TileEngine.GetCollision(tileX + (int)direction, tileY) == TileCollision.Platform)
                {
                    velocity = new Vector2(0.0f, 0.0f);
                    waitTime = MaxWaitTime;
                }
                else
                {
                    if (isSmashBlock)
                    {
                        // Move in the current direction.
                        velocity = new Vector2(0.0f, (int)direction * (MoveSpeed / 2) * elapsed);
                        //velocity = new Vector2((int)direction * MoveSpeed * elapsed, 0.0f);
                    }
                    else
                    {
                        velocity = new Vector2((int)direction * MoveSpeed * elapsed, 0.0f);
                    }

                    position = position + velocity;
                }
            }

            if (Statics.Level.TileEngine.movableTiles.Count > 0)
            {
                //If we're about to run into a MovableTile move in other direction.
                foreach (var movableTile in Statics.Level.TileEngine.movableTiles)
                {
                    if (BoundingRectangle != movableTile.BoundingRectangle)
                    {
                        if (BoundingRectangle.Intersects(movableTile.BoundingRectangle))
                        {
                            direction = (G.Globals.Enums.FaceDirection)(-(int)direction);
                            velocity  = new Vector2((int)direction * MoveSpeed * elapsed, 0.0f);
                        }
                    }
                }
            }
        }
        public void IntersectsCircle()
        {
            var nonOverlappingCircle        = new BoundingCircle(21, 21, 1);
            var closelyNonOverlappingCircle = new BoundingCircle(20.711f, 20.711f, 1);
            var closelyOverlappingCircle    = new BoundingCircle(20.699f, 20.699f, 1);
            var containedCircle             = new BoundingCircle(10, 10, 5);

            Assert.That(_testAabb.Intersects(nonOverlappingCircle), Is.False);
            Assert.That(_testAabb.Intersects(closelyNonOverlappingCircle), Is.False);
            Assert.That(_testAabb.Intersects(closelyOverlappingCircle), Is.True);
            Assert.That(_testAabb.Intersects(containedCircle), Is.True);
        }
Beispiel #17
0
 public void Intersects(BoundingRectangle boundingRectangle1, BoundingRectangle boundingRectangle2, bool expectedToIntersect)
 {
     Assert.AreEqual(expectedToIntersect, boundingRectangle1.Intersects(boundingRectangle2));
     Assert.AreEqual(expectedToIntersect, BoundingRectangle.Intersects(boundingRectangle1, boundingRectangle2));
 }
Beispiel #18
0
        /// <summary>
        /// Handles input, performs physics, and animates the player sprite.
        /// </summary>
        /// <remarks>
        /// We pass in all of the input states so that our game is only polling the hardware
        /// once per frame. We also pass the game's orientation because when using the accelerometer,
        /// we need to reverse our motion when the orientation is in the LandscapeRight orientation.
        /// </remarks>
        public void Update(
            GameTime gameTime,
            KeyboardState keyboardState,
            GamePadState gamePadState,
            TouchCollection touchState,
            AccelerometerState accelState,
            DisplayOrientation orientation)
        {
            velocity.X = 0;
            movement   = 0;
            if (!IsPoweredDown)
            {
                MoveAcceleration = 700f;
                MaxMoveSpeed     = 1750.0f;
                MaxJumpTime      = 0.35f;
            }
            else
            {
                MoveAcceleration = 350f;
                MaxMoveSpeed     = 1750.0f / 2;
                MaxJumpTime      = 0.20f;
            }

            GetInput(keyboardState, gamePadState, touchState, accelState, orientation);
            if (IsPoweredUp)
            {
                powerUpTime = Math.Max(0.0f, powerUpTime - (float)gameTime.ElapsedGameTime.TotalSeconds);
            }
            if (IsPoweredDown)
            {
                powerDownTime = Math.Max(0.0f, powerDownTime - (float)gameTime.ElapsedGameTime.TotalSeconds);
            }
            if (!BoundingRectangle.Intersects(FingerRectangle) && pressed)
            {
                ApplyPhysics(gameTime);

                if (IsAlive && IsOnGround)
                {
                    if (Math.Abs(Velocity.X) - 0.2f > 0)
                    {
                        sprite.PlayAnimation(runAnimation);
                    }
                    else
                    {
                        sprite.PlayAnimation(idleAnimation);
                    }
                }
            }
            else if (isOnGround)
            {
                sprite.PlayAnimation(idleAnimation);
                pressed = false;
            }
            else
            {
                ApplyPhysics(gameTime);
                pressed = false;
            }

            // Clear input.
            movement  = 0.0f;
            isJumping = false;
            if (isOnGround)
            {
                numberOfJumps = 0;
            }
        }
Beispiel #19
0
 protected sealed override bool BoundaryIntersects(BoundingRectangle boundary, BoundingRectangle target)
 {
     return(boundary.Intersects(target));
 }
Beispiel #20
0
 internal bool Intersects(CameraProvider camera) => Bounds.Intersects(ref camera.Bounds);
Beispiel #21
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="a"></param>
 /// <param name="b"></param>
 /// <returns></returns>
 protected override bool Intersects(BoundingRectangle a, ref BoundingRectangle b)
 {
     return(a.Intersects(b));
 }