/******************************************************************************/ /*! \file Sprite.cs \author Kevin Carey Classes for 2D objects and text Copyright © 2007 DigiPen(USA) Corporation. All rights reserved. */ /******************************************************************************/ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Content; using System; namespace Shooting_Range { // Sprite Class // Represents a 2D object class Sprite { // Constructors // Note: Position is center position, not top left public Sprite(Texture2D texture) { m_Texture = texture; m_OverTexture = null; m_Rect = new Rectangle(0, 0, m_Texture.Width, m_Texture.Height); m_IsActive = true; } public Sprite(Texture2D texture, int x, int y) { m_Texture = texture; m_OverTexture = null; m_Rect = new Rectangle(x - (m_Texture.Width / 2), y - (m_Texture.Width / 2), m_Texture.Width, m_Texture.Height); m_IsActive = true; } public Sprite(Texture2D texture, int x, int y, int width, int height) { m_Texture = texture; m_OverTexture = null; m_Rect = new Rectangle(x - (width / 2), y - (height / 2), width, height); m_IsActive = true; } public Sprite(Texture2D texture, Texture2D overTexture, int x, int y, int width, int height) { m_Texture = texture; m_OverTexture = overTexture; m_Rect = new Rectangle(x - (width / 2), y - (height / 2), width, height); m_IsActive = true; } public Sprite(Texture2D texture, Texture2D overTexture, int x, int y, int width, int height, bool isActive) { m_Texture = texture; m_OverTexture = overTexture; m_Rect = new Rectangle(x - (width / 2), y - (height / 2), width, height); m_IsActive = isActive; } // Texture get and set public Texture2D Texture { get { return m_Texture; } set { m_Texture = value; } } // OverTexture get and set public Texture2D OverTexture { get { return m_OverTexture; } } // Rect get and set public Rectangle Rect { get { return m_Rect; } } // PositionX get and set public int PositionX { get { return m_Rect.X + (m_Rect.Width / 2); } set { m_Rect.X = value - (m_Rect.Width / 2); } } // PositionY get and set public int PositionY { get { return m_Rect.Y + (m_Rect.Height / 2); } set { m_Rect.Y = value - (m_Rect.Height / 2); } } // Width get and set public int Width { get { return m_Rect.Width; } set { m_Rect.Width = value; } } // Height get and set public int Height { get { return m_Rect.Height; } set { m_Rect.Height = value; } } // IsActive get and set public bool IsActive { get { return m_IsActive; } set { m_IsActive = value; } } // Default texture of the sprite private Texture2D m_Texture; // Texture to be displayed when the mouse is over the sprite private Texture2D m_OverTexture; // Rectangle location of the sprite private Rectangle m_Rect; // IsActive flag private bool m_IsActive; } // Text class // Class representing a piece of text to be display class Text { // Constructors // Note: Position is top left public Text(String text, SpriteFont font) { m_Text = text; m_Font = font; m_Color = Color.Black; m_Position = Vector2.Zero; m_Scale = Vector2.One; m_IsActive = true; } public Text(String text, SpriteFont font, Color color, Vector2 position) { m_Text = text; m_Font = font; m_Color = color; m_Position = position; m_Scale = Vector2.One; m_IsActive = true; } public Text(String text, SpriteFont font, Color color, Vector2 position, Vector2 scale) { m_Text = text; m_Font = font; m_Color = color; m_Position = position; m_Scale = scale; m_IsActive = true; } public Text(String text, SpriteFont font, Color color, Vector2 position, Vector2 scale, bool isActive) { m_Text = text; m_Font = font; m_Color = color; m_Position = position; m_Scale = scale; m_IsActive = isActive; } // Text get and get public String TextString { get { return m_Text; } set { m_Text = value; } } // Font get and set public SpriteFont Font { get { return m_Font; } set { m_Font = value; } } // Color get and set public Color Color { get { return m_Color; } set { m_Color = value; } } // Position get and set public Vector2 Position { get { return m_Position; } set { m_Position = value; } } // Scale get and set public Vector2 Scale { get { return m_Scale; } set { m_Scale = value; } } // IsActive get and set public bool IsActive { get { return m_IsActive; } set { m_IsActive = value; } } // String of text to be displayed private String m_Text; // Font private SpriteFont m_Font; // Color private Color m_Color; // Position private Vector2 m_Position; // Scale private Vector2 m_Scale; // Active private bool m_IsActive; } }