https://github.com/shendriks/pathfinding-2d
A collection of code examples from my blog
https://github.com/shendriks/pathfinding-2d
a-star a-star-path-finding blazor-webassembly blazorgl csharp game-development gamedev kni monogame pathfinding
Last synced: about 1 month ago
JSON representation
A collection of code examples from my blog
- Host: GitHub
- URL: https://github.com/shendriks/pathfinding-2d
- Owner: shendriks
- License: mit
- Created: 2024-07-22T18:58:31.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2026-04-02T05:33:27.000Z (3 months ago)
- Last Synced: 2026-04-02T18:56:36.795Z (3 months ago)
- Topics: a-star, a-star-path-finding, blazor-webassembly, blazorgl, csharp, game-development, gamedev, kni, monogame, pathfinding
- Language: C#
- Homepage: https://shendriks.dev
- Size: 316 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# A* Pathfinding in 2D Games
[](https://github.com/shendriks/pathfinding-2d/actions/workflows/dotnet.yml)
[](https://github.com/shendriks/pathfinding-2d/actions/workflows/super-linter.yml)
This is a collection of code examples from the blog series https://shendriks.dev/series/a-pathfinding-in-2d-games/
In here you'll find the following projects:
| Blog Post | Projects | Branch |
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------|------------------|
| Part 1: [A* Pathfinding in 2D Games: The Basics for a simple Top-down Scenario](https://shendriks.dev/posts/2024-07-13-a-star-pathfinding-in-2d-games-the-basics-for-top-down-scenarios/) |
- `TopDownView.Console`
- `TopDownView.Console.Tests`
| Part 2: [A* Pathfinding in 2D Games: A simple Top-down Scenario implemented with MonoGame/KNI](https://shendriks.dev/posts/2024-08-24-a-star-pathfinding-top-down-blazorgl/) |
- `TopDownView.BlazorGL`
- `TopDownView.BlazorGL.Tests`
| Part 3: [A* Pathfinding in 2D Games: Side-View](https://shendriks.dev/posts/2024-09-04-a-star-pathfinding-side-view/) |
- `SideView.BlazorGL`
- `SideView.BlazorGL.Tests`
| Part 4: [A* Pathfinding in 2D Games: Addendum about Cyclic Dependencies](https://shendriks.dev/posts/2024-12-01-a-star-pathfinding-supplemental/) |
- `SideView.BlazorGL`
- `SideView.BlazorGL.Tests`
## A few notes about the implementation
### Code Duplication
If you compare the applications, you'll notice that all projects have
similar classes like `Cell`, `Grid` or `AStarPathfinder` with quite a bit of duplicated code.
Duplicated code is generally considered bad practice (see [the DRY principle](https://en.wikipedia.org/wiki/Don%27t_repeat_yourself)).
However, it seems acceptable in this case because
1. These are separate projects, each with its own set of requirements (e.g. a console application
is meant to be called once, while a MonoGame application is meant to be interactive and game-like, e.g. you can step through
the algorithm).
2. Trying to avoid duplicated code by extracting superclasses into a separate project makes the relatively simple
examples unnecessarily complicated.
3. The code is unlikely to change.
### About not unsubscribing from Events
In general, it's good practice to unsubscribe from events when you no longer need them.
In this example, however, we'll skip the step of unsubscribing for simplicity's sake, because it's just one level, if you will, and the
"game" is not progressing in the sense that a new level or area needs to be loaded while the current one is being unloaded, or
new game objects are being created or existing ones are being destroyed. The only time we would need to unsubscribe is when the
whole game ends, in which case everything will end up in data nirvana anyway.
### Testing
You'll find a few rudimentary tests in the test projects. The coverage is probably not super high.