How to use the esper.World function in esper

To help you get started, we’ve selected a few esper examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github benmoran56 / esper / tests / test_world.py View on Github external
def test_world_instantiation(world):
    assert type(world) == esper.World
    assert type(world._next_entity_id) == int
    assert type(world._entities) == dict
    assert type(world._components) == dict
    assert type(world._processors) == list
github benmoran56 / esper / examples / pygame_example.py View on Github external
def run():
    # Initialize Pygame stuff
    pygame.init()
    window = pygame.display.set_mode(RESOLUTION)
    pygame.display.set_caption("Esper Pygame example")
    clock = pygame.time.Clock()
    pygame.key.set_repeat(1, 1)

    # Initialize Esper world, and create a "player" Entity with a few Components.
    world = esper.World()
    player = world.create_entity()
    world.add_component(player, Velocity(x=0, y=0))
    world.add_component(player, Renderable(image=pygame.image.load("redsquare.png"), posx=100, posy=100))
    # Another motionless Entity:
    enemy = world.create_entity()
    world.add_component(enemy, Renderable(image=pygame.image.load("bluesquare.png"), posx=400, posy=250))

    # Create some Processor instances, and asign them to be processed.
    render_processor = RenderProcessor(window=window)
    movement_processor = MovementProcessor(minx=0, maxx=RESOLUTION[0], miny=0, maxy=RESOLUTION[1])
    world.add_processor(render_processor)
    world.add_processor(movement_processor)

    running = True
    while running:
        for event in pygame.event.get():
github benmoran56 / esper / examples / headless_example.py View on Github external
def main():
    # Create a World instance to hold everything:
    world = esper.World()

    # Instantiate a Processor (or more), and add them to the world:
    movement_processor = MovementProcessor()
    world.add_processor(movement_processor)

    # Create entities, and assign Component instances to them:
    player = world.create_entity()
    world.add_component(player, Velocity(x=0.9, y=1.2))
    world.add_component(player, Position(x=5, y=5))

    # A dummy main loop:
    try:
        while True:
            # Call world.process() to run all Processors.
            world.process()
            time.sleep(1)
github eyeCube / Softly-Roguelike / rogue.py View on Github external
    def create_world(cls):      cls.world = esper.World()
    @classmethod
github benmoran56 / esper / examples / lab.py View on Github external
import sys
import time
import esper

world = esper.World()


class Velocity(esper.Component):
    def __init__(self, x=0, y=0):
        self.x = x
        self.y = y


class Position(esper.Component):
    def __init__(self, x=0, y=0):
        self.x = x
        self.y = y


class MovementProcessor(esper.Processor):
    def process(self):
github benmoran56 / esper / examples / pyglet_example_batch.py View on Github external
def run(args=None):
    # Initialize the main window stuff
    window = pyglet.window.Window(width=RESOLUTION[0], height=RESOLUTION[1])
    window.set_caption("Esper pyglet Example")
    pyglet.gl.glClearColor(*BGCOLOR)
    # pyglet graphics batch for efficient rendering
    renderbatch = pyglet.graphics.Batch()

    # Initialize Esper world, and create a "player" Entity with a few Components.
    world = esper.World()
    player = world.create_entity()
    world.add_component(player, Velocity(x=0, y=0))
    redsquare = Renderable(texture=texture_from_image("redsquare.png"),
                           width=64,
                           height=64,
                           posx=100,
                           posy=100)
    world.add_component(player, redsquare)

    # Another motionless Entity:
    enemy = world.create_entity()
    bluesquare = Renderable(texture=texture_from_image("bluesquare.png"),
                            width=64,
                            height=64,
                            posx=400,
                            posy=250)