Example #1
0
        private void SetupWorld()
        {
            //TODO initialize the view first...
            int numPeople = 5;
            int mapSize   = 50;
            int numFoods  = 20;

            for (int i = 0; i < numFoods; ++i)
            {
                Vector2 pos = positionManager.closestEmpty(new Vector3(UnityEngine.Random.value * mapSize, 0f, UnityEngine.Random.value * mapSize));
                if (PositionManager.IsBogus(pos))
                {
                    continue;
                }
                Entity            food     = new Entity();
                PositionComponent position = new PositionComponent();
                position.position = pos;
                food.AddComponent(position);
                foods.Add(position);
                PlantComponent plant = new PlantComponent();
                food.AddComponent(plant);
                food.AddComponent(new CarriableComponent());
                positionManager.ObjectSpawnedAt(food, pos);
                UnityView.AddEntity(food);
            }
            for (int i = 0; i < numPeople; ++i)
            {
                Vector2 pos = positionManager.closestEmpty(new Vector3(UnityEngine.Random.value * mapSize, 0f, UnityEngine.Random.value * mapSize));
                if (PositionManager.IsBogus(pos))
                {
                    continue;
                }
                Entity            person   = new Entity();
                PositionComponent position = new PositionComponent();
                position.position = pos;
                person.AddComponent(position);
                HumanoidAI brain = new HumanoidAI();
                person.AddComponent(brain);
                BehaviorComponent agent = new BehaviorComponent(brain);
                agent.name = GetRandomName();
                person.AddComponent(agent);
                person.AddComponent(new InventoryComponent());
                positionManager.ObjectSpawnedAt(person, pos);
                UnityView.AddEntity(person);
                UnityView.RegisterControllableAgent(person);
            }
        }
        public static Entity CreatePlant(Vector2 position)
        {
            Vector3 offsetDir = UnityEngine.Random.onUnitSphere;
            var     plantPos  = new PositionComponent();

            plantPos.position = position;
            var    plantPlant = new PlantComponent();
            Entity plant      = new Entity();

            plant.AddComponent(plantPos);
            plant.AddComponent(plantPlant);
            plant.AddComponent(new CarriableComponent());
            ProceduralWorldSimulator.instance.positionManager.ObjectSpawnedAt(plant, position);
            ProceduralWorldSimulator.instance.foods.Add(plantPos);
            UnityView.AddEntity(plant);
            return(plant);
        }
Example #3
0
 public EatEvent(IEntity eater, PositionComponent food)
 {
     this.eater = eater.GetComponent <BehaviorComponent>();
     this.food  = food;
     this.plant = food.GetEntity().GetComponent <PlantComponent> ();
 }