1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Microsoft.Xna.Framework;
- namespace Robot_Rampage
- {
- public static class Camera
- {
- #region Declarations
- private static Vector2 position = Vector2.Zero;
- private static Vector2 viewPortSize = Vector2.Zero;
- private static Rectangle worldRectangle = new Rectangle(0, 0, 0, 0);
- #endregion
- #region Properties
- public static Vector2 Position
- {
- get { return position; }
- set
- {
- position = new Vector2(
- MathHelper.Clamp(value.X,
- worldRectangle.X,
- worldRectangle.Width - ViewPortWidth),
- MathHelper.Clamp(value.Y,
- worldRectangle.Y,
- worldRectangle.Height - ViewPortHeight));
- }
- }
- public static Rectangle WorldRectangle
- {
- get { return worldRectangle; }
- set { worldRectangle = value; }
- }
- public static int ViewPortWidth
- {
- get { return (int)viewPortSize.X; }
- set { viewPortSize.X = value; }
- }
- public static int ViewPortHeight
- {
- get { return (int)viewPortSize.Y; }
- set { viewPortSize.Y = value; }
- }
- public static Rectangle ViewPort
- {
- get
- {
- return new Rectangle(
- (int)Position.X, (int)Position.Y,
- ViewPortWidth, ViewPortHeight);
- }
- }
- #endregion
- #region Public Methods
- public static void Move(Vector2 offset)
- {
- Position += offset;
- }
- public static bool ObjectIsVisible(Rectangle bounds)
- {
- return (ViewPort.Intersects(bounds));
- }
- public static Vector2 Transform(Vector2 point)
- {
- return point - position;
- }
- public static Rectangle Transform(Rectangle rectangle)
- {
- return new Rectangle(
- rectangle.Left - (int)position.X,
- rectangle.Top - (int)position.Y,
- rectangle.Width,
- rectangle.Height);
- }
- #endregion
- }
- }
|