You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+42Lines changed: 42 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -48,16 +48,58 @@ If you want to contribute to our repository (push, open pull requests), please u
48
48
This class implements a collision-grid.
49
49
When doing game development you've all come across a point when you'd like to do some collision-checks and that's usually the time when you realize that just checking all sprites against each other just doesn't cut it.
50
50
The problem is that the number of checks grow very fast (N² for N sprites) when the number of your sprites grow.
51
+
52
+
So you somehow have to narrow down your collision-candidates.
53
+
This piece of software does that for you. It does not do collision checking itself. It just tells you if a sprite is near enough to a second one to maybe collide which allows you to do a collision test for those two, or three, or five...
54
+
55
+
The first thing is: You have to set-up a grid. Usually you'd take your game-coordinate-system's bounds.
56
+
Then you have to tell the grid how many cells it has by setting the number of cells on the X and Y axis.
57
+
58
+
Then you may add your sprites or other objects to the grid by calling `Add(object, Point/Vector2/Rectangle/Rect)` or `Move(object, Point/Vector2/Rectangle/Rect)`. Move removes the item first if it was present on the grid.
59
+
60
+
### Parameters
61
+
The first parameter is your item. The grid is generic and there are no constraints for that.
62
+
The second parameter is always one of the following:
63
+
| Parameter | Description | Info |
64
+
|:----------|:------------|:-----|
65
+
|Point|This is an int-point.|By specifying this you tell the grid you mean the cell at exactly this position.|
66
+
|Vector2|This is a float-vector.|By specifying this you tell the grid that you mean the cell that contains these game-coordinates.|
67
+
|Rectangle|This is a basic int-rectangle. It is not rotated and therefore axis-alinged. So it's an Axis-Aligned-Bounding-Box or AABB.|By specifying this you give the grid a rectangle in the cell-coordinate-system (0-numberOfCellsX, 0-numberOfCellsY).|
68
+
|Rect|This is a special parameter in our utility-package. It's essentially a Rectangle, but with all float parameters.|By specifying this you give the grid a rectangle in the game-coordinate-system.|
69
+
70
+
All rectangles this grid works with are axis-aligned.
51
71
72
+
You're free to remove them at any time by using one of the remove-methods `Remove(Point/Vector2/Rectangle/Rect)`.
73
+
74
+
The method `Get(Point/Vector2/Rectangle/Rect)` returns an array of your items with all of them that the grid has encountered in the area you've specified when calling `Get`. If it doesn't find any it returns an empty array.
0 commit comments