Conceptual overview
Kheljs provides a modular architecture where each game level is created as a set of loosely coupled components. During application startup, an initial Game Level object will be created by the application. The Game Level object, in turn, creates and initializes a set of manager objects, each manager object handling some aspects of the game. These manager objects initialize independent of each other and may initialize synchronously or ansynchronously. The manager objects implements the following interfaces:
- ICameraManager - Manages cameras for the game
- ICollectibleManager - places collectible on the game level.
- IGuiManager - Displays UI for the game
- IInventoryManager - Manages game level and player's inventory
- ILightManager - Creates the lights for the game
- IPlayerManager - Creates the player objects and is responsible for movements of the player character.
- ISkyboxManager - Creates skybox for the game
- ITerrainManager - Creates the terrain and places objects on the terrain.
These interfaces, by themselves, are pretty simple but provides a powerful framework for creating games using BabylonJS library. The kheljs framework provides a number of classes around each manager class so that the manager component can fulfill its responsibility.
In future, additional manager components may be added but the fundamental way a game level provides its functionality using these components will remain the same.
Player Manager
The Player Manager class is responsible for the following aspects of the game:
- loading the assets related to the player such as meshes, skeletons and animations.
- Move player in the scene based on user inputs from keyboard or controller.
- Play suitable animations on the player when the player is idle or is involved in some activity.
The Player Manager generated by kheljs loads a simple character that comes with the framework, listens to keyboard events and moves the player around based on arrow keys. It also plays animations on the character while the character is idle or moving.
The default behavior can be changed easily to move the player by using an XBox or a PlayStation controller and play any other animation supported by the assets loaded for the player. The generated code provides a basic starting point for the player component and should be extended to take advantage of all animations and rigging supported by the 3D model loaded by the Player Manager.
Terrain Manager
The Terrain Manager class is responsible for not only creating the terrain but also for placing objects on the terrain. The general role of the terrain manager is as follows:
- Create ground or terrain for the level.
- Place objects on the terrain such as buildings, houses, trees etc.
- Divide the terrain into different regions and set ambient characteristics of a region.
- place barriers to restrict movement of the player character or NPCs.
The default Terrain Manager generated by kheljs creates a planer ground with a simple ground material, places a few ground objects to demonstrate some capabilities in the Terrain Manager. To create a realistic terrain, you should create the terrain from a height map or load a model created from any 3D modeling software such as Blender or Maya. See the Terrain Manager section under the programming guide for details.
Inventory Manager
Inventory is the set of items in the game like gems, medicines, food, weapons which can be carried by the player or can be placed in a level in the game. The Inventory Manager is responsible for creating and managing the inventory items for the player as well as for the level of the game.
The default inventory manager generated by khlejs places a few inventory items on the ground and let the player collect those items. It demonstrates how inventory items for the player and the game level can be created easily in a declarative way. The programming guide section for Inventory Manager shows how to configure the initial inventory for the player and for the game level.
Gui Manager
The GUI manager is responsible for displaying the user interface for the game. The default GUI manager displays a tab based intreface where the default inventory panel for the player is displayed.
Skybox Manager
The SkyboxManager component is responsible for creating the skybox for your game. The default SkyboxManager generated at a given level does not do anything. It just acts as a placeholder where you can add code for your skybox.
Camera Manager
The camera manager class is where you create cameras for your game and allow users to switch between cameras in response to user actions. The default CameraManager component creates a scene camera to provide a bird eye view of the scene. It also allows switching between player's camera and the scene camera. For detail, see the programming guide section for CameraManager component.
Light Manager
The LIghtManager component is used to create and manage the lights of the scene. The default LightManager generated by khlejs creates a hemispheric light and a directional light.