Exemplo n.º 1
0
        public void Update()
        {
            if (Alive == true)
            {//生存なう
                MaxHP -= agePerTick;
                HP    -= agePerTick;
                if (!isStable)
                {
                    int   freq       = 10;
                    int   SpeedLevel = 5;
                    float MaxSpeed   = 0.5F;
                    if (Program.Rand.Next(freq) == 0)
                    {
                        float Direction = (float)((Program.Rand.Next(359) / 180.0f) * Math.PI);
                        float Speed     = MaxSpeed * SpeedLevel / 10;
                        //速度はCreatureの方で持つようにしました
                        Velocity = new Vector2D((float)Math.Cos(Direction), (float)Math.Sin(Direction)) * Speed;
                    }
                }
                ActMgr.Update();
                Nutrition -= new Nutrition(Size * 5, Size, Size);
                Nutrition  = Nutrition.clamp_floor(Nutrition.ZERO);

                if (!(this.Nutrition > Nutrition.ZERO))
                {
                    this.HP = 0;
                }
                if (!(this.Nutrition < this.MaxNutrition))
                {
                    Nutrition lastNut = this.Nutrition.Copy();
                    this.Nutrition = this.Nutrition.clamp(this.MaxNutrition);
                    mgr.Land.SetLandNutrition(Position, mgr.Land.GetLandNutrition(Position) + lastNut - Nutrition);
                }

                //突然の死
                if (Program.Rand.Next(1000) == 0)
                {
                    this.HP = 0;
                }

                //Nutrition.clamp(MaxNutrition);

                if (HP <= 0)
                {
                    Alive    = false;
                    deadTime = Time;
                    //栄養ばらまく。後々は、まず死体になってそれが分解されていく感じにしたい
                    OnDied();
                }
            }
            else
            {
                if (Nutrition.Sum <= 0)
                {
                    Existence = false;
                }
            }

            Time++;
        }
Exemplo n.º 2
0
 public static void Register()
 {
     ActMgr.RegisterAct(0, typeof(Divide));
     ActMgr.RegisterAct(1, typeof(Attack));
     //ActMgr.RegisterAct(2, typeof(Move));
     ActMgr.RegisterAct(4, typeof(Recover));
     ActMgr.RegisterAct(5, typeof(Age));
     //ActMgr.RegisterAct(6, typeof(Produce));
     ActMgr.RegisterAct(7, typeof(GetNutFromLand));
     ActMgr.RegisterAct(8, typeof(Scavenge));
     ActMgr.RegisterAct(9, typeof(Photosynthesis));
     ActMgr.RegisterAct(10, typeof(NitrogenFixation));
     ActMgr.RegisterAct(11, typeof(Chemoautotroph));
     ActMgr.RegisterAct(12, typeof(Stabilize));
 }
Exemplo n.º 3
0
 public Gene(Gene parentGene)
 {
     Size = parentGene.Size + Program.Rand.Next(-5, 5);
     if (Size < 10)
     {
         Size = 10;
     }
     HP = parentGene.HP + Program.Rand.Next(-50, 50);
     if (HP < 1)
     {
         HP = 1;
     }
     Nutrition = parentGene.Nutrition + new Nutrition().Rand(5);
     ActList   = new Dictionary <int, int>(parentGene.ActList); // 値渡し
     if (Program.Rand.Next(20) == 0)
     {
         int id    = ActMgr.GetRandomActId();
         int level = 1;
         if (ActList.ContainsKey(id))
         {
             level += ActList[id];
             ActList.Remove(id);
         }
         ActList.Add(id, level);
     }
     if (Program.Rand.Next(20) == 0)
     {
         if (ActList.Count > 1)
         {
             int pos   = Program.Rand.Next(ActList.Count - 1);
             int id    = ActList.Keys.ElementAt(pos);
             int level = ActList.Values.ElementAt(pos) - 1;
             if (level > 1)
             {
                 ActList.Remove(id);
                 ActList.Add(id, level);
             }
             else
             {
                 ActList.Remove(id);
             }
         }
     }
 }
Exemplo n.º 4
0
        public Creature(CreatureMgr mgr, Gene gene, Nutrition nutrition)
        {
            this.mgr = mgr;

            Gene         = gene;
            Size         = gene.Size;
            MaxHP        = gene.HP;
            HP           = Program.Rand.Next(MaxHP);
            MaxNutrition = gene.Nutrition;
            Nutrition    = nutrition;

            ActMgr.Initialize(this, TargetList, gene.ActList);

            Time = 0;

            Existence = true;
            Alive     = true;

            Velocity = new Vector2D();
            LastVelocityMultiplier = 60f / (float)mgr.TimerMax;
            Velocitycache          = new Vector2D();
        }