public void AttributesTestsMethod()
        {
            EntityWorld world = new EntityWorld();
            world.PoolCleanupDelay = 1;
            world.InitializeAll();

            Debug.Assert(world.SystemManager.Systems.Size == 2);

            Entity et = world.CreateEntity();
            var power = et.AddComponentFromPool<Power2>();
            power.POWER = 100;
            et.Refresh();

            Entity et1 = world.CreateEntityFromTemplate("teste");
            Debug.Assert(et1 != null);

            {
                world.Update(0, ExecutionType.UpdateSynchronous);
            }

            et.RemoveComponent<Power2>();
            et.Refresh();

            {
                world.Update(0, ExecutionType.UpdateSynchronous);
            }

            et.AddComponentFromPool<Power2>();
            et.GetComponent<Power2>().POWER = 100;
            et.Refresh();

            world.Update(0, ExecutionType.UpdateSynchronous);
        }
Exemple #2
0
 void Start()
 {
     world = new EntityWorld (false, true, true);
     world.InitializeAll (true);
     Entity e = world.CreateEntityFromTemplate ("Ship");
     GameObject obj = new GameObject("Ship");
     PhysicsRelay relay = obj.AddComponent<PhysicsRelay>();
     relay.SetEntity (e);
 }
        public void TestAttributes()
        {
            Debug.WriteLine("Initialize EntityWorld: ");
            EntityWorld entityWorld = new EntityWorld { PoolCleanupDelay = 1 };
            #if (!FULLDOTNET && !METRO) || CLIENTPROFILE
            entityWorld.InitializeAll(global::System.Reflection.Assembly.GetExecutingAssembly());
            #else
            entityWorld.InitializeAll(true);
            #endif
            Debug.WriteLine("OK");

            const int ExpectedNumberOfSystems = 2;
            int actualNumberOfSystems = entityWorld.SystemManager.Systems.Count;
            Assert.AreEqual(ExpectedNumberOfSystems, actualNumberOfSystems, "Number of initial systems does not fit.");
            Debug.WriteLine("Number of Systems: {0} OK", actualNumberOfSystems);

            Debug.WriteLine("Build up entity with component from pool manually: ");
            Entity entityWithPooledComponent = TestEntityFactory.CreateTestPowerEntityWithPooledComponent(entityWorld);
            Debug.WriteLine("OK");

            Debug.WriteLine("Build up entity from template: ");
            Entity entityFromTemplate = entityWorld.CreateEntityFromTemplate("test");
            Assert.IsNotNull(entityFromTemplate, "Entity from test template is null.");
            Debug.WriteLine("OK");

            entityWorld.Update();
            entityWorld.Draw();

            Debug.WriteLine("Remove component from entity: ");
            entityWithPooledComponent.RemoveComponent<TestPowerComponentPoolable>();

            entityWorld.Update();
            entityWorld.Draw();

            Assert.IsFalse(entityWithPooledComponent.HasComponent<TestPowerComponentPoolable>(), "Entity has still deleted component.");
            Debug.WriteLine("OK");

            Debug.WriteLine("Add component to entity: ");
            entityWithPooledComponent.AddComponentFromPool<TestPowerComponentPoolable>();
            entityWithPooledComponent.GetComponent<TestPowerComponentPoolable>().Power = 100;

            entityWorld.Update();
            entityWorld.Draw();

            Assert.IsTrue(entityWithPooledComponent.HasComponent<TestPowerComponentPoolable>(), "Could not add component to entity.");
            Debug.WriteLine("OK");
        }
        public void TestAttributes()
        {
            Debug.WriteLine("Initialize EntityWorld: ");
            EntityWorld entityWorld = new EntityWorld(false,true,true) { PoolCleanupDelay = 1 };
#if (!FULLDOTNET && !METRO) || CLIENTPROFILE
            entityWorld.InitializeAll(global::System.Reflection.Assembly.GetExecutingAssembly());       
#endif
            Debug.WriteLine("OK");

            const int ExpectedNumberOfSystems = 2;
            int actualNumberOfSystems = entityWorld.SystemManager.Systems.Count;
            Assert.AreEqual(ExpectedNumberOfSystems, actualNumberOfSystems, "Number of initial systems does not fit.");
            Debug.WriteLine("Number of Systems: {0} OK", actualNumberOfSystems);

            Debug.WriteLine("Build up entity with component from pool manually: ");
            Entity entityWithPooledComponent = TestEntityFactory.CreateTestPowerEntityWithPooledComponent(entityWorld);
            Debug.WriteLine("OK");

            Debug.WriteLine("Build up entity from template: ");
            Entity entityFromTemplate = entityWorld.CreateEntityFromTemplate("test");
            Assert.IsNotNull(entityFromTemplate, "Entity from test template is null.");
            Debug.WriteLine("OK");

            entityWorld.Update();
            entityWorld.Draw();

            Debug.WriteLine("Remove component from entity: ");
            entityWithPooledComponent.RemoveComponent<TestPowerComponentPoolable>();
       
            entityWorld.Update();
            entityWorld.Draw();

            Assert.IsFalse(entityWithPooledComponent.HasComponent<TestPowerComponentPoolable>(), "Entity has still deleted component.");
            Debug.WriteLine("OK");

            Debug.WriteLine("Add component to entity: ");
            entityWithPooledComponent.AddComponentFromPool<TestPowerComponentPoolable>();
            entityWithPooledComponent.GetComponent<TestPowerComponentPoolable>().Power = 100;

            entityWorld.Update();
            entityWorld.Draw();

            Assert.IsTrue(entityWithPooledComponent.HasComponent<TestPowerComponentPoolable>(), "Could not add component to entity.");
            Debug.WriteLine("OK");

            // TestNormalEntityProcessingSystem2 and TestNormalEntityProcessingSystem3 are autoloaded (marked with ArtemisEntitySystem attribute)
            List<TestNormalEntityProcessingSystem2> listOfTestNormalEntityProcessingSystem2 = entityWorld.SystemManager.GetSystems<TestNormalEntityProcessingSystem2>();
            Assert.IsNotNull(listOfTestNormalEntityProcessingSystem2, "Failed to retrieve autoloaded TestNormalEntityProcessingSystem2 system.");
            Assert.AreEqual(1, listOfTestNormalEntityProcessingSystem2.Count, "Invalid count of TestNormalEntityProcessingSystem2 systems");
            Debug.WriteLine("OK");

            List<TestNormalEntityProcessingSystem3> listOfTestNormalEntityProcessingSystem3 = entityWorld.SystemManager.GetSystems<TestNormalEntityProcessingSystem3>();
            Assert.IsNotNull(listOfTestNormalEntityProcessingSystem3, "Failed to retrieve autoloaded TestNormalEntityProcessingSystem3 system.");
            Assert.AreEqual(1, listOfTestNormalEntityProcessingSystem3.Count, "Invalid count of TestNormalEntityProcessingSystem3 systems");
            Debug.WriteLine("OK");

        }
 /// <summary>
 /// Creates our Player.
 /// </summary>
 /// <param name="world">The Game's EntityWorld.</param>
 /// <returns>The Player that was just created.</returns>
 public static Entity CreatePlayer(EntityWorld world)
 {
     Player = world.CreateEntityFromTemplate("agent");
     return Player;
 }
