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
This section contains various useful projects that should help your development-process.
7
7
@@ -11,123 +11,25 @@ In order to get help with basic GIT commands you may try [the GIT cheat-sheet][c
11
11
This repository located on our [homepage][homepage] is private since this is the master- and release-branch. You may clone it, but it will be read-only.
12
12
If you want to contribute to our repository (push, open pull requests), please use the copy on github located here: [the public github repository][github]
This class is a PCL library for MonoGame that implements a collision-grid.
17
-
When doing game development you've probably come across a point when you'd liked to do some collision-checks and that's usually the time when you've realize that just checking all sprites against each other doesn't cut it.
18
-
The problem with that brute-force-approach is, that the number of checks grow very fast (N² for N sprites) when the number of your sprites increase.
19
-
20
-
So you somehow have to narrow down your collision-candidates.
21
-
This piece of software does that for you. It does not do the collision checks themself. It just tells you if a sprite may be near enough to a second one to maybe collide with it, which allows you to do a collision test for those two, or three, or five sprites instead of the whole bunch.
16
+
This class is a PCL library for MonoGame that implements a bloom effect.
17
+
If you'd like your game to truly shine, you can use this little beauty without much hassle.
18
+
The problem with that brute-force-approach is, that the number of checks grow very fast (N² for N sprites)
22
19
23
20
> **If you like this repo, please don't forget to star it.**
24
21
> **Thank you.**
25
22
26
23
27
24
28
-
## What It Really Does...
25
+
## Getting Started
29
26
30
-
...is a simple trade-off.
31
-
You may query it about the sprites around your coordinate or rectangle, but your sprites have to register with it and update their position/AABB on every update.
32
-
But all in all this is a lot faster than a simple brute-force check.
33
27
34
-
## Getting Started
35
-
The first thing is: You have to set-up a grid. Usually you'd take your game-coordinate-system's bounds.
36
-
Then you have to tell the grid how many cells it has by setting the number of cells on the X and Y axis.
37
-
38
-
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.
39
-
40
-
### Parameters
41
-
The first parameter is your item. The grid is generic and there are no constraints for that.
42
-
The second parameter is always one of the following:
43
-
#### Point
44
-
This is an int-point.
45
-
By specifying this you tell the grid you mean the cell at exactly this position.
46
-
#### Vector2
47
-
This is a float-vector.
48
-
By specifying this you tell the grid that you mean the cell that contains these game-coordinates.
49
-
#### Rectangle
50
-
This is a basic int-rectangle.
51
-
It is not rotated and therefore axis-aligned. So it's an Axis-Aligned-Bounding-Box or AABB.
52
-
By specifying this you give the grid a rectangle in the cell-coordinate-system
53
-
(0-numberOfCellsX, 0-numberOfCellsY).
54
-
#### Rect
55
-
This is a special parameter in our utility-package. It's essentially a Rectangle, but with all float parameters.
56
-
By specifying this you give the grid a rectangle in the game-coordinate-system.
57
-
58
-
All rectangles this grid works with are axis-aligned.
59
-
60
-
You're free to remove them at any time by using one of the remove-methods `Remove(Point/Vector2/Rectangle/Rect)`.
61
-
62
-
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.
63
-
64
-
If you add your sprites by their position, then this is what the grid will basically do:
65
-
![Position Test][testposition]
66
-
67
-
If you add your sprites by their AABBs, then this is what the grid will basically do:
Place your sprites on to the grid in your update-method:
84
-
```csharp
85
-
publicoverridevoidUpdate(GameTimegameTime)
86
-
{
87
-
base.Update(gameTime);
88
-
foreach (Spritesinsprites)
89
-
{
90
-
Grid.Move(s, s.Position);
91
-
}
92
-
}
93
-
```
94
-
The move-method adds an item on the given position (cell that encapsulates the given game-coordinate).
95
-
This is the code to achieve the output in the first GIF.
96
-
97
-
To achieve the output in the second one, just change the Move-line to the following one:
98
-
```csharp
99
-
Grid.Move(s, s.getAABB());
100
-
```
101
-
Whereas of course your sprite has to return the axis-aligned-bounding-box as a Rect.
102
-
103
-
Please don't forget to clean up afterwards. There are a few data-structures the grid has to dispose of:
104
-
```csharp
105
-
protectedoverridevoidUnloadContent()
106
-
{
107
-
base.UnloadContent();
108
-
Grid.Dispose();
109
-
}
110
-
```
111
-
112
-
## So What's A QuadTree Then?
113
-
Maybe you've heard of such a data-structure that does essentially exactly the same things as this grid with one major difference:
114
-
115
-
The QuadTree divides the space all by itself, dynamically whenever you add new items.
116
-
It doesn't need a fixed uniform grid, but divides space unevenly and only when another partition is needed.
117
-
And that's good and bad at the same time.
118
-
The good thing is that it can cope with unevenly distributed items very well.
119
-
The bad thing is that it costs a lot more time (the updating of this data-structure); At least when compared to this grid here.
120
-
[Here's a very good implementation of a QuadTree on GitHub with an excellent explanation what it exactly does.][quadtree]
121
-
122
-
The good news about the QuadTree is that it's exactly what you're looking for if you are thinking...
123
-
> Oh! Nice thing this grid. But the space I have to check is REALLY BIG and my sprites are very unevenly distributed. Most of the time they are clustered with much space in between those clusters. So my cells become way too big to segment those clusters in a helpful way.
124
-
125
-
...when reading the explanation of the CollisionGrid.
0 commit comments