using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; public class GameObject { protected GameObject parent; public Vector2 position, velocity; protected Color color; protected int layer; protected string id; public GameObject(int layer = 0, string id = "") { this.layer = layer; this.id = id; Reset(); } public virtual void HandleInput(InputHelper inputHelper, GameWorld gameWorld) { } public virtual void Update(GameTime gameTime, GameWorld gameWorld) { } public virtual void Draw(GameTime gameTime, SpriteBatch spriteBatch) { } public virtual void Reset() { position = Vector2.Zero; velocity = Vector2.Zero; } public virtual Vector2 Position { get { return position; } set { position = value; } } public virtual Vector2 Velocity { get { return velocity; } set { velocity = value; } } public virtual Color Color //Property to change color has been added. { get { return color; } set { color = value; } } public virtual Vector2 GlobalPosition { get { if (parent != null) return parent.GlobalPosition + this.Position; else return this.Position; } } public virtual Rectangle BoundingRectangle { get { return new Rectangle((int)GlobalPosition.X, (int)GlobalPosition.Y, 0, 0); } } public static Vector2 calculateIntersectionDepth(Rectangle rectA, Rectangle rectB) { Vector2 minDistance = new Vector2(rectA.Width + rectB.Width, rectA.Height + rectB.Height) / 2; Vector2 centerA = new Vector2(rectA.Center.X, rectA.Center.Y); Vector2 centerB = new Vector2(rectB.Center.X, rectB.Center.Y); Vector2 distance = centerA - centerB; Vector2 depth = Vector2.Zero; if (distance.X > 0) depth.X = minDistance.X - distance.X; else depth.X = -minDistance.X - distance.X; if (distance.Y > 0) depth.Y = minDistance.Y - distance.Y; else depth.Y = -minDistance.Y - distance.Y; return depth; } public virtual int Layer { get { return layer; } set { layer = value; } } public virtual GameObject Parent { get { return parent; } set { parent = value; } } public string ID { get { return id; } } }