GamePlay Objects

In khlejs, interactions between different actors in the game are modelled as GamePlay objects which are implementations of the GamePlay interface. A GamePlay object encapsulates the interaction between two or more actors in the game. Typical actors in a game are player, NPCs, terrain, terrain objects, cameras, lights, inventory items and so on but for the purpose of GamePlay objects any data structure in the game can be an actor.

The concept of GamePlay object is very simple. It contains a set of actors and two methods:

  • isTrggered()
  • performAction()

Once the GamePlay object is registered with the kheljs runtime, the isTriggered() Method is called for each frame of the scene and if the method returns true then the performAction() method is called. The isTriggered() method should check the actors to see if the a condition for an interaction is satisfied and should return true or false accordingly. Any time the data structures (i.e. actors) in the GamePlay object changes to fulfill the condition of an interaction, performAction() method will be called i.e. the interaction will take place. Later, on this page, we will see how to model some interactions in the game using GamePlay objects.

What can be designed using GamePlay objects?

Any dynamic aspect of your game that involves single or multiple actors can be modeled as GamePlay objects. Some examples of interactions that can be modeled using GamePlay objects:

  • Player picking up an inventory item by walking over the item.
  • Automatically reload a weapon when the cartridge is low.
  • NCP reacting to a player when they are closer than a certain distance
  • Perform an action based on user command.
  • Highlight a checkpoint when the user goes close to it.
  • Play some music when the user completes a mission.