diff --git a/src/cs/MonoGame.Extended.Collisions/CollisionActor.cs b/src/cs/MonoGame.Extended.Collisions/CollisionActor.cs deleted file mode 100644 index 1b50c2c7..00000000 --- a/src/cs/MonoGame.Extended.Collisions/CollisionActor.cs +++ /dev/null @@ -1,33 +0,0 @@ -using Microsoft.Xna.Framework; - -namespace MonoGame.Extended.Collisions -{ - public class CollisionActor : IActorTarget - { - private readonly IActorTarget _target; - - public CollisionActor(IActorTarget target) - { - _target = target; - } - - public Vector2 Velocity - { - get { return _target.Velocity; } - set { _target.Velocity = value; } - } - - public Vector2 Position - { - get { return _target.Position; } - set { _target.Position = value; } - } - - public RectangleF BoundingBox => _target.BoundingBox; - - public void OnCollision(CollisionInfo collisionInfo) - { - _target.OnCollision(collisionInfo); - } - } -} \ No newline at end of file diff --git a/src/cs/MonoGame.Extended.Collisions/CollisionGrid.cs b/src/cs/MonoGame.Extended.Collisions/CollisionGrid.cs deleted file mode 100644 index 2554dc38..00000000 --- a/src/cs/MonoGame.Extended.Collisions/CollisionGrid.cs +++ /dev/null @@ -1,101 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using Microsoft.Xna.Framework; - -namespace MonoGame.Extended.Collisions -{ - /// - /// Represents a collision grid. This is used to break the game world into - /// chunks to detect collisions efficiently. - /// - public class CollisionGrid - { - private readonly CollisionGridCell[] _data; - - /// - /// Creates a new collision grid of specified size. - /// - /// - /// Number of columns in the grid. - /// Number of rows in the grid. - /// The width of each individual cell. - /// The height of each individual cell. - public CollisionGrid(int[] data, int columns, int rows, int cellWidth, int cellHeight) - { - _data = new CollisionGridCell[data.Length]; - - for (var y = 0; y < rows; y++) - for (var x = 0; x < columns; x++) - { - var index = x + y*columns; - _data[index] = new CollisionGridCell(this, x, y, data[index]); - } - - Columns = columns; - Rows = rows; - CellWidth = cellWidth; - CellHeight = cellHeight; - } - - /// - /// Gets the number of columns in this grid. - /// - public int Columns { get; } - - /// - /// Gets the number of rows in this grid. - /// - public int Rows { get; private set; } - - /// - /// Gets the width of each cell. - /// - public int CellWidth { get; } - - /// - /// Gets the height of each cell. - /// - public int CellHeight { get; } - - public CollisionGridCell GetCellAtIndex(int column, int row) - { - var index = column + row*Columns; - - if ((index < 0) || (index >= _data.Length)) - return new CollisionGridCell(this, column, row, 0); - - return _data[index]; - } - - public CollisionGridCell GetCellAtPosition(Vector3 position) - { - var column = (int) (position.X/CellWidth); - var row = (int) (position.Y/CellHeight); - - return GetCellAtIndex(column, row); - } - - public IEnumerable GetCellsOverlappingRectangle(RectangleF rectangle) - { - var sx = (int) (rectangle.Left/CellWidth); - var sy = (int) (rectangle.Top/CellHeight); - var ex = (int) (rectangle.Right/CellWidth + 1); - var ey = (int) (rectangle.Bottom/CellHeight + 1); - - for (var y = sy; y < ey; y++) - for (var x = sx; x < ex; x++) - yield return GetCellAtIndex(x, y); - } - - public IEnumerable GetCollidables(RectangleF overlappingRectangle) - { - return GetCellsOverlappingRectangle(overlappingRectangle) - .Where(cell => cell.Flag != CollisionGridCellFlag.Empty); - } - - public Rectangle GetCellRectangle(int column, int row) - { - return new Rectangle(column*CellWidth, row*CellHeight, CellWidth, CellHeight); - } - } -} \ No newline at end of file diff --git a/src/cs/MonoGame.Extended.Collisions/CollisionGridCell.cs b/src/cs/MonoGame.Extended.Collisions/CollisionGridCell.cs deleted file mode 100644 index c30ca813..00000000 --- a/src/cs/MonoGame.Extended.Collisions/CollisionGridCell.cs +++ /dev/null @@ -1,46 +0,0 @@ - - -namespace MonoGame.Extended.Collisions -{ - /// - /// Represents a single cell in a collision grid. - /// - public class CollisionGridCell : ICollidable - { - private readonly CollisionGrid _parentGrid; - - /// - /// Creates a collision grid cell at a location in the parent grid. - /// - /// The collision grid which this cell is a part of. - /// The column position of this cell. - /// The row position of this cell. - /// - public CollisionGridCell(CollisionGrid parentGrid, int column, int row, int data) - { - _parentGrid = parentGrid; - Column = column; - Row = row; - Data = data; - Flag = data == 0 ? CollisionGridCellFlag.Empty : CollisionGridCellFlag.Solid; - } - - /// - /// Gets the Column in the parent grid that this cell represents. - /// - public int Column { get; } - - /// - /// Gets the Row in the parent grid that this cell represents. - /// - public int Row { get; } - public int Data { get; private set; } - public object Tag { get; set; } - public CollisionGridCellFlag Flag { get; set; } - - /// - /// Gets the bounding box of the cell. - /// - public RectangleF BoundingBox => _parentGrid.GetCellRectangle(Column, Row).ToRectangleF(); - } -} \ No newline at end of file diff --git a/src/cs/MonoGame.Extended.Collisions/CollisionGridCellFlag.cs b/src/cs/MonoGame.Extended.Collisions/CollisionGridCellFlag.cs deleted file mode 100644 index 546d2be9..00000000 --- a/src/cs/MonoGame.Extended.Collisions/CollisionGridCellFlag.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace MonoGame.Extended.Collisions -{ - public enum CollisionGridCellFlag - { - Empty, - Solid, - Interesting - } -} \ No newline at end of file diff --git a/src/cs/MonoGame.Extended.Collisions/CollisionInfo.cs b/src/cs/MonoGame.Extended.Collisions/CollisionInfo.cs deleted file mode 100644 index bcc8efcc..00000000 --- a/src/cs/MonoGame.Extended.Collisions/CollisionInfo.cs +++ /dev/null @@ -1,21 +0,0 @@ -using Microsoft.Xna.Framework; - -namespace MonoGame.Extended.Collisions -{ - /// - /// This class holds data on a collision. It is passed as a parameter to - /// OnCollision methods. - /// - public class CollisionInfo - { - /// - /// Gets the object being collided with. - /// - public ICollidable Other { get; internal set; } - - /// - /// Gets a vector representing the overlap between the two objects. - /// - public Vector2 PenetrationVector { get; internal set; } - } -} \ No newline at end of file diff --git a/src/cs/MonoGame.Extended.Collisions/CollisionWorld.cs b/src/cs/MonoGame.Extended.Collisions/CollisionWorld.cs deleted file mode 100644 index a02a4151..00000000 --- a/src/cs/MonoGame.Extended.Collisions/CollisionWorld.cs +++ /dev/null @@ -1,88 +0,0 @@ -using System; -using System.Collections.Generic; -using Microsoft.Xna.Framework; - -namespace MonoGame.Extended.Collisions -{ - public class CollisionWorld : IDisposable, IUpdate - { - private readonly List _actors; - - private readonly Vector2 _gravity; - private CollisionGrid _grid; - - public CollisionWorld(Vector2 gravity) - { - _gravity = gravity; - _actors = new List(); - } - - public void Dispose() - { - } - - public void Update(GameTime gameTime) - { - var deltaTime = (float) gameTime.ElapsedGameTime.TotalSeconds; - - foreach (var actor in _actors) - { - actor.Velocity += _gravity*deltaTime; - actor.Position += actor.Velocity*deltaTime; - - if (_grid != null) - foreach (var collidable in _grid.GetCollidables(actor.BoundingBox)) - { - var intersection = RectangleF.Intersection(collidable.BoundingBox, actor.BoundingBox); - - if (intersection.IsEmpty) - continue; - - var info = GetCollisionInfo(actor, collidable, intersection); - actor.OnCollision(info); - } - } - } - - public CollisionActor CreateActor(IActorTarget target) - { - var actor = new CollisionActor(target); - _actors.Add(actor); - return actor; - } - - public CollisionGrid CreateGrid(int[] data, int columns, int rows, int cellWidth, int cellHeight) - { - if (_grid != null) - throw new InvalidOperationException("Only one collision grid can be created per world"); - - _grid = new CollisionGrid(data, columns, rows, cellWidth, cellHeight); - return _grid; - } - - private CollisionInfo GetCollisionInfo(ICollidable first, ICollidable second, RectangleF intersectingRectangle) - { - var info = new CollisionInfo - { - Other = second - }; - - if (intersectingRectangle.Width < intersectingRectangle.Height) - { - var d = first.BoundingBox.Center.X < second.BoundingBox.Center.X - ? intersectingRectangle.Width - : -intersectingRectangle.Width; - info.PenetrationVector = new Vector2(d, 0); - } - else - { - var d = first.BoundingBox.Center.Y < second.BoundingBox.Center.Y - ? intersectingRectangle.Height - : -intersectingRectangle.Height; - info.PenetrationVector = new Vector2(0, d); - } - - return info; - } - } -} \ No newline at end of file diff --git a/src/cs/MonoGame.Extended.Collisions/CollisionWorldExtensions.cs b/src/cs/MonoGame.Extended.Collisions/CollisionWorldExtensions.cs deleted file mode 100644 index ba9f22fd..00000000 --- a/src/cs/MonoGame.Extended.Collisions/CollisionWorldExtensions.cs +++ /dev/null @@ -1,17 +0,0 @@ -//using System.Linq; -//using MonoGame.Extended.Tiled; - -//namespace MonoGame.Extended.Collisions -//{ -// public static class CollisionWorldExtensions -// { -// public static CollisionGrid CreateGrid(this CollisionWorld world, TiledTileLayer tileLayer) -// { -// var data = tileLayer.Tiles -// .Select(t => (int)t.GlobalIdentifier) -// .ToArray(); - -// return world.CreateGrid(data, tileLayer.Width, tileLayer.Height, tileLayer.TileWidth, tileLayer.TileHeight); -// } -// } -//} \ No newline at end of file diff --git a/src/cs/MonoGame.Extended.Collisions/IActorTarget.cs b/src/cs/MonoGame.Extended.Collisions/IActorTarget.cs deleted file mode 100644 index df93ea9e..00000000 --- a/src/cs/MonoGame.Extended.Collisions/IActorTarget.cs +++ /dev/null @@ -1,15 +0,0 @@ -using Microsoft.Xna.Framework; - -namespace MonoGame.Extended.Collisions -{ - public interface ICollidable - { - RectangleF BoundingBox { get; } - } - - public interface IActorTarget : IMovable, ICollidable - { - Vector2 Velocity { get; set; } - void OnCollision(CollisionInfo collisionInfo); - } -} \ No newline at end of file