From e16fd28efdd8479bf2fbaf86607da28495ef32b8 Mon Sep 17 00:00:00 2001 From: Jonathan Crum Date: Sat, 16 Jan 2021 23:32:46 -0500 Subject: [PATCH] Update to README --- README.md | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index cc8deeb..f623cfd 100644 --- a/README.md +++ b/README.md @@ -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: @@ -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