Skip to content

Commit b8d2830

Browse files
committed
Adds readme
1 parent a6cff80 commit b8d2830

File tree

6 files changed

+152
-136
lines changed

6 files changed

+152
-136
lines changed

README.md

Lines changed: 12 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
[![NuGet](https://img.shields.io/nuget/v/CollisionGrid.svg?maxAge=2592000)](https://www.nuget.org/packages/CollisionGrid/)
2-
[![license](https://img.shields.io/github/license/unterrainerinformatik/collisiongrid.svg?maxAge=2592000)](http://unlicense.org) [![Twitter Follow](https://img.shields.io/twitter/follow/throbax.svg?style=social&label=Follow&maxAge=2592000)](https://twitter.com/throbax)
1+
[![NuGet](https://img.shields.io/nuget/v/BloomEffectRenderer.svg?maxAge=2592000)](https://www.nuget.org/packages/BloomEffectRenderer/)
2+
[![license](https://img.shields.io/github/license/unterrainerinformatik/BloomEffectRenderer.svg?maxAge=2592000)](http://unlicense.org) [![Twitter Follow](https://img.shields.io/twitter/follow/throbax.svg?style=social&label=Follow&maxAge=2592000)](https://twitter.com/throbax)
33

4-
# General
4+
# General
55

66
This section contains various useful projects that should help your development-process.
77

@@ -11,123 +11,25 @@ In order to get help with basic GIT commands you may try [the GIT cheat-sheet][c
1111
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.
1212
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]
1313

14-
# ![Icon](https://github.com/UnterrainerInformatik/collisiongrid/raw/master/icon.png)CollisionGrid
14+
# ![Icon](https://github.com/UnterrainerInformatik/BloomEffectRenderer/raw/master/icon.png) BloomEffectRenderer
1515

16-
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)
2219

2320
> **If you like this repo, please don't forget to star it.**
2421
> **Thank you.**
2522
2623

2724

28-
## What It Really Does...
25+
## Getting Started
2926

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.
3327

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:
68-
![Rectangle Test][testrectangle]
69-
70-
#### Example
71-
72-
Set up the collision-grid:
73-
```csharp
74-
public CollisionGrid<Sprite> Grid;
75-
76-
public DrawableGrid(Game game, SpriteBatch spriteBatch,
77-
float width, float height, int numberOfCellsX,
78-
int numberOfCellsY) : base(game)
79-
{
80-
Grid = new CollisionGrid<Sprite>(width, height, numberOfCellsX, numberOfCellsY);
81-
}
82-
```
83-
Place your sprites on to the grid in your update-method:
84-
```csharp
85-
public override void Update(GameTime gameTime)
86-
{
87-
base.Update(gameTime);
88-
foreach (Sprite s in sprites)
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-
protected override void UnloadContent()
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.
28+
29+
#### Example
30+
12631

12732

12833
[homepage]: http://www.unterrainer.info
12934
[coding]: http://www.unterrainer.info/Home/Coding
130-
[github]: https://github.com/UnterrainerInformatik/collisiongrid
131-
[quadtree]: https://github.com/ChevyRay/QuadTree
132-
[testrectangle]: https://github.com/UnterrainerInformatik/collisiongrid/blob/master/testrectangle.gif
133-
[testposition]: https://github.com/UnterrainerInformatik/collisiongrid/blob/master/testposition.gif
35+
[github]: https://github.com/UnterrainerInformatik/BloomEffectRenderer
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<XnaContent xmlns:Graphics="Microsoft.Xna.Framework.Content.Pipeline.Graphics">
3+
<Asset Type="Graphics:FontDescription">
4+
<FontName>Anonymous Pro</FontName>
5+
<Size>8</Size>
6+
<Spacing>0</Spacing>
7+
<UseKerning>true</UseKerning>
8+
<Style>Regular</Style>
9+
<DefaultCharacter>*</DefaultCharacter>
10+
<CharacterRegions>
11+
<CharacterRegion>
12+
<Start>&#32;</Start>
13+
<End>&#255;</End>
14+
</CharacterRegion>
15+
</CharacterRegions>
16+
</Asset>
17+
</XnaContent>

TestGame/Content/Content.mgcb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,22 @@
1313

1414
#---------------------------------- Content ---------------------------------#
1515

16+
#begin AnonymousPro8.spritefont
17+
/importer:FontDescriptionImporter
18+
/processor:FontDescriptionProcessor
19+
/processorParam:PremultiplyAlpha=True
20+
/processorParam:TextureFormat=Compressed
21+
/build:AnonymousPro8.spritefont
22+
23+
#begin image.jpg
24+
/importer:TextureImporter
25+
/processor:TextureProcessor
26+
/processorParam:ColorKeyColor=255,0,255,255
27+
/processorParam:ColorKeyEnabled=True
28+
/processorParam:GenerateMipmaps=False
29+
/processorParam:PremultiplyAlpha=True
30+
/processorParam:ResizeToPowerOfTwo=False
31+
/processorParam:MakeSquare=False
32+
/processorParam:TextureFormat=Color
33+
/build:image.jpg
34+

TestGame/Content/image.jpg

226 KB
Loading

TestGame/Game1.cs

Lines changed: 104 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,111 @@
1-
using Microsoft.Xna.Framework;
1+
// ***************************************************************************
2+
// This is free and unencumbered software released into the public domain.
3+
//
4+
// Anyone is free to copy, modify, publish, use, compile, sell, or
5+
// distribute this software, either in source code form or as a compiled
6+
// binary, for any purpose, commercial or non-commercial, and by any
7+
// means.
8+
//
9+
// In jurisdictions that recognize copyright laws, the author or authors
10+
// of this software dedicate any and all copyright interest in the
11+
// software to the public domain. We make this dedication for the benefit
12+
// of the public at large and to the detriment of our heirs and
13+
// successors. We intend this dedication to be an overt act of
14+
// relinquishment in perpetuity of all present and future rights to this
15+
// software under copyright law.
16+
//
17+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18+
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20+
// IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21+
// OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22+
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23+
// OTHER DEALINGS IN THE SOFTWARE.
24+
//
25+
// For more information, please refer to <http://unlicense.org>
26+
// ***************************************************************************
27+
28+
using System;
29+
using BloomEffectRenderer;
30+
using Microsoft.Xna.Framework;
231
using Microsoft.Xna.Framework.Graphics;
332
using Microsoft.Xna.Framework.Input;
433

534
namespace TestGame
635
{
736
/// <summary>
8-
/// This is the main type for your game.
37+
/// This is the main type for your game.
938
/// </summary>
1039
public class Game1 : Game
1140
{
12-
GraphicsDeviceManager graphics;
13-
SpriteBatch spriteBatch;
14-
41+
private const string IMAGE_COPYRIGHT =
42+
"Image by Michael Beckwith\nAuthor: https://www.flickr.com/people/78207463@N04 \n" +
43+
"Source: https://www.flickr.com/photos/78207463@N04/8226826999/ \n'Inside St Kentigerns RC Church.'\n" +
44+
"Located in Blackpool, Lancashire, England, UK.";
45+
46+
private readonly GraphicsDeviceManager graphics;
47+
private SpriteBatch spriteBatch;
48+
49+
private SpriteFont Font { get; set; }
50+
private Texture2D Image { get; set; }
51+
private Point Resolution { get; } = new Point(1280, 720);
52+
private Renderer Renderer { get; } = new Renderer();
53+
private bool IsBoom { get; set; } = true;
54+
1555
public Game1()
1656
{
1757
graphics = new GraphicsDeviceManager(this);
58+
graphics.PreferMultiSampling = true;
59+
graphics.PreferredBackBufferWidth = Resolution.X;
60+
graphics.PreferredBackBufferHeight = Resolution.Y;
61+
graphics.IsFullScreen = false;
62+
graphics.PreparingDeviceSettings += PrepareDeviceSettings;
63+
graphics.SynchronizeWithVerticalRetrace = true;
64+
1865
Content.RootDirectory = "Content";
1966
}
2067

21-
/// <summary>
22-
/// Allows the game to perform any initialization it needs to before starting to run.
23-
/// This is where it can query for any required services and load any non-graphic
24-
/// related content. Calling base.Initialize will enumerate through any components
25-
/// and initialize them as well.
26-
/// </summary>
27-
protected override void Initialize()
68+
void PrepareDeviceSettings(object sender, PreparingDeviceSettingsEventArgs e)
2869
{
29-
// TODO: Add your initialization logic here
70+
e.GraphicsDeviceInformation.GraphicsProfile = GraphicsProfile.HiDef;
71+
}
3072

73+
protected override void Initialize()
74+
{
3175
base.Initialize();
76+
Renderer.Initialize(graphics.GraphicsDevice, Resolution);
3277
}
3378

3479
/// <summary>
35-
/// LoadContent will be called once per game and is the place to load
36-
/// all of your content.
80+
/// LoadContent will be called once per game and is the place to load
81+
/// all of your content.
3782
/// </summary>
3883
protected override void LoadContent()
3984
{
4085
// Create a new SpriteBatch, which can be used to draw textures.
4186
spriteBatch = new SpriteBatch(GraphicsDevice);
42-
43-
// TODO: use this.Content to load your game content here
87+
Font = Content.Load<SpriteFont>("AnonymousPro8");
88+
Image = Content.Load<Texture2D>("image");
4489
}
4590

4691
/// <summary>
47-
/// UnloadContent will be called once per game and is the place to unload
48-
/// game-specific content.
92+
/// UnloadContent will be called once per game and is the place to unload
93+
/// game-specific content.
4994
/// </summary>
5095
protected override void UnloadContent()
5196
{
52-
// TODO: Unload any non ContentManager content here
97+
Renderer.UnloadContent();
5398
}
5499

55100
/// <summary>
56-
/// Allows the game to run logic such as updating the world,
57-
/// checking for collisions, gathering input, and playing audio.
101+
/// Allows the game to run logic such as updating the world,
102+
/// checking for collisions, gathering input, and playing audio.
58103
/// </summary>
59104
/// <param name="gameTime">Provides a snapshot of timing values.</param>
60105
protected override void Update(GameTime gameTime)
61106
{
62-
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
107+
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed ||
108+
Keyboard.GetState().IsKeyDown(Keys.Escape))
63109
Exit();
64110

65111
// TODO: Add your update logic here
@@ -68,16 +114,48 @@ protected override void Update(GameTime gameTime)
68114
}
69115

70116
/// <summary>
71-
/// This is called when the game should draw itself.
117+
/// This is called when the game should draw itself.
72118
/// </summary>
73119
/// <param name="gameTime">Provides a snapshot of timing values.</param>
74120
protected override void Draw(GameTime gameTime)
75121
{
76122
GraphicsDevice.Clear(Color.CornflowerBlue);
77123

78-
// TODO: Add your drawing code here
124+
DrawImage();
125+
DrawText(gameTime);
79126

80127
base.Draw(gameTime);
81128
}
129+
130+
private void DrawImage()
131+
{
132+
if (IsBoom)
133+
{
134+
Renderer.Render(graphics.GraphicsDevice, spriteBatch, "image", Image, null, Settings.PRESET_SETTINGS[1]);
135+
}
136+
else
137+
{
138+
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);
139+
spriteBatch.Draw(Image, new Rectangle(0, 0, Resolution.X, Resolution.Y), Color.White);
140+
spriteBatch.End();
141+
}
142+
}
143+
144+
private void DrawText(GameTime gameTime)
145+
{
146+
var t = .5f + .5f * (float)Math.Sin(5 * gameTime.TotalGameTime.TotalSeconds);
147+
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);
148+
Color c = Color.Lerp(Color.White, Color.Gray, t);
149+
150+
spriteBatch.DrawString(Font, "More to come... Press <ESC> to exit!", new Vector2(10, 10), c);
151+
152+
Vector2 s = Font.MeasureString(IMAGE_COPYRIGHT);
153+
spriteBatch.DrawString(Font,
154+
IMAGE_COPYRIGHT,
155+
new Vector2(30f, Resolution.Y - s.Y - 30f),
156+
c);
157+
158+
spriteBatch.End();
159+
}
82160
}
83-
}
161+
}

icon.png

-1.47 KB
Loading

0 commit comments

Comments
 (0)