2D game engine based on SDL2
This project aims to create a full 2D game engine for the SDL2 library.
The AssetManager
has a set of Locators and Loaders.
A locator is used to check if the requested asset exists. It will return a pointer to the asset location.
Example:
FileLocator
: check if the requested asset exists on-disk.ZipLocator
: check if the requested asset exists in a ZIP archive (todo).URLLocator
: check if the requested asset exists at a URL (todo).A loader is used to load the asset from the pointer returned by the locator.
Example:
ImageLoader
: using SDL2_image, loads an image.FontLoader
: using SDL2_ttf, loads a TTF font.JSONLoader
: loads a JSON file.AudioLoader
: loads a sound file (todo).Asset requests are made using an AssetDescriptor
. The descriptor holds all
informations about the asset (ie: name, font size, bit rate, ...).
The manager holds a cache of asset and descriptors. If a descriptor has already been loaded, the same asset is returned.
Map keys, mouse buttons and controller buttons to a named action, and then check in your code if the action is triggered or not.
The SceneManager
keeps track of all your game's scenes. It handles the scene
loading and unloading, and notify the scene's graph of inputs, updates, and draw
requests.
The scene graph is a tree of node, each one implementing a specific task:
Example of nodes:
PositionNode
: handle relative and absolute positionSpriteNode
: loads an asset and draw at a positionAnimatedSpriteNode
: loads multiple asset, change the frame on update, draw at a positionAreaNode
: notified when overlaps with another AreaNode
In order to create a Scene
, you just need to inherit from it, and creates your
nodes in the load()
method, and delete them in the unload()
method.
Specific nodes in the scene graph are used for collision detection:
BodyNode
: is notified for a collisionBoundingBoxNode
: as a child of the BodyNode
, defines a bounding box used to filter out nodes in the collision detectionCollisionShapeNode
: as a child of the BodyNode
, defines the shape used to check for accurate collision2-step collision detection:
BodyNode
, check if at least one child BoundingBoxNode
is overlappingBodyNode
with at least one BoundingBoxNode
overlapping, construct the ContactManifold
for each child CollisionShapeNode
Finally, the BodyNode
is notified of a collision by receiving the resulting ContactManifold
.
If you want to initialize libraries (ie: Stemworks API) and unload them at shutdown,
just inherit from Initializer
and add it to the engine instance.
At the moment, the following initializers are enabled by default:
The engine instance is initialized with a configuration object, used to customize how the engine will works. Feel free to use it to customize:
NB: The configuration object does not handle loading from a file and saves.
You need cmake
and a compiler supporting the C++14 standard.
$ mkdir __build__
$ cd __build__
$ cmake ..
$ make
This project is released under the MIT License.