Example #1
0
	def test_system(self):
		Engine.reset_indices()
		s = TestIteratingSystem()
		e1 = Entity()
		vel = VelocityComponent(1,0,0)
		pos = PositionComponent()
		e1.add(vel)
		e1.add(pos)
		engine = Engine()
		engine.add_entity(e1)
		engine.add_system(s)

		for i in range(10):
			engine.update(0.5)

		self.assertEqual(pos.x, 5.0)
Example #2
0
    def test_system(self):
        Engine.reset_indices()
        s = TestIteratingSystem()
        e1 = Entity()
        vel = VelocityComponent(1, 0, 0)
        pos = PositionComponent()
        e1.add(vel)
        e1.add(pos)
        engine = Engine()
        engine.add_entity(e1)
        engine.add_system(s)

        for i in range(10):
            engine.update(0.5)

        self.assertEqual(pos.x, 5.0)
Example #3
0
	def test_component(self):
		global COMPONENT_REMOVED
		global COMPONENT_ADDED

		Engine.reset_indices()
		engine = Engine()
		e1 = Entity()
		c = VelocityComponent()
		e1.component_added.append(TestComponentAddedListener())
		e1.component_removed.append(TestComponentRemovedListener())
		engine.add_entity(e1)
		e1.add(c)
		self.assertEqual(COMPONENT_ADDED, e1)
		reset_component_listener_test()

		family = Family.get_for_bits(ComponentType.get_bits_for(VelocityComponent))
		entities = engine.get_entities_for(family)
		self.assertEqual(entities[0], e1)

		e1.remove(VelocityComponent)
		self.assertEqual(COMPONENT_REMOVED, e1)
		reset_component_listener_test()
Example #4
0
    def test_remove_entity(self):
        global ENTITY_ADDED
        global ENTITY_REMOVED

        Engine.reset_indices()
        engine = Engine()
        engine.add_entity_listener(TestEntityListener())
        e1 = Entity()
        engine.add_entity(e1)
        engine.remove_entity(e1)
        entities = engine.get_entities()
        self.assertEqual(len(entities), 0)
        self.assertEqual(len(e1.component_added), 0)
        self.assertEqual(len(e1.component_removed), 0)
        self.assertEqual(ENTITY_REMOVED, e1)
        reset_entity_listener_test()

        e2 = Entity()
        engine.add_entity(e1)
        engine.add_entity(e1)
        engine.remove_all_entities()
        entities = engine.get_entities()
        self.assertEqual(len(entities), 0)
Example #5
0
    def test_add_entity(self):
        global ENTITY_ADDED
        global ENTITY_REMOVED

        Engine.reset_indices()
        engine = Engine()
        engine.add_entity_listener(TestEntityListener())
        e1 = Entity()
        engine.add_entity(e1)
        entities = engine.get_entities()
        self.assertEqual(e1, entities[0])
        self.assertTrue(
            e1.component_added[0] is engine.component_added_listener)
        self.assertTrue(
            e1.component_removed[0] is engine.component_removed_listener)

        self.assertEqual(ENTITY_ADDED, e1)
        reset_entity_listener_test()
Example #6
0
    def test_component(self):
        global COMPONENT_REMOVED
        global COMPONENT_ADDED

        Engine.reset_indices()
        engine = Engine()
        e1 = Entity()
        c = VelocityComponent()
        e1.component_added.append(TestComponentAddedListener())
        e1.component_removed.append(TestComponentRemovedListener())
        engine.add_entity(e1)
        e1.add(c)
        self.assertEqual(COMPONENT_ADDED, e1)
        reset_component_listener_test()

        family = Family.get_for_bits(
            ComponentType.get_bits_for(VelocityComponent))
        entities = engine.get_entities_for(family)
        self.assertEqual(entities[0], e1)

        e1.remove(VelocityComponent)
        self.assertEqual(COMPONENT_REMOVED, e1)
        reset_component_listener_test()
Example #7
0
		self.graphics_list = graphics_list

class ParentTransformComponent(Component):
	def __init__(self, parent_entity):
		self.parent_entity = parent_entity

class SailSystem(IteratingSystem):
	family = Family.get_for_classes(SailComponent)


class RenderingSystem(IteratingSystem):
	family = Family.get_for_classes(GraphicsComponent)
	def __init__(self):
		super(RenderingSystem, self).__init__(self.family)

	def process_entity(self, entity, deltatime):
		print(entity, deltatime)



if __name__ == '__main__':
	engine = Engine()
	e1 = Entity()
	engine.add_entity(e1)
	e1.add(GraphicsComponent())

	rs = RenderingSystem()
	engine.add_system(rs)

	engine.update(1.0)