Interfaces - Lojemiru/Loj-Hadron-Collider GitHub Wiki

Interfaces are the cornerstone of the Loj Hadron Collider. They are used for checking and triggering collisions, and provide a means to ensure consistent function naming to give objects within an Interface a robust API for interaction in collision events.

Internally, Interfaces are little more than tags with some method names attached. In execution, however, Interfaces allow for the definition of common collision-event APIs across numerous different objects, and even allow for the inheritance of multiple Interfaces - say, for example, a window object that both inherits from IBreakable and ISolid, allowing projectiles to shatter it but blocking the player until destroyed.


lhc_assign_interface

Assigns the input object[s] to the specified Interface.

Syntax:

lhc_assign_interface(interface, object, [...]);

Returns: N/A

Argument Type Description
interface String The interface to assign the input objects to.
object Object An object to assign to the interface.
[...] Object[s] More objects to assign to the interface.

Example:

lhc_assign_interface("ISolid", obj_solid, obj_bounce, obj_platform);

lhc_create_interface

Creates an interface with the [optional] specified functions. If functions are defined for an Interface, all objects assigned to it should run lhc_inherit_interface in their Create event to locally register the assigned function names.

The purpose of function name registration is much like with Interfaces in a language such as C#; we wish to have a common behavior that is implemented differently in different classes (objects in GML-speak). For instance, an Interface called IBreakable would be registered with the function break, which could then be called by any object colliding with IBreakable by using lhc_colliding().break(). Different objects assigned to IBreakable would all implement breaking behavior in their own way (glass breaks differently from wood, for example), so objects that are supposed to break IBreakables only need to make a single call during collision.

Syntax:

lhc_create_interface(name, [functionName], [...]);

Returns: N/A

Argument Type Description
name String The name of the Interface.
[functionName] String A function name to assign to members of the Interface.
[...] String[s] More function names to assign to members of the Interface.

Example:

lhc_create_interface("IProjectile", "do_hit", "deflect", "reflect");