...

Source file src/code.rocketnine.space/tslocum/gohan/doc.go

Documentation: code.rocketnine.space/tslocum/gohan

     1  /*
     2  Package gohan provides an Entity Component System framework for Ebitengine.
     3  
     4  An example game is available at /examples/twinstick, which may be built by
     5  executing the following command (in /examples/twinstick):
     6  
     7    go build -tags example .
     8  
     9  Entity
    10  
    11  A general-purpose object, which consists of a unique ID, starting with 1.
    12  
    13  Component
    14  
    15  The raw data for one aspect of an object, and how it interacts with the world.
    16  Each component is assigned a unique ID, starting with 1.
    17  
    18    type ExampleComponent struct {
    19      X, Y float64
    20    }
    21  
    22  System
    23  
    24  Each system runs continuously, performing actions on every entity that matches
    25  each systems' set of required components. When no required components are
    26  specified, the system will match all active entities.
    27  
    28    type ExampleSystem struct {
    29      Position *component.PositionComponent // Required component.
    30      Velocity *component.VelocityComponent // Required component.
    31  
    32      Sprite *component.SpriteComponent `gohan:"?"` // Optional component.
    33  
    34      Enabled bool `gohan:"-"` // Not a component.
    35    }
    36  
    37  Component Design Guidelines
    38  
    39  Components are located in a separate package, typically named component. They
    40  should be public (start with an uppercase letter) and may be of any type.
    41  Using only struct types (with zero or more public fields) and accessing the
    42  structs via pointer is recommended. Components should not have any logic (i.e. game code)
    43  within them, as all logic should be implemented within a system.
    44  
    45  System Design Guidelines
    46  
    47  Systems are located in a separate package, typically named system. They should
    48  be public (start with an uppercase letter) and offer an instantiation function
    49  named as follows: NewSystemNameHere(). Data should be stored within components
    50  attached to one or more entities, rather than within the systems themselves.
    51  References to components must not be maintained outside each Update and Draw
    52  call, or else the application will encounter race conditions.
    53  
    54  Environment Variables
    55  
    56  Running an application with the environment variable GOHAN_DEBUG set to 1
    57  will enable printing verbose system update and draw information.
    58  */
    59  package gohan
    60  

View as plain text