Skip to content

Commit

Permalink
Update to README
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Crum committed Jan 17, 2021
1 parent 1adb81a commit e16fd28
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ from ecstremity import (Engine, Component)

ecs = Engine()

# Define some simple components to start with.
class Position(Component):
name: str = "POSITION"
def __init__(self, x: int, y: int) -> None:
Expand All @@ -37,35 +36,39 @@ class Velocity(Component):

class Frozen(Component):
name: str = "FROZEN"
```

All components must be registered with the engine. Component registration must use the class symbol (i.e. do not use the component name attribute).

# All components must be registered with the engine.
# Component registration must use the class symbol (i.e. do not use the component name attribute).
```python
ecs.register_component(Position)
ecs.register_component(Velocity)
ecs.register_component(Frozen)
```

Instruct the engine to make a new entity, then add components to it.
Once a component is registered, it can be accessed using the class symbol or the name attribute. The name attribute is not case-sensitive.

# Tell the engine to make an entity.
# You can call `entity.uid` to get the entity's unique ID.
```python
entity = ecs.create_entity()

# Add components to the entity.
# Once a component is registered, it can be accessed using the class symbol, but the name
# attribute can also be used. The component name is not case-sensitive.
entity.add(Position)
entity.add("Velocity")
entity.add("FROZEN")
```

The ecstremity library has no actual "system" class. Instead, instruct the engine to produce a query. For example, make a query that tracks all components that have both a `Position` and `Velocity` component, but not a `Frozen` component. A query can have any combination of the `all_of`, `any_of`, and `none_of` quantifiers.

# Create a query that tracks all components that have both a `Position` and `Velocity`
# component, but not a a `Frozen` component. A query can have any combination of the
# `all_of`, `any_of`, and `none_of` quantifiers.
```python
kinematics = ecs.create_query(
all_of = ['POSITION', 'VELOCITY'],
none_of = ['FROZEN']
)
```

Loop over the result set to update the position for all entities in the query. The query will always reutrn an up-to-date list containing entities that match.

```python
def loop(dt):
# Loop over the result set to update the position for all entities in the query.
# The query will always return an up-to-date list containing entities that match.
for entity in kinematics.result:
entity['POSITION'].x += entity['VELOCITY'].x * dt
entity['POSITION'].y += entity['VELOCITY'].y * dt
Expand Down

0 comments on commit e16fd28

Please sign in to comment.