mirror of
https://github.com/AlexMacocian/MonoGame.Extended.git
synced 2026-07-24 03:56:31 +00:00
ce9fc2459b
* Created unit test project for collisions. * Started on tests * Created unit test project for collisions. * Started on tests * Update collision test * CollisionInfo docs * More docs for CollisionGrid and Cell * Fix obsolete warning for RectangleF.Intersect * Summary for CollisionGrid and CollisionGridCell * QuadTree collision implemented - Ported from C++ from Game Physics Cookbook chapter 6, 2D Optimizations * Small refactor for QuadTree naming * First tests for QuadTree * Fix test * COde Cleanup * Added DefaultMaxObjectsPerNode * Add missed Query code * Insert Tests and bugfix * Fix bug with QuadTree.Shake * Fix namespaces * Query tests and fix * Additional test for Query * Initial QuadTreeCollision Component * Basic collision demo working * Spikey ball colliding with walls * Improved the collision demo * Update QuadTree * Added comment for CollisionComponent * Ignore test that needs fixed * Rename QuadTree to Quadtree * Fix penetration vector * Update to 2.0 and xUnit
46 lines
1.6 KiB
C#
46 lines
1.6 KiB
C#
|
|
|
|
namespace MonoGame.Extended.Collisions
|
|
{
|
|
/// <summary>
|
|
/// Represents a single cell in a collision grid.
|
|
/// </summary>
|
|
public class CollisionGridCell : ICollidable
|
|
{
|
|
private readonly CollisionGrid _parentGrid;
|
|
|
|
/// <summary>
|
|
/// Creates a collision grid cell at a location in the parent grid.
|
|
/// </summary>
|
|
/// <param name="parentGrid">The collision grid which this cell is a part of.</param>
|
|
/// <param name="column">The column position of this cell.</param>
|
|
/// <param name="row">The row position of this cell.</param>
|
|
/// <param name="data"></param>
|
|
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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Gets the Column in the parent grid that this cell represents.
|
|
/// </summary>
|
|
public int Column { get; }
|
|
|
|
/// <summary>
|
|
/// Gets the Row in the parent grid that this cell represents.
|
|
/// </summary>
|
|
public int Row { get; }
|
|
public int Data { get; private set; }
|
|
public object Tag { get; set; }
|
|
public CollisionGridCellFlag Flag { get; set; }
|
|
|
|
/// <summary>
|
|
/// Gets the bounding box of the cell.
|
|
/// </summary>
|
|
public RectangleF BoundingBox => _parentGrid.GetCellRectangle(Column, Row).ToRectangleF();
|
|
}
|
|
} |