Base tools are provided by the lionengine-game
module, giving a balanced game type development with
standard classes and architecture. It is also the main dependency of any other game specialized module.
In this section we will see how to use these main tools, and the way of we should use them.
The primary objects are designed to be reused as much as possible, being enough generic and useful.
ObjectGame
This is the main primary object type, providing the essentials tools for any sub object. It is designed to work with a
SetupGame
, needed by its constructor.
EffectGame
This is a sub
ObjectGame
, already specialized for effect creation, such as explode and smoke trailing effect (for example). It already contains a minimalist architecture, and support localization.
EntityGame
This is the main sub
ObjectGame
, specialized for more complex object, supporting gravity and collision. It also provides an easy distance calculation with another entity.
ProjectileGame
This is a sub
EntityGame
, specialized for projectile objects, designed to be thrown from aLauncherProjectileGame
. It provides an advanced architecture, allowing to custom its movement and target.
The FactoryObjectGame
The FactoryObjectGame
improves the FactoryGame
by creating typed objects using a generic way.
Also, the factory implementation is a bit more easer, as the configuration Media
is already provided by
the object type.
The only one argument should always be the same, using a SetupGame
single argument.
As we used a default implementation, all objects that can be created by the factory must be in "factory/"
folder. You can override createSetup(...)
by making it more complex in order to handle different
directories. If you don't want to use internal reflection, you can define your own create method by using a classic
switch and direct call the constructors.
It is now possible to create type instances, without doing any cast. Just ensure that you use the same type as the enumeration target type. Else you will have an error during the creation.
The HandlerObjectGame
allows to handle many objects, in order to update and render them. It is possible to
add and remove objects while using the handler. Changes will be performed at the end of the handler update.
You can now update a series of object, and render them. New objects can be added at any time.
An effect is a special object representation dedicated to improve the game rendering.
It is designed to be triggered on special event, such as entity death or object trails, and should not stay alive too much time.
It is highly recommended to understand first how is working the factory & the handler system !
You can now see the effect system in action. The goal of effect is to be triggered on special event, such as entity death, or projectile smoke...
The projectile system represents two main components:
The launcher is a special object (LauncherProjectileGame
) able to throw ProjectileGame
at a
defined rate, to a specified destination, which can also be a moving target.
The projectile is a special object (ProjectileGame
) that is thrown by a LauncherProjectileGame
,
with an autonomous update and render, and an adaptable trajectory.
This system also include a ready to use HandlerProjectileGame
, which will update and render all
active projectiles.
It is highly recommended to understand first how is working the factory & the handler system !
The way we implemented the entity is not important here, as we will just use it to show the projectile system in action.
The launcher need to know with which objects main type it should work (projectile, thrower and receiver).
This factory will allow a launcher to create instances of projectiles by using only their enum type. It is easy to define how projectiles are thrown by the launcher.
This will allow to create a launcher for an entity easily.
The most important part is the movement implementation, where you can define its trajectory after being launched, and what should happen when in case of hit.
You can now see the projectile system in action. It is possible to create a more complex system by allowing a weapon switching system, and creating more complex launcher with different projectiles.
A map represents a tile composition, where is tile is an image at a specified location, including extra information such as collision. Tiles image are stored in tilesheets.
The tile size determine the final map size, as the map knowns its tiles number and their location.
This is were are defined the different collision types (such as ground, slope, spike...)
The map is responsible in tile creation, and also able to fill the collision from an external file. A minimap can be generated at any time.
You can now see the projectile system in action. It is possible to create a more complex system by allowing a weapon switching system, and creating more complex launcher with different projectiles.
The WorldGame
is used as the main game container, rather than the Sequence
, as it supports
save and load features. The main goal of a world is to handle the game logic update and render order. With such a
class, the Sequence
is only used to load a WorldGame
, update and render it, nothing more.
To show all the main features, the world will just save a simple string, and load it. It will also display on screen the loaded string.
The only object handled by the scene is the world, calling save and load just to show how it is working.
As you can see, this is very basic. But once you will add more things in your world (such as Map
, Handler
...),
it will be easy to define a game saving and loading, as each complex object can be saved easily (MapTile
already have save and load functions). You can also implement different version of a world, and just select it from
the Sequence
, without changing any other thing.
Read next page: Platform games