From 9f47ad9a5724144a2eeda5e3c312bdd47a6a3a4a Mon Sep 17 00:00:00 2001 From: Simon Holmberg Date: Thu, 18 Oct 2012 01:34:08 +0200 Subject: [PATCH] Documentation added to Component.*, Entity, EntityManager, Grid, GUI.* and Utility classes. Minor cleanups. --- .../DepthsBelow/Component/Collision.cs | 40 +++- .../DepthsBelow/Component/Component.cs | 10 + .../DepthsBelow/Component/PathFinder.cs | 54 +++++- .../DepthsBelow/Component/SpriteRenderer.cs | 19 +- .../DepthsBelow/Component/Transform.cs | 78 +++++++- DepthsBelow/DepthsBelow/DepthsBelow.csproj | 2 +- .../DepthsBelow/DepthsBelow_TemporaryKey.pfx | Bin 1684 -> 0 bytes DepthsBelow/DepthsBelow/Entity.cs | 171 +++++++++++------- DepthsBelow/DepthsBelow/EntityManager.cs | 28 +++ DepthsBelow/DepthsBelow/GUI/Button.cs | 20 +- DepthsBelow/DepthsBelow/GUI/Frame.cs | 60 +++++- DepthsBelow/DepthsBelow/GUI/Text.cs | 13 ++ DepthsBelow/DepthsBelow/Grid.cs | 16 ++ DepthsBelow/DepthsBelow/Utility.cs | 13 +- 14 files changed, 424 insertions(+), 100 deletions(-) delete mode 100644 DepthsBelow/DepthsBelow/DepthsBelow_TemporaryKey.pfx diff --git a/DepthsBelow/DepthsBelow/Component/Collision.cs b/DepthsBelow/DepthsBelow/Component/Collision.cs index c61f7fa..f9da86d 100644 --- a/DepthsBelow/DepthsBelow/Component/Collision.cs +++ b/DepthsBelow/DepthsBelow/Component/Collision.cs @@ -8,25 +8,53 @@ using Microsoft.Xna.Framework.Graphics; namespace DepthsBelow.Component { + /// + /// Component for handling collisions. + /// Contains a rectangle which defines its hitbox. + /// public class Collision : Component { - + /// + /// The collision rectangle. + /// public Rectangle Rectangle; - public int Width; - public int Height; + /// + /// Width of the collision rectangle. + /// + public int Width + { + get { return this.Rectangle.Width; } + set { this.Rectangle.Width = value; } + } + /// + /// Height of the collision rectangle. + /// + public int Height + { + get { return this.Rectangle.Height; } + set { this.Rectangle.Height = value; } + } + /// + /// Create a collision component. + /// + /// Parent entity. + /// Width of the collision rectangle. + /// Height of the collision rectangle. public Collision(Entity parent, int width, int height) : base(parent) { - this.Width = width; - this.Height = height; this.Rectangle = new Rectangle(0, 0, width, height); } + /// + /// Updates the position of the collision rectangle to the position of its parent entity. + /// + /// public override void Update(GameTime gameTime) { - Transform transform = this.Parent.GetComponent(); + var transform = this.Parent.GetComponent(); this.Rectangle.X = (int)transform.World.X; this.Rectangle.Y = (int)transform.World.Y; } diff --git a/DepthsBelow/DepthsBelow/Component/Component.cs b/DepthsBelow/DepthsBelow/Component/Component.cs index 259494b..61a67f5 100644 --- a/DepthsBelow/DepthsBelow/Component/Component.cs +++ b/DepthsBelow/DepthsBelow/Component/Component.cs @@ -6,8 +6,14 @@ using Microsoft.Xna.Framework; namespace DepthsBelow.Component { + /// + /// Base component. + /// public class Component { + /// + /// Parent entity of which the component belongs. + /// public Entity Parent; public Component(Entity parent) @@ -15,6 +21,10 @@ namespace DepthsBelow.Component Parent = parent; } + /// + /// Virtual component update function. + /// + /// public virtual void Update(GameTime gameTime) { diff --git a/DepthsBelow/DepthsBelow/Component/PathFinder.cs b/DepthsBelow/DepthsBelow/Component/PathFinder.cs index 42309c0..de9e7ba 100755 --- a/DepthsBelow/DepthsBelow/Component/PathFinder.cs +++ b/DepthsBelow/DepthsBelow/Component/PathFinder.cs @@ -8,14 +8,34 @@ using Microsoft.Xna.Framework; namespace DepthsBelow.Component { + /// + /// Component that handles pathfinding. + /// public class PathFinder : Component { + /// + /// A pathfinder node. + /// public class Node { + /// + /// Grid position of the node. + /// public Point Position; + /// + /// A* F-score + /// public int F; + /// + /// A* G-score + /// public int G; + /// + /// Explicit conversion between A* library node and Node object. + /// + /// + /// public static explicit operator Node(AStar.PathFinderNode aStarNode) { return new Node @@ -27,22 +47,36 @@ namespace DepthsBelow.Component } } + /// + /// Start position of the path. + /// public Point Start { get; private set; } + /// + /// A collision bytemap. + /// 0 = unwalkable node + /// 1 = walkable node + /// public byte[,] CollisionMap; private Point goal; + /// + /// Sets a goal point and finds a path to it. + /// After a path is created, call Next() go get the next node in the path. + /// public Point Goal { get { return goal; } set { this.goal = value; - //this.Start = this.Parent.GetComponent().Grid.Position; this.FindPath(this.Parent.GetComponent().Grid.Position, value, null); } } + /// + /// Is a path in progress? + /// public bool IsMoving { get @@ -74,6 +108,10 @@ namespace DepthsBelow.Component base.Update(gameTime); } + /// + /// Gets the next node of the current path. + /// + /// The next node in the path. public Node Next() { if (path == null) @@ -87,11 +125,21 @@ namespace DepthsBelow.Component return (Node)nextNode; } + /// + /// Cancels the current path in memory. + /// public void Stop() { path = null; } + /// + /// Finds a path between two points. + /// + /// The start point. + /// The goal point. + /// A list of unwalkable points that will be joined with the original collision map. + /// private List FindPath(Point start, Point goal, List appendCollisionMap) { byte[,] mapCollisionMap = Core.Map.GetCollisionMap(); @@ -123,6 +171,10 @@ namespace DepthsBelow.Component return path; } + /// + /// Recreate the current path in memory with a list of unwalkable points that will be joined with the original collision map. + /// + /// A list of unwalkable points that will be joined with the collision map. public void RecreatePath(List appendCollisionMap) { FindPath(this.Parent.GetComponent().Grid.Position, this.Goal, appendCollisionMap); diff --git a/DepthsBelow/DepthsBelow/Component/SpriteRenderer.cs b/DepthsBelow/DepthsBelow/Component/SpriteRenderer.cs index 59897dd..e612aa8 100644 --- a/DepthsBelow/DepthsBelow/Component/SpriteRenderer.cs +++ b/DepthsBelow/DepthsBelow/Component/SpriteRenderer.cs @@ -7,14 +7,28 @@ using Microsoft.Xna.Framework.Graphics; namespace DepthsBelow.Component { + /// + /// Sprite render component. + /// Handles rendering of a 2D texture. + /// public class SpriteRenderer : Component { + /// + /// The texture to be rendered. + /// public Texture2D Texture; + /// + /// Color modifier. + /// public Color Color; + /// + /// Scale of the texture. + /// public float Scale; public SpriteEffects SpriteEffects; - public SpriteRenderer(Entity parent) : base(parent) + public SpriteRenderer(Entity parent) + : base(parent) { this.Color = Color.White; this.Scale = 1; @@ -23,8 +37,7 @@ namespace DepthsBelow.Component public void Draw(SpriteBatch spriteBatch) { - Transform transform = this.Parent.GetComponent(); - //spriteBatch.Draw(Texture, tc.Position, this.Color); + var transform = this.Parent.GetComponent(); spriteBatch.Draw(Texture, transform.World.Position + new Vector2(Grid.TileSize / 2, Grid.TileSize / 2), null, Color, transform.World.Rotation, transform.World.Origin, Scale, SpriteEffects, 0); } } diff --git a/DepthsBelow/DepthsBelow/Component/Transform.cs b/DepthsBelow/DepthsBelow/Component/Transform.cs index c7a451c..68fe14b 100755 --- a/DepthsBelow/DepthsBelow/Component/Transform.cs +++ b/DepthsBelow/DepthsBelow/Component/Transform.cs @@ -7,11 +7,21 @@ using Microsoft.Xna.Framework; namespace DepthsBelow.Component { + /// + /// Transform component. + /// Handles both grid and world positions and rotations, while keeping them in sync. + /// public class Transform : Component { + /// + /// Represents a grid position. + /// public class GridTransform { private Point position; + /// + /// Sets the grid position and updates the world position of WorldTransform. + /// public Point Position { get { return position; } @@ -22,6 +32,9 @@ namespace DepthsBelow.Component } } + /// + /// Shorthand for the grid x-position. + /// public int X { get { return position.X; } @@ -31,6 +44,10 @@ namespace DepthsBelow.Component masterTransform.World.SetWithoutRelation((Vector2)this); } } + + /// + /// Shorthand for the grid y-position. + /// public int Y { get { return position.Y; } @@ -41,11 +58,17 @@ namespace DepthsBelow.Component } } + /// + /// Implicit conversion between GridTransform and a Point grid position. + /// public static implicit operator Point(GridTransform gridTransform) { return gridTransform.position; } + /// + /// Explicit conversion between GridTransform and a Vector2 world position. + /// public static explicit operator Vector2(GridTransform gridTransform) { var worldPosition = DepthsBelow.Grid.GridToWorld(gridTransform.Position); @@ -53,11 +76,19 @@ namespace DepthsBelow.Component } private readonly Transform masterTransform; + /// + /// Create a GridTransform within a master Transform component. + /// + /// The master Transform component. public GridTransform(Transform masterTransform) { this.masterTransform = masterTransform; } + /// + /// Sets the position data without updating the associated world position. + /// + /// The grid position. public void SetWithoutRelation(Point position) { this.position = position; @@ -67,6 +98,9 @@ namespace DepthsBelow.Component public class WorldTransform { private Vector2 position; + /// + /// Sets the world position and updates the grid position of GridTransform. + /// public Vector2 Position { get { return position; } @@ -77,6 +111,9 @@ namespace DepthsBelow.Component } } + /// + /// Shorthand for the world x-position. + /// public float X { get { return position.X; } @@ -86,6 +123,10 @@ namespace DepthsBelow.Component masterTransform.Grid.SetWithoutRelation((Point)this); } } + + /// + /// Shorthand for the world y-position. + /// public float Y { get { return position.Y; } @@ -96,20 +137,27 @@ namespace DepthsBelow.Component } } + /// + /// Rotation in radians. + /// public float Rotation; - public void Rotate(int directionX, int directionY) - { - Rotation = (float)Math.Atan(directionY/directionX); - } - + /// + /// Origin to rotate around. + /// public Vector2 Origin; + /// + /// Implicit conversion between WorldTransform and a Vector2 world position. + /// public static implicit operator Vector2(WorldTransform worldTransform) { return worldTransform.Position; } + /// + /// Explicit conversion between WorldTransform and a Point grid position. + /// public static explicit operator Point(WorldTransform worldTransform) { var gridPosition = DepthsBelow.Grid.WorldToGrid(worldTransform.Position); @@ -117,18 +165,32 @@ namespace DepthsBelow.Component } private readonly Transform masterTransform; + /// + /// Create a WorldTransform within a master Transform component. + /// + /// The master Transform component. public WorldTransform(Transform masterTransform) { this.masterTransform = masterTransform; } + /// + /// Sets the position data without updating the associated grid position. + /// + /// The world position. public void SetWithoutRelation(Vector2 position) { this.position = position; } } + /// + /// The grid position. + /// public GridTransform Grid; + /// + /// The world position. + /// public WorldTransform World; public Transform(Entity parent) @@ -138,11 +200,17 @@ namespace DepthsBelow.Component World = new WorldTransform(this); } + /// + /// Implicit conversion between Transform and a Point grid position. + /// public static implicit operator Point(Transform transform) { return transform.Grid; } + /// + /// Implicit conversion between Transform and a Vector2 world position. + /// public static implicit operator Vector2(Transform transform) { return transform.World; diff --git a/DepthsBelow/DepthsBelow/DepthsBelow.csproj b/DepthsBelow/DepthsBelow/DepthsBelow.csproj index fca0875..f67f7a9 100644 --- a/DepthsBelow/DepthsBelow/DepthsBelow.csproj +++ b/DepthsBelow/DepthsBelow/DepthsBelow.csproj @@ -47,6 +47,7 @@ false x86 false + bin\x86\Debug\DepthsBelow.XML pdbonly @@ -193,7 +194,6 @@ - diff --git a/DepthsBelow/DepthsBelow/DepthsBelow_TemporaryKey.pfx b/DepthsBelow/DepthsBelow/DepthsBelow_TemporaryKey.pfx deleted file mode 100644 index 826b25df927d15d0b1ae0830003a82304ea8cc4d..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1684 zcmY*YdpOit7(Tz5@f(w5$|aR?N$d#q8@Xo_MQoF3w%T=BDr#yc$z_n-#zbi?Ghsz8 znPr+J31iAoE-6fdsMw0Ki76Gv)M|?T)w7qU=X<_$-uFGuzGKTXN33zfLC-b)-2%YUxvvuWIB;x=V!DE9jFml2yS>p<$sd*>k1iLTE44 z6!EG+$&h#B*cETy%YS&Co_y?fiOZTsfBD@@#`^i$Ia|4=meD7v0Ey1j2t9#WxqhCi zHl@A5bKT0cup%R#m4WoW^`4N%p_hK9UDp!)7>Y@mLMOdHM?APzx!w7ZfmSy#e1sny zDZe|@V3FYvr4{4w;mEnCy#tM7S$SN$YbdPF(mz`Gg_WmR3@AM2j z<&DpsT^}AVjH^F%PfL~=rt4)=X!Yt^Os&|%V4r9WmNz?nqxUSq*rbXat$(UCcfEOGsDif{jv*~{*%~nH6$s$&qsPuR;-NM z*idD@butu+vp8ctiCIu?<#b6Rs~peZ*=JTwduOB=7zZdc3{?JzmTbOcP#4~6&T%js z3HH=~{u9@L*q40V1TQkgADiMQejMM1bAoq_Wy+b4r%6sE8JA*Oq@HZ->1V#2EPXao zn(swP?nN~J8*_p-1;*hZ0083mzoi6H_JMG41Vo^@ zA4CE}KttEhN+>vhvP~$C1!1Um1m)pi4~pqux(tE$mpUfOftrY>hWeyfu|k z{Cdh&)ohL9($49Wop&8I26B(ooPubZVmTCL>}g?0+d)q@C(E^wr}!XTZ0+kvh#YH) zQq{>4K$5_Rv136$J>UMiVOZ1a7AY|)VFy`LOYqeh+qezxf+QztmAY)%ruxkn;-wx!BfE<-(M)Le<1K7civ;J)4x4?nYMsIt z?ZS$hHaB0#x%s8EG`-=rMFXqt538s*`-oL%&r;oI{fkECNB1_oS))@nan)ak&vzKk z_5ZlaBSewOFXOLesP#V`XFI2GS5S@QfwdVMr9JDzTSCbKQ(G%9vg;U#bL*(;m?Rj6 z8(9j12Dgk_t#vl1YUX>hoYilGvg%cz?%(msdS+KJ6iLcl>iaS(prNv+R7G!9VY0b5 zNmN>xubU1Iw0D}Ew+O3I`W7A3TqkiVJ*d^RM*G0SmUw>*au{ca@+b1tx-)K$wZJ1hdm daauu)vZ3lGte%s+o*$SR8%?KUS9~70zX6=t*`@#h diff --git a/DepthsBelow/DepthsBelow/Entity.cs b/DepthsBelow/DepthsBelow/Entity.cs index 5941f63..d7722eb 100644 --- a/DepthsBelow/DepthsBelow/Entity.cs +++ b/DepthsBelow/DepthsBelow/Entity.cs @@ -1,83 +1,118 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using Microsoft.Xna.Framework; - -namespace DepthsBelow -{ - public class Entity : IDisposable - { - List Components; - public Component.Transform Transform; - - public int X - { - get { return this.Transform.Grid.X; } - set - { - this.Transform.Grid.X = value; - } - } - public int Y - { - get { return this.Transform.Grid.Y; } - set - { - this.Transform.Grid.Y = value; - } +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Microsoft.Xna.Framework; + +namespace DepthsBelow +{ + /// + /// Game object. + /// + public class Entity : IDisposable + { + List Components; + + /// + /// Shorthand for transform component. + /// + public Component.Transform Transform; + + private EntityManager entityManager; + + /// + /// Shorthand to the grid transform position. + /// + public Point Position + { + get { return this.Transform.Grid.Position; } + set { this.Transform.Grid.Position = value; } + } + /// + /// Shorthand to the grid transform x-position. + /// + public int X + { + get { return this.Transform.Grid.X; } + set { this.Transform.Grid.X = value; } + } + /// + /// Shorthand to the grid transform y-position. + /// + public int Y + { + get { return this.Transform.Grid.Y; } + set { this.Transform.Grid.Y = value; } } - private EntityManager entityManager; - - public Entity(EntityManager entityManager) + /// + /// Creates a game object and adds it to the referenced entity manager. + /// + /// An instance of EntityManager to add the entity to. + public Entity(EntityManager entityManager) { this.entityManager = entityManager; entityManager.Add(this); - - Components = new List(); - - Transform = new Component.Transform(this); - AddComponent(Transform); + + Components = new List(); + + Transform = new Component.Transform(this); + AddComponent(Transform); } + /// + /// Implementation of IDisposable. + /// Dispose of any unmanaged resources. + /// public virtual void Dispose() { - } - + } + + /// + /// Removes the entity from the game world and disposes + /// potential unmanaged resources. + /// public virtual void Remove() { entityManager.Remove(this); Dispose(); - } - - public virtual void Kill() + } + + /// + /// Get the reference to a component contained in the entity. + /// + /// The component type. + /// Returns the component of requested type. + public T GetComponent() where T : Component.Component { - Remove(); - } - - public T GetComponent() where T : Component.Component - { - foreach (Component.Component c in Components) - { - if (c is T) - return (T)c; - } - - return null; - } - - public void AddComponent(Component.Component c) - { - Components.Add(c); - } - - public virtual void Update(GameTime gameTime) - { - // Update components - foreach (Component.Component c in Components) - c.Update(gameTime); - } - } -} + foreach (Component.Component c in Components) + { + if (c is T) + return (T)c; + } + + return null; + } + + /// + /// Add a component to the entity. + /// + /// the component to add + public void AddComponent(Component.Component c) + { + Components.Add(c); + } + + /// + /// Update the entity and all child components. + /// + /// + public virtual void Update(GameTime gameTime) + { + // Update components + foreach (Component.Component c in Components) + c.Update(gameTime); + } + } +} diff --git a/DepthsBelow/DepthsBelow/EntityManager.cs b/DepthsBelow/DepthsBelow/EntityManager.cs index c064d7b..ea781da 100755 --- a/DepthsBelow/DepthsBelow/EntityManager.cs +++ b/DepthsBelow/DepthsBelow/EntityManager.cs @@ -7,6 +7,9 @@ using Microsoft.Xna.Framework.Graphics; namespace DepthsBelow { + /// + /// Manages a group of entities. + /// public class EntityManager : IDisposable { private List entities; @@ -16,22 +19,39 @@ namespace DepthsBelow entities = new List(); } + /// + /// Implementation of IDisposable. + /// Dispose of the entity manager, and all entities it contains. + /// public void Dispose() { foreach (var entity in entities) entity.Dispose(); + + entities = null; } + /// + /// Add an entity to the entity manager. + /// + /// The entity to add. public void Add(Entity entity) { entities.Add(entity); } + /// + /// Remove an entity from the entity manager. + /// + /// The entity to remove. public void Remove(Entity entity) { entities.Remove(entity); } + /// + /// Reset the entity manager, disposing any entities it contains. + /// public void Reset() { foreach (var entity in entities) @@ -40,12 +60,20 @@ namespace DepthsBelow entities.Clear(); } + /// + /// Update all entities handled by the entity manager. + /// + /// public void Update(GameTime gameTime) { foreach (var entity in entities) entity.Update(gameTime); } + /// + /// Draw all entities handled by the entity manager. + /// + /// public void Draw(SpriteBatch spriteBatch) { foreach (var entity in entities) diff --git a/DepthsBelow/DepthsBelow/GUI/Button.cs b/DepthsBelow/DepthsBelow/GUI/Button.cs index 4d2c23d..a099ff9 100755 --- a/DepthsBelow/DepthsBelow/GUI/Button.cs +++ b/DepthsBelow/DepthsBelow/GUI/Button.cs @@ -9,19 +9,20 @@ using Microsoft.Xna.Framework.Input; namespace DepthsBelow.GUI { + /// + /// A button frame which can handle clicks. + /// public class Button : Frame { public delegate void OnClickHandler(Point pos); + /// + /// Handler of OnClick events. + /// public OnClickHandler OnClick; private MouseState lastMouseState; - /*public void OnClick(Point pos) - { - Debug.WriteLine(this + " was clicked at (" + pos.X + "," + pos.Y + ")"); - }*/ - public Button() : base() { @@ -29,7 +30,7 @@ namespace DepthsBelow.GUI } public Button(Frame parent) - : this() + : this() { this.Parent = parent; } @@ -59,12 +60,5 @@ namespace DepthsBelow.GUI lastMouseState = ms; } - - public override void Draw(SpriteBatch spriteBatch) - { - //spriteBatch.DrawString(Font, Value, new Vector2(Rectangle.X + Parent.Rectangle.X, Rectangle.Y + Parent.Rectangle.Y), Color); - - base.Draw(spriteBatch); - } } } diff --git a/DepthsBelow/DepthsBelow/GUI/Frame.cs b/DepthsBelow/DepthsBelow/GUI/Frame.cs index 61c551e..9cac473 100755 --- a/DepthsBelow/DepthsBelow/GUI/Frame.cs +++ b/DepthsBelow/DepthsBelow/GUI/Frame.cs @@ -8,48 +8,87 @@ using Microsoft.Xna.Framework.Graphics; namespace DepthsBelow.GUI { + /// + /// A generic GUI frame. + /// public class Frame { public string Name; + /// + /// Width of the frame. + /// public int Width { get { return this.Rectangle.Width; } set { this.Rectangle.Width = value; } } + /// + /// Height of the frame. + /// public int Height { get { return this.Rectangle.Height; } set { this.Rectangle.Height = value; } } + /// + /// X-position of the frame. + /// public int X { get { return this.Rectangle.X; } set { this.Rectangle.X = value; } } + /// + /// Y-position of the frame. + /// public int Y { get { return this.Rectangle.Y; } set { this.Rectangle.Y = value; } } + /// + /// Rectangle of the frame. + /// public Rectangle Rectangle; + /// + /// Absolute rectangle of the frame. Takes parent frame positions in consideration. + /// public Rectangle AbsoluteRectangle { get { if (Parent != null) - return new Rectangle(Parent.Rectangle.X + Rectangle.X, Parent.Rectangle.Y + Rectangle.Y, Rectangle.Width, Rectangle.Height); + return new Rectangle(Parent.AbsoluteRectangle.X + Rectangle.X, Parent.AbsoluteRectangle.Y + Rectangle.Y, Rectangle.Width, Rectangle.Height); else return Rectangle; } } + /// + /// Optional background texture of the frame. + /// public Texture2D Texture; + /// + /// Texture color tint. + /// public Color Color; + /// + /// If the frame is visible or not. + /// public bool Visible = true; + /// + /// Potential parent frame. + /// public Frame Parent; + /// + /// Potential children frames. + /// public List Children; + /// + /// Create a blank frame. + /// public Frame() { this.Rectangle = Rectangle.Empty; @@ -61,12 +100,20 @@ namespace DepthsBelow.GUI GUIManager.Add(this); } + /// + /// Create a blank frame as the child of a frame. + /// + /// The parent frame. public Frame(Frame parentFrame) : this() { this.Parent = parentFrame; } + /// + /// Add a child frame to the frame. + /// + /// The child frame to add. public void AddChild(Frame childFrame) { childFrame.Parent = this; @@ -74,12 +121,19 @@ namespace DepthsBelow.GUI Children.Add(childFrame); } + /// + /// Remove a child frame from the frame. + /// + /// The child frame to remove. public void RemoveChild(Frame childFrame) { if (Children.Contains(childFrame)) Children.Remove(childFrame); } + /// + /// Destroys the frame and all its children. + /// public void Destroy() { if (Parent != null) @@ -88,6 +142,10 @@ namespace DepthsBelow.GUI GUIManager.Remove(this); } + /// + /// Set the background texture of the frame. + /// + /// Filename of the texture. public void SetTexture(string fileName) { Texture = GameServices.GetService().Load(fileName); diff --git a/DepthsBelow/DepthsBelow/GUI/Text.cs b/DepthsBelow/DepthsBelow/GUI/Text.cs index 575212a..1c7f212 100755 --- a/DepthsBelow/DepthsBelow/GUI/Text.cs +++ b/DepthsBelow/DepthsBelow/GUI/Text.cs @@ -8,9 +8,18 @@ using Microsoft.Xna.Framework.Graphics; namespace DepthsBelow.GUI { + /// + /// A basic text control. + /// class Text : Frame { + /// + /// Text to display. + /// public String Value; + /// + /// Font to use while rendering. + /// public SpriteFont Font; public Text() @@ -25,6 +34,10 @@ namespace DepthsBelow.GUI this.Parent = parent; } + /// + /// Set the font to use while rendering. + /// + /// Filename of the font. public void SetFont(string spriteFontName) { Font = GameServices.GetService().Load(spriteFontName); diff --git a/DepthsBelow/DepthsBelow/Grid.cs b/DepthsBelow/DepthsBelow/Grid.cs index 92b0e1f..229c987 100644 --- a/DepthsBelow/DepthsBelow/Grid.cs +++ b/DepthsBelow/DepthsBelow/Grid.cs @@ -3,15 +3,31 @@ using Microsoft.Xna.Framework; namespace DepthsBelow { + /// + /// Global grid utility functions. + /// public static class Grid { + /// + /// The size of a tile in pixels. + /// public const int TileSize = 32; + /// + /// Converts a grid position into a world position. + /// + /// The grid position to convert. + /// Returns a Vector2 world position. public static Vector2 GridToWorld(Point gridPos) { return new Vector2(gridPos.X * TileSize, gridPos.Y * TileSize); } + /// + /// Converts a world position into a grid position. + /// + /// The world position to convert. + /// Returns a Point grid position. public static Point WorldToGrid(Vector2 screenPos) { return new Point( diff --git a/DepthsBelow/DepthsBelow/Utility.cs b/DepthsBelow/DepthsBelow/Utility.cs index 408c2c4..1ee1487 100644 --- a/DepthsBelow/DepthsBelow/Utility.cs +++ b/DepthsBelow/DepthsBelow/Utility.cs @@ -6,8 +6,17 @@ using Microsoft.Xna.Framework; namespace DepthsBelow { + /// + /// Various global utility functions. + /// static class Utility { + /// + /// Calculate the chance of an entity with a Stat component to hit another unit. + /// + /// The attacking unit. + /// The recieving unit. + /// Returns a hit chance percentage. public static int CalculateHitChance(Entity attacker, Entity defender) { Component.Stat shooting = attacker.GetComponent(); @@ -23,7 +32,7 @@ namespace DepthsBelow //Console.WriteLine(chanceToHit); return chanceToHit; } - public static bool HitTest(Entity attacker, Entity defender, int chanceToHit) + /*public static bool HitTest(Entity attacker, Entity defender, int chanceToHit) { Component.Stat shooting = attacker.GetComponent(); Component.Stat dodging = defender.GetComponent(); @@ -34,6 +43,6 @@ namespace DepthsBelow return true; } return false; - } + }*/ } }