### Navigation

- index
- modules |
- next |
- previous |
- Grease v0.2 documentation »

# `grease.entity` – Entity Classes

Grease entities are useful as actionable, interactive game elements that are often visible to the player.

You might use entities to represent:

- Characters
- Bullets
- Particles
- Pick-ups
- Space Ships
- Weapons
- Trees
- Planets
- Explosions

See an example entity class in the tutorial.

class `grease.entity.``Entity`

  Base class for grease entities.

  Entity objects themselves are merely identifiers within a `grease.world.World`. They also provide a facade for convenient entity-wise access of component data. However, they do not contain any data themselves other than an entity id.

  Entities must be instantiated in the context of a world. To instantiate an entity, you must pass the world as the first argument to the constructor. Subclasses that implement the `__init__()` method, must accept the world as their first argument (after `self`). Other constructor arguments can be specified arbitarily by the subclass.

  `__getattr__`(name)

    Return an `EntityComponentAccessor` for this entity for the component named.

    Example:

        my_entity.movement

  `__setattr__`(name, value)

    Set the entity data in the named component for this entity. This sets the values of the component fields to the values of the matching attributes of the value provided. This value must have attributes for each of the component fields.

    This allows you to easily copy component data from one entity to another.

    Example:

        my_entity.position = other_entity.position

  `__delattr__`(name)

    Remove this entity and its data from the component.

    Example:

        del my_entity.renderable

  `delete`()
    Delete the entity from its world. This removes all of its component data. If then entity has already been deleted, this call does nothing.
  `exists`
    True if the entity still exists in the world

class `grease.entity.``ComponentEntitySet`(component, entities=())
  Set of entities in a component, can be queried by component fields

class `grease.entity.``EntityComponentAccessor`(component, entity)

  A facade for accessing specific component data for a single entity. The implementation is lazy and does not actually access the component data until needed. If an attribute is set for a component that the entity is not yet a member of, it is automatically added to the component first.

  Parameters: | component – The `grease.Component` being accessed entity – The `Entity` being accessed

  `__getattr__`(name)
    Return the data for the specified field of the entity’s component
  `__setattr__`(name, value)
    Set the data for the specified field of the entity’s component
  `__nonzero__`()
    The accessor is True if the entity is in the component, False if not, for convenient membership tests

### Navigation

- index
- modules |
- next |
- previous |
- Grease v0.2 documentation »