Ejemplo n.º 1
0
        public void intialize(int width, int height)
        {
            this.width = width;
            this.height = height;
            this.cropNumber = width / 200;

            center = new Vector2(width / 2, height / 2);

            // choose random points to be crops within the map
            for (int i = 0; i < cropNumber; i++)
            {
                int x = random.Next(width);
                int y = random.Next(height);

                Vector2 point = new Vector2(x, y);
                float minD = Math.Min(height / 2, width / 2);
                if (Vector2.Distance(center, point) >= minD - 100)
                {
                    // not within the circle so generate new points
                    i--;
                }
                else
                {
                    Environment grass = new Environment("grass", 10, 10, 5, (short)x, (short)y, 0, System.Environment.TickCount + i + 1);
                    Crop field = new Crop(grass, random.Next(3, 8), System.Environment.TickCount + i, 4);
                    crops.Add(field);
                }
            }
        }
Ejemplo n.º 2
0
        public Environment(String name, short foodValue, short energyValue, short size, short xPos, short yPos, int type, int randSeed, Crop theCrop)
        {
            this.name = name;
            this.foodValue = foodValue;
            this.size = size;
            this.energyValue = energyValue;
            this.position = new Vector2((float)xPos, (float)yPos);
            this.type = type;
            this.frame = 0;
            random = new Random(randSeed);

            this.theCrop = theCrop;

            switch (type)
            {
                case 0:
                    spriteRectangle = Sprites.flower;
                    break;
                case 1:
                    spriteRectangle = Sprites.flower;
                    break;
                default:
                    spriteRectangle = Sprites.flower;
                    break;
            }

            float w = size * 0.1f * spriteRectangle.Width;
            float h = size * 0.1f * spriteRectangle.Height;

            orientation = random.Next(62) * 0.1f;

            origin = new Vector2(spriteRectangle.Width / 2, spriteRectangle.Height / 2);

            body = new CircleOfLife.RotatedRectangle(new Rectangle(xPos, yPos, (int)w, (int)h), orientation);

            color = Color.Green;
        }
Ejemplo n.º 3
0
        public void update(GameTime gameTime)
        {
            // if there are less than the required number of crops then add some new ones
            if (crops.Count < cropNumber)
            {
                int i = 0;

                while (i == 0)
                {
                    int x = random.Next(width);
                    int y = random.Next(height);

                    Vector2 point = new Vector2(x, y);
                    float minD = Math.Min(height / 2, width / 2);
                    if (Vector2.Distance(center, point) < minD - 100)
                    {
                        // within the circle so generate new points
                        i++;
                        Environment grass = new Environment("grass", 10, 10, 5, (short)x, (short)y, 0, System.Environment.TickCount + 1);
                        Crop field = new Crop(grass, random.Next(3, 8), System.Environment.TickCount, 4);
                        crops.Add(field);
                    }

                }
            }

            // remove any plants that are dead
            // grow the grass
            for (int i = 0; i < crops.Count(); i++)
            {
                if (crops[i].plants.Count == 0)
                {
                    crops.RemoveAt(i);
                    i--;
                }
                else
                {
                    crops[i].grow(gameTime, this.width, this.height);
                }
            }
        }