Beispiel #1
0
        public void gather(Mineral m)
        {
            Random random = new Random();

            int alpha = random.Next(10);

            switch (alpha)
            {
                case 0:
                case 1:
                case 2:
                case 3:
                    resourceA++;
                    break;
                case 4:
                case 5:
                case 6:
                    resourceB++;
                    break;
                case 7:
                case 8:
                    resourceC++;
                    break;
                case 9:
                    resourceD++;
                    break;
            }
        }
Beispiel #2
0
        public GatherZone(ResourceManager _rm, Game1 _game)
        {
            game = _game;
            manager = _rm;

            gatherers = new List<Gatherer>();
            minerals = new List<Mineral>();
            gatherersAddQueue = new List<Gatherer>();
            mineralsAddQueue = new List<Mineral>();
            gatherersDeleteQueue = new List<Gatherer>();
            mineralsDeleteQueue = new List<Mineral>();

            //minerals
            for (int i = 0; i < 400; ++i)
            {
                Vector3 p = new Vector3(250, 8, 0);
                p += new Vector3((float)rand.NextDouble(), 0.5f, (float)rand.NextDouble()) * 200f - Vector3.One * 80f;

                Mineral m = new Mineral(this, p);

                add(m);
            }
            //gatherers
            for (int i = 0; i < 10; ++i)
            {
                Gatherer g = new Gatherer(this, new Vector3(100, 8, -40 + 8 * i));

                g.targetPosition = new Vector3(250, 8, 0);

                add(g);
            }

            updateLists();
        }
Beispiel #3
0
        public void update()
        {
            if (mining) {
                if (targetMineral != null)
                {
                    // this is the speed at which minerals are mined
                    targetMineral.life-=2;

                    if (targetMineral.life <= 0)
                    {
                        gatherzone.manager.gather(targetMineral);
                        targetMineral.remove();
                    }
                }
                else
                {
                    mining = false;
                }

            } else {
                if (targetMineral == null) {
                    //... go toward targetPosition ...

                    if ((targetPosition - position).Length() < size)
                    {
                        if (gatherzone.minerals.Count > 0)
                        {
                            Random rand = new Random();
                            targetPosition = gatherzone.minerals[rand.Next(gatherzone.minerals.Count)].position;
                        }
                    }
                    else
                    {
                        direction = targetPosition - position;
                        direction.Normalize();
                        position += direction * speed;

                        List<Mineral> nearby = gatherzone.getNearbyMinerals(viewRadius);
                        if (nearby.Count > 0)
                        {
                            targetMineral = nearby[0];
                            targetMineral.addFollower(this);
                        }
                    }

                } else {
                    // if (... close enough to targetMineral ...)
                    if ((targetMineral.position - position).Length() < size) {
                        if (targetMineral.myGatherer == null) {
                            targetMineral.myGatherer = this;
                            targetMineral.addFollower(this);
                            mining = true;
                        } else {
                            targetMineral = null;
                            mining = false;
                        }
                    } else {
                        //... go toward targetMineral ...
                        direction = targetMineral.position - position;
                        direction.Normalize();
                        position += direction * speed;
                    }
                }
            }
        }
Beispiel #4
0
 public void add(Mineral m)
 {
     mineralsAddQueue.Add(m);
 }
Beispiel #5
0
        public void update()
        {
            if (rand.NextDouble() < 0.01) {
                Vector3 p = new Vector3(250, 8, 0);
                p += new Vector3((float)rand.NextDouble(), 0.5f, (float)rand.NextDouble()) * 160f - Vector3.One * 80f;

                Mineral m = new Mineral(this, p);

                add(m);
            }

            if ((rand.NextDouble() < 0.05) && (minerals.Count < gatherers.Count * 2))
            {
                for (int i = 0; i < 200; ++i)
                {
                    Vector3 p = new Vector3(250, 8, 0);
                    p += new Vector3((float)rand.NextDouble(), 0.5f, (float)rand.NextDouble()) * 160f - Vector3.One * 80f;

                    Mineral m = new Mineral(this, p);

                    add(m);
                }
            }

            foreach (Gatherer g in gatherers)
                g.update();
            foreach (Mineral m in minerals)
                m.update();
            updateLists();

            game.LIFE = gatherers.Count() * 100;
        }
Beispiel #6
0
 public void remove(Mineral m)
 {
     mineralsDeleteQueue.Add(m);
 }