public void Test()
        {
            World         world   = new World();
            EntityHandler entityA = world.CreateEntity();

            entityA.AddComponent(new TestComponent());

            EntityHandler entityB = world.CreateEntity();

            entityB.AddComponent(new TestComponent());

            GameSystem system = new TestSystem(world);

            Assert.IsTrue(entityA.GetComponent <TestComponent>().foo == 0, "component default value is wrong");

            system.Update();
            Assert.IsTrue(entityA.GetComponent <TestComponent>().foo == 1, "component A did not update correctly after system update");
            Assert.IsTrue(entityB.GetComponent <TestComponent>().foo == 1, "component B did not update correctly after system update");

            system.Update();
            Assert.IsTrue(entityA.GetComponent <TestComponent>().foo == 2, "component A did not update correctly after system update");
            Assert.IsTrue(entityB.GetComponent <TestComponent>().foo == 2, "component B did not update correctly after system update");

            world.RemoveEntity(entityA.entity);
            Assert.IsTrue(
                !world.GetComponentManager <TestComponent>().EntityHasComponent(entityA.entity),
                "entity A was not removed");

            system.Update();
            Assert.IsTrue(entityB.GetComponent <TestComponent>().foo == 3, "component B did not update correctly after system update");
        }
Beispiel #2
0
        private void InitWorld()
        {
            world = new World();

            gameLogicSystems.Add(new ApplyVelocitySystem(world));

            EntityHandler entity = world.CreateEntity();

            entity.AddComponent(new TransformComponent(-500, 400));
            entity.AddComponent(new VelocityComponent(150f, -75f));
            entity.AddComponent(new SpriteComponent());

            entity = world.CreateEntity();
            entity.AddComponent(new TransformComponent(500, 400));
            entity.AddComponent(new VelocityComponent(-150f, -95f));
            entity.AddComponent(new SpriteComponent());
        }