Uploaded April 2019 | Updated September 2026, 2 hours ago
This engine allows the user to input thousands of objects, and in using very simple code, create what appears to be a swarm of bees. This video demonstrates 1000 "creatures", running at a fast smooth frame rate.
This is my first attempt at "emergent behaviour" - i.e. AI that is coded with just a small number of commands, but that in a group appear to be controlled by some larger intelligence. I have "cheated" a little bit by adding in a couple of global toggles (using sin waves) that alter how far away other creatures need to be over time. This creates a nice "heartbeat" type feel to the swarm.
I'd imagine that this code could also be used to simulate other things like particles for a magic fireball in a game, or similar. I might just have to use this in one of my next games!
I've also included a "beacon" effect, which attracts the entire swarm - although I do want to work on that a bit more so that the beacons slowly attract the swarm if that effect is being aimed for.
It relies on only a few functions and objects to do all the work, so hopefully the code is quite easy to understand and follow.
The codebase can be found here: github.com/s0lly/Swarm-AI
Please let me know how I could improve this!
Acknowledgements:
This was made using the Chili Framework: http://wiki.planetchili.net/index.php... - thanks Chili!
The ideas of using simple states to create emergent behaviour came about while reading Mat Buckland's book Programming Game AI by Example. This code uses ideas similar to the Seek and Evade AI states.
This engine allows the user to input thousands of objects, and in using very simple code, create what appears to be a swarm of bees. This video demonstrates 1000 "creatures", running at a fast smooth frame rate.
This is my first attempt at "emergent behaviour" - i.e. AI that is coded with just a small number of commands, but that in a group appear to be controlled by some larger intelligence. I have "cheated" a little bit by adding in a couple of global toggles (using sin waves) that alter how far away other creatures need to be over time. This creates a nice "heartbeat" type feel to the swarm.
I'd imagine that this code could also be used to simulate other things like particles for a magic fireball in a game, or similar. I might just have to use this in one of my next games!
I've also included a "beacon" effect, which attracts the entire swarm - although I do want to work on that a bit more so that the beacons slowly attract the swarm if that effect is being aimed for.
It relies on only a few functions and objects to do all the work, so hopefully the code is quite easy to understand and follow.
The codebase can be found here: github.com/s0lly/Swarm-AI
Please let me know how I could improve this!
Acknowledgements:
This was made using the Chili Framework: http://wiki.planetchili.net/index.php... - thanks Chili!
The ideas of using simple states to create emergent behaviour came about while reading Mat Buckland's book Programming Game AI by Example. This code uses ideas similar to the Seek and Evade AI states.


![2D Game Engine in C++: [2] Adding a Camera / Moving Camera and Sprites
This video shows object movement, corrected relative to rotation, alongside camera movement.
Camera rotation and zooming is still lacking - this will be the next task to complete.
I already see a top down racing game from this! Itll need some collision detection sooner rather than later, Id imagine.
I will release all code on GitHub once Ive finalised the engine - and have nice looking code to boot!
Using the Chili Framework: http://wiki.planetchili.net/index.php... - thanks Chili! 2D Game Engine in C++: [2] Adding a Camera / Moving Camera and Sprites](https://i.ytimg.com/vi/I5Xv2AzYeXY/mqdefault.jpg)





![2D Game Engine in C++: [6] Perspective
This video expands the planes concept, allowing for corrected translation and scaling of sprites depending on which plane they exist on, creating a pretty cool sense of depth.
An example of this effect would be for clouds flying on top of the game world for a top-down game. As they would be closer to the camera, they would naturally move faster and be of different scales depending on how high up / close to the camera they are.
The Draw routine allows for all of an objects information in determining where it should be drawn, so the graphics calls are relatively simple to use in coding. Hopefully this will allow me to easily add in whatever graphics I need for my next game ideas, which will allow me to spend a lot more time on other game development concepts, e.g. AI.
I will release all code on GitHub once Ive finalised the engine - and have nice looking code to boot!
Using the Chili Framework: http://wiki.planetchili.net/index.php... - thanks Chili! 2D Game Engine in C++: [6] Perspective](https://i.ytimg.com/vi/IvUYPMLZ76Q/mqdefault.jpg)