Exemple #6
0
        public void generate(EntityWorld entityWorld)
        {
            occupied = new bool[tileMap.Size.x, tileMap.Size.y];

            // Create border forest
            fillArea(generateArea(tileMap.Size / 2, (float)tileMap.Size.x + 1, (float)tileMap.Size.x + 1), 4);
            fillArea(generateArea(tileMap.Size / 2, 0f, (float)tileMap.Size.x / 2), 1);

            // Forest
            for (int i = 0; i < 16; ++i)
            {
                int2 pos = new int2(random.Next(tileMap.Size.x), random.Next(tileMap.Size.y));
                fillArea(generateArea(pos, 8f, 16f), 4);
            }

            // Small Forest
            for (int i = 0; i < 32; ++i)
            {
                int2 pos = new int2(random.Next(tileMap.Size.x), random.Next(tileMap.Size.y));
                fillArea(generateArea(pos, 2f, 8f), 4);
            }

            // Create player land
            fillArea(generateArea(new int2(18, 18), 4, 16), 2);
            fillArea(createPath(new Point(18, 18), new Point(tileMap.Size.x/2, tileMap.Size.y/2), 2, 0.5f), 2);

            // Paths:
            //float curliness = 0.75f;
            //for (int i = 0; i < 3; ++i)
            //{
            //    fillArea(createPath(new Point(0, 0), new Point(tileMap.Size.x - 1, tileMap.Size.y - 1), i + 2, curliness), 2);
            //    fillArea(createPath(new Point(0, 0), new Point(tileMap.Size.x - 1, tileMap.Size.y - 1), i + 2, curliness), 2);
            //    fillArea(createPath(new Point(0, 0), new Point(tileMap.Size.x - 1, tileMap.Size.y - 1), i + 2, curliness), 2);

            //    curliness *= 0.85f;
            //}

            List<Point> players = new List<Point>();
            players.Add(new Point(tileMap.Size.x / 6, tileMap.Size.y / 6));
            players.Add(new Point(tileMap.Size.x*3 / 6, tileMap.Size.y / 6));
            players.Add(new Point(tileMap.Size.x*5 / 6, tileMap.Size.y / 6));
            players.Add(new Point(tileMap.Size.x*5 / 6, tileMap.Size.y*5 / 6));
            players.Add(new Point(tileMap.Size.x*3 / 6, tileMap.Size.y*5 / 6));
            players.Add(new Point(tileMap.Size.x / 6, tileMap.Size.y*5 / 6));

            for (int i = 0; i < players.Count; ++i)
            {
                fillArea(createPath(players[i], players[(i+1)%players.Count], 5, 0.25f), 2);
                fillArea(generateArea(new int2(players[i].X, players[i].Y), 2, 16), 2);
                fillArea(generateArea(new int2(players[i].X, players[i].Y), 2, 4), 5);
            }
            fillArea(createPath(players[1], players[4], 5, 0.25f), 2);

            // River:
            Area riverArea = createPath(new Point(tileMap.Size.x - 1, 0), new Point(0, tileMap.Size.y - 1), 8, 0.5f);
            replaceArea(riverArea, 1, 3);
            replaceArea(riverArea, 2, 5);

            for (int x = 0; x < tileMap.Size.x; x++)
            {
                for (int y = 0; y < tileMap.Size.y; y++)
                {
                    float zoom = 0.05f;
                    if (tileMap.getTileID(x, y) == 4)
                    {
                        int treeWidth = 2;
                        int treeHeight = 2;

                        bool canPlaceTree = true;
                        for (int xt = 0; xt < treeWidth; xt++)
                        {
                            for (int yt = 0; yt < treeHeight; yt++)
                            {
                                int checkX = xt + x;
                                int checkY = yt + y;

                                if (checkX >= tileMap.Size.x || checkY >= tileMap.Size.y || occupied[checkX, checkY] || !tileMap.getTile(checkX, checkY).Name.Equals("tree"))
                                {
                                    canPlaceTree = false;
                                    break;
                                }
                            }
                            if (!canPlaceTree)
                                break;
                        }
                        if (!canPlaceTree)
                            continue;

                        entityWorld.CreateEntityFromTemplate("Resource", new object[] {
                            new int2(x, y),
                            (float)random.Next(360),
                            "wood",
                            500,
                            5
                        });

                        for (int xt = 0; xt < treeWidth; xt++)
                        {
                            for (int yt = 0; yt < treeHeight; yt++)
                            {
                                int checkX = xt + x;
                                int checkY = yt + y;
                                occupied[checkX, checkY] = true;
                            }
                        }
                    }
                }
            }

            for (int x = 0; x < tileMap.Size.x; x++)
            {
                for (int y = 0; y < tileMap.Size.y; y++)
                {
                    if (tileMap.getTile(x, y).Name.Equals("tree"))
                        tileMap.setTile(x, y, 1);
                }
            }
        }