Example #1
0
    private Dictionary <string, int> CountAnimalsInChunk(IntVector2 chunkIndex)
    {
        Dictionary <string, int> count = new Dictionary <string, int>();

        if (player.HasNode("AnimalArea"))
        {
            Vector3 playerPos = player.GetTranslation();
            Array   bodies    = (player.GetNode("AnimalArea") as Area).GetOverlappingBodies();

            Vector3 chunkCentre = (new Vector3(chunkIndex.x * Chunk.SIZE.x, Chunk.SIZE.y / 2.0f, chunkIndex.y * Chunk.SIZE.z) * Block.SIZE) + (new Vector3((Chunk.SIZE.x * Block.SIZE), 0, (Chunk.SIZE.y * Block.SIZE)) / 2.0f);

            foreach (PhysicsBody body in bodies)
            {
                if (body.IsInGroup("animals"))
                {
                    AnimalBehaviourComponent behaviour = ((Entity)body.GetNode("Entity")).GetComponent <AnimalBehaviourComponent>();
                    if (!count.ContainsKey(behaviour.PresetName))
                    {
                        count.Add(behaviour.PresetName, 1);
                    }
                    else
                    {
                        count[behaviour.PresetName]++;
                    }
                }
            }
        }

        return(count);
    }
Example #2
0
    private void KillAnimal(Node animalNode)
    {
        AnimalBehaviourComponent animal = (animalNode.GetNode("Entity") as Entity).GetComponent <AnimalBehaviourComponent>();

        animal.Kill();
        player.AddItem(ItemID.MEAT, animal.FoodDrop);
    }
Example #3
0
    public void ObjectOutOfRange(object[] args)
    {
        PhysicsBody body = (PhysicsBody)args[0];

        if (body.IsInGroup("animals"))
        {
            AnimalBehaviourComponent behaviourComponent = ((Entity)body.GetNode("Entity")).GetComponent <AnimalBehaviourComponent>();
            if (behaviourComponent.PresetName.Equals(component.PresetName) && behaviourComponent.Sex != component.Sex)
            {
                breedableTargets.Remove(body);
            }
        }
    }
Example #4
0
 private void eat(Godot.Object nom)
 {
     component.Satiated = Math.Max(100.0f, component.Satiated + 20.0f);
     if (nom is PhysicsBody)
     {
         PhysicsBody otherBody = (PhysicsBody)nom;
         if (otherBody.IsInGroup("animals"))
         {
             AnimalBehaviourComponent behaviourComponent = ((Entity)otherBody.GetNode("Entity")).GetComponent <AnimalBehaviourComponent>();
             behaviourComponent.Kill();
         }
         else if (otherBody.IsInGroup("plants"))
         {
             otherBody.QueueFree();
             otherBody.RemoveFromGroup("alive");
         }
     }
     active = false;
 }
Example #5
0
    public void ObjectOutOfRange(object[] args)
    {
        PhysicsBody otherBody = (PhysicsBody)args[0];

        if (otherBody.IsInGroup("animals"))
        {
            AnimalBehaviourComponent behaviourComponent = ((Entity)otherBody.GetNode("Entity")).GetComponent <AnimalBehaviourComponent>();
            if (IsFood(otherBody) && behaviourComponent.FoodChainLevel < component.FoodChainLevel)
            {
                foodInRange.Remove(otherBody);
            }
        }
        else
        {
            if (IsFood(otherBody))
            {
                foodInRange.Remove(otherBody);
            }
        }
    }
Example #6
0
    public void SpawnAnimal(string presetName, AnimalBehaviourComponent.AnimalSex sex, Vector3 position)
    {
        // Choose preset
        AnimalPreset preset = null;

        foreach (AnimalPreset p in presets)
        {
            if (p.presetName.Equals(presetName) && p.sex == sex)
            {
                preset = p;
                break;
            }
        }

        // Use preset to generate animal
        PackedScene chosenScene = preset.scene;

        KinematicBody kb = (KinematicBody)chosenScene.Instance();

        Entity entity = new Entity();

        kb.AddChild(entity);

        entity.SetName("Entity");

        AnimalBehaviourComponent behaviourComponent = new AnimalBehaviourComponent(entity, preset.sex, preset.diet, preset.foodChainLevel, preset.breedability,
                                                                                   preset.presetName, preset.oxygenConsumption, preset.co2Production, preset.foodDrop, preset.birthDrop);
        PhysicsComponent physicsComponent = new PhysicsComponent(entity);

        entity.AddComponent(behaviourComponent);
        entity.AddComponent(physicsComponent);

        kb.SetTranslation(position);

        AddChild(kb);
    }
Example #7
0
 public EatStrategy(AnimalBehaviourComponent component) : base(component)
 {
 }
Example #8
0
 public BaseStrategy(AnimalBehaviourComponent component)
 {
     this.component = component;
 }