From ced3d03bdb3ce866d832e03fb212865140905a9a Mon Sep 17 00:00:00 2001 From: Thomas Leyh Date: Sun, 24 Jul 2016 08:14:18 +0200 Subject: Add project files. --- V3/Objects/TextureObject.cs | 76 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 V3/Objects/TextureObject.cs (limited to 'V3/Objects/TextureObject.cs') diff --git a/V3/Objects/TextureObject.cs b/V3/Objects/TextureObject.cs new file mode 100644 index 0000000..b7da6c0 --- /dev/null +++ b/V3/Objects/TextureObject.cs @@ -0,0 +1,76 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Content; +using Microsoft.Xna.Framework.Graphics; +using System; + +namespace V3.Objects +{ + /// + /// Texture objects represent map data like tiles and map objects which are placed on the screen. + /// + public sealed class TextureObject : IGameObject + { + public Vector2 Position { get; set; } + public int Id { get; } + public Rectangle BoundaryRectangle => new Rectangle(mDrawPosition, mTextureSize); + private readonly string mTextureName; + private readonly Point mDrawPosition; + private readonly Point mTextureSize; + private Texture2D mTexture; + private readonly Point mTextureSource; + + /// + /// Creates an empty TextureObject. + /// + public TextureObject() + { + Id = IdGenerator.GetNextId(); + Position = Vector2.Zero; + mDrawPosition = Point.Zero; + mTextureSize = Point.Zero; + mTextureName = "EmptyPixel"; + mTextureSource = Point.Zero; + } + + public TextureObject(Point position, Point drawPosition, Point textureSize, Point textureSource, string textureName) + { + Position = position.ToVector2(); + mDrawPosition = drawPosition; + mTextureSize = textureSize; + mTextureName = textureName; + mTextureSource = textureSource; + } + + public void LoadContent(ContentManager contentManager) + { + mTexture = contentManager.Load("Textures/" + mTextureName); + //mOnePixelTexture = contentManager.Load("Sprites/WhiteRectangle"); + } + + public void Draw(SpriteBatch spriteBatch) + { + spriteBatch.Draw(mTexture, BoundaryRectangle, new Rectangle(mTextureSource, mTextureSize), Color.White); + } + + public IGameObject GetSelf() + { + return this; + } + + public override bool Equals(Object obj) + { + if (obj == null) + return false; + if (obj == this) + return true; + if (!(obj is IGameObject)) + return false; + return Id.Equals(((IGameObject) obj).Id); + } + + public override int GetHashCode() + { + return Id; + } + } +} -- cgit v1.2.1