Beispiel #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);
            }
        }
Beispiel #2
0
        public void SpawnOffspring()
        {
            int numOffspring = UnityEngine.Random.Range(numOffspringMin, numOffspringMax + 1);
            var position     = GetEntity().GetComponent <PositionComponent> ();

            for (int i = 0; i < numOffspring; ++i)
            {
                Vector3 offsetDir       = UnityEngine.Random.onUnitSphere;
                var     offsetMagnitude = UnityEngine.Random.value * spreadRadius;
                var     pos             = ProceduralWorldSimulator.instance.positionManager.closestEmpty(new Vector3(position.position.x + offsetDir.x * offsetMagnitude, 0f, position.position.y + offsetDir.y * offsetMagnitude));
                if (PositionManager.IsBogus(pos))
                {
                    continue;
                }
                ThingCreator.CreatePlant(pos);
            }
        }