Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def world():
return esper.World()
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
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():
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)
def create_world(cls): cls.world = esper.World()
@classmethod
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):
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)