Exemple #1
0
        public override Entity clone()
        {
            Plant ret = (Plant)this.MemberwiseClone();

            ret.init();
            return(ret);
        }
Exemple #2
0
        public override bool Step()
        {
            base.Step();
            if (age > maxPlantAge)
            {
                parentEnvironment.remove(this);
            }

            if (val == 0)
            {
                val          = -plantRegrowAfter;
                this.visible = false;
            }
            else
            {
                if (val < 0 && val >= -2)
                {
                    //regrow
                    init();
                    this.visible = true;
                    age         += 50;
                }

                val += 2;

                if (val > plantsReproduceAfter)
                {
                    Plant p = (Plant)this.clone();
                    p.init();
                    p.age = 0;
                    parentEnvironment.addRandom(p, 1);

                    Plant  nearplant = (Plant)parentEnvironment.getNearest(x, y, new Plant(parentEnvironment));
                    double dist;
                    if (nearplant != null && (dist = parentEnvironment.getDistance(this.x, this.y, nearplant.x, nearplant.y)) < plantInterferenceRadius)
                    {
                        //next plant too near
                        if (Utils.rnd.Next(3) > 0)
                        {
                            parentEnvironment.remove(this);
                            return(true);
                        }
                    }
                }
            }
            return(true);
        }