Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            //Give Components a cId
            EntityComponent.HealthComponent.cid = _id++;
            EntityFu.Component.numCids          = _id; //total number of cids

            //Create a new entity and add a HealthComponent to it
            EntityFu.create(
                new EntityComponent.HealthComponent(10, 100)
                );

            EntityFu.create(
                new EntityComponent.HealthComponent(5, 50)
                );


            //Example usage, take away 1 health point every second.
            while (EntityFu.count() > 0)
            {
                EntitySystem.HealthSystem.tick(0.1);
                Thread.Sleep(1000);
            }

            //We're done. Destroy it.
            EntityFu.dealloc();
            Console.ReadLine();
        }
Ejemplo n.º 2
0
            public static void tick(double fixedDelta)
            {
                List <Eid> entitiesToDestroy = new List <Eid>(); //Required to keep from getting 'Collection Was Modified' exception

                var all = EntityFu.getAll(EntityComponent.HealthComponent.getCid());

                // for this example, just decrement all health components each tick
                foreach (var eid in all)
                {
                    Ent e = new Ent(eid);

                    // this is overly pragmatic, but you get the drift of how to check if a component is valid
                    if (e.health == null || e.health.isEmpty())
                    {
                        continue;
                    }

                    // decrement
                    e.health.hp--;
                    if (e.health.hp < 0)
                    {
                        e.health.hp = 0;
                    }
                    Console.Write("Entity ");
                    Console.Write((int)e.id);
                    Console.Write(" has ");
                    Console.Write(e.health.hp);
                    Console.Write("/");
                    Console.Write(e.health.maxHP);
                    Console.Write(" hit points.");
                    Console.Write("\n");

                    // destroy entity if zero health
                    if (e.health.hp <= 0)
                    {
                        //EntityFu.destroyNow(eid);
                        entitiesToDestroy.Add(eid);
                    }
                }

                foreach (Eid eid in entitiesToDestroy)
                {
                    EntityFu.destroyNow(eid);
                }
            }
Ejemplo n.º 3
0
            /// Add more components your systems will use frequently

            public Ent(Eid _id)
            {
                health = (EntityComponent.HealthComponent)EntityFu.getComponent(EntityComponent.HealthComponent.getCid(), _id);
                id     = _id;
            }