Example #1
0
        public RotatedRectangle(RectangleF rectangle, Single rotation)
            : base(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height)
        {
            this.Rotation = rotation;

            // Calculate the Rectangle's origin. We assume the center of the Rectangle will
            // be the point that we will be rotating around and we use that for the origin
            Origin = new Vector2(Width / 2, Height / 2);
        }
Example #2
0
 /// <summary>
 /// Checks to see if a <see cref="RectangleF"/> has collided with a <see cref="RotatedRectangle"/>.
 /// </summary>
 /// <param name="rectangle"></param>
 /// <param name="overlap"></param>
 /// <returns></returns>
 public bool Intersects(RectangleF rectangle, out Single overlap, out Vector2 collisionProjection)
 {
     return Intersects(new RotatedRectangle(rectangle, 0), out overlap, out collisionProjection);
 }
Example #3
0
 public static RectangleF WorldUnitsToPixels(RectangleF rectangle)
 {
     return new RectangleF(rectangle.X * WorldToPixel, rectangle.Y * WorldToPixel,
                           rectangle.Width * WorldToPixel, rectangle.Height * WorldToPixel);
 }
Example #4
0
        public override void Draw(GameTime gameTime)
        {
            // FIRST Draw pass: the background
            spriteBatch.Begin(SpriteBlendMode.None,
                              SpriteSortMode.Immediate,
                              SaveStateMode.None,
                              camera.GetViewMatrix());

            // magic to tile
            GraphicsDevice.SamplerStates[0].AddressU = TextureAddressMode.Wrap;
            GraphicsDevice.SamplerStates[0].AddressV = TextureAddressMode.Wrap;

            RectangleF bgRect = new RectangleF(camera.CameraPosition,
                                               new Vector2(GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height));

            Single resizeByX = Math.Abs(camera.Origin.X / camera.Zoom);
            Single resizeByY = Math.Abs(camera.Origin.Y / camera.Zoom);

            bgRect.X -= resizeByX;
            bgRect.Y -= resizeByY;

            bgRect.Width += 2 * resizeByX;
            bgRect.Height += 2 * resizeByY;

            // draw the grass background
            spriteBatch.Draw(backgroundTexture, (Rectangle)bgRect, (Rectangle)bgRect, Color.White);

            spriteBatch.End();

            // SECOND Draw pass: draw the stretched map objects.
            spriteBatch.Begin(SpriteBlendMode.AlphaBlend,
                              SpriteSortMode.BackToFront,
                              SaveStateMode.None,
                              camera.GetViewMatrix());
            
            mapObjects.TryGetValue("stretched", out stretched);
            foreach (Sprite mapObject in stretched)
                mapObject.Draw(gameTime, spriteBatch);

            spriteBatch.End();

            // THIRD Draw pass: draw the tiled map objects.
            spriteBatch.Begin(SpriteBlendMode.AlphaBlend,
                              SpriteSortMode.Immediate,
                              SaveStateMode.None,
                              camera.GetViewMatrix());

            // using wrapping
            GraphicsDevice.SamplerStates[0].AddressU = TextureAddressMode.Wrap;
            GraphicsDevice.SamplerStates[0].AddressV = TextureAddressMode.Wrap;

            mapObjects.TryGetValue("tiled", out tiled);
            foreach (Sprite mapObject in tiled)
                mapObject.Draw(gameTime, spriteBatch);

            spriteBatch.End();

            // FOURTH Draw pass: draw the dynamic objects (stretched).
            spriteBatch.Begin(SpriteBlendMode.AlphaBlend,
                              SpriteSortMode.BackToFront,
                              SaveStateMode.None,
                              camera.GetViewMatrix());
            
            foreach (Sprite sprite in dynamicObjects)
                sprite.Draw(gameTime, spriteBatch);

            playerManager.Draw(gameTime, spriteBatch);

            spriteBatch.End();

            // FIFTH Draw pass: draw the HUD components.
            spriteBatch.Begin(SpriteBlendMode.AlphaBlend,
                              SpriteSortMode.BackToFront,
                              SaveStateMode.None);

            scoreHUD.Draw(spriteBatch);

            spriteBatch.End();
           
            base.Draw(gameTime);
        }