Inheritance: MSUnit
        private void DrawMoodFace(MSMobber mobber)
        {
            //This is where the position for the MoodFace gets updated when it goes out of bounds
            Rectangle boundingRectangle = mobber.MoodFace.BoundingRectangle;
            Vector2 position = mobber.MoodFace.Position;
            SpriteEffects effect = SpriteEffects.None;

            if (position.X + 50 < 0 ||
                position.X + 50 + boundingRectangle.Width > MSResolution.VirtualWidth)
            {
                Vector3 left = MSCamera.GetInstance().Frustum.GetCorners()[4];
                Vector3 right = MSCamera.GetInstance().Frustum.GetCorners()[5];

                double distLeft = Vector3.Distance(left, mobber.Position);
                double distRight = Vector3.Distance(right, mobber.Position);
                if (distLeft < distRight)
                {
                    position.X = 0;
                    effect = SpriteEffects.FlipHorizontally;
                }
                else
                {
                    position.X = MSResolution.VirtualWidth - boundingRectangle.Width;
                }
            }

            int maxY = 0;
            if (position.X >= 0 && position.X <= 465)
                maxY = (91 - 53) / 465 * (int)(position.X) + 53;
            else if (position.X > 465 && position.X < 540)
                maxY = 91;
            else if (position.X >= 540 && position.X <= 1024)
                maxY = (91 - 53) / (540 - 1024) * (int)(position.X - 1024) + 53;

            maxY += 20;

            if (position.Y < maxY ||
                position.Y + 50 + boundingRectangle.Height > MSResolution.VirtualHeight)
            {

                Vector3 top = MSCamera.GetInstance().Frustum.GetCorners()[4];
                Vector3 bottom = MSCamera.GetInstance().Frustum.GetCorners()[7];

                double distTop = Vector3.Distance(top, mobber.Position);
                double distBottom = Vector3.Distance(bottom, mobber.Position);

                if (distTop < distBottom)
                {
                    effect = SpriteEffects.FlipVertically;
                    position.Y = maxY;
                }
                else
                {
                    position.Y = MSResolution.VirtualHeight - boundingRectangle.Height;
                }
            }

            boundingRectangle = new Rectangle((int)position.X, (int)position.Y, boundingRectangle.Width, boundingRectangle.Height);
            SpriteBatch.Draw(mobber.MoodFace.Image, boundingRectangle, null, Color.White, 0, Vector2.Zero, effect, position.Y / MSResolution.VirtualHeight);
        }
Exemple #2
0
        public void Update(MSMap map)
        {
            List<MSUnit> toRemove = new List<MSUnit>();
            foreach (MSMobParam mp in this.mobTypeParam)
            {
                mp.incrTimer();
            }
            for (int i = 0; i < units.Count; i++)
            {
                MSUnit unit = units[i];
                if (!unit.DestinationReached)
                    unit.Walk(map.MapArray, units);

                else
                    toRemove.Add(unit);
            }

            foreach (MSUnit person in toRemove)
            {
                units.Remove(person);
                person.Dispose();
            }

            for (int i = 0; i < units.Count; i++)
            {
                int rnd = MSRandom.Instance.GetUniformInt(MAX_PROBABILITY);

                if (rnd <= MOB_RECRUIT_RATE && units[i].IsMobbable)
                {
                    foreach (MSUnit p in units)
                    {
                        if (p is MSMobber)
                        {
                            if (Vector3.Distance(units[i].Position, p.Position) <= MOB_RECRUIT_DISTANCE)
                            {
                                units[i] = new MSMobber(units[i].Position, p.Path, map, (p as MSMobber).Concern, p.Rotation);
                                units[i].Follow(p);
                                break;

                            }
                        }
                    }
                }
            }
        }
Exemple #3
0
 public void AddMember(MSMobber m)
 {
     mobList.Add(m);
 }
Exemple #4
0
        public void TryForBaby(MSMap map)
        {
            List<MSUnit> mobbers = new List<MSUnit>();

            for (int i = 0; i < 9; i++)
            {
                MSMobParam mp = this.mobTypeParam[i];
                int rnd = MSRandom.Instance.GetUniformInt(100);
                if (rnd < mp.getProbability())
                {
                    System.Console.WriteLine("SUCCESS");
                    MSUnit person;

                    MSUnchangeableBuilding source = map.GetRandomCitizenSource();

                    MSUnchangeableBuilding sink;
                    do
                    {
                        sink = map.GetRandomCitizenSource();
                    } while (source == sink);

                    Vector2 start = new Vector2(source.Row, source.Column);
                    Vector2 end = new Vector2(sink.Row, sink.Column);

                    MSMilleniumDevelopmentGoal? mdg = this.getGoal(i);

                    if (mdg != null)
                    {
                        MSMilleniumDevelopmentGoal mobmdg = (MSMilleniumDevelopmentGoal)mdg;
                        person = new MSMobber(
                                map.MapArray[(int)start.X, (int)start.Y].Position + MSUnit.UNITZ_POSITION,
                                map.GetPath(start, MSDistrictHall.getInstance().TileCoordinate), map, mobmdg, 0);
                    }
                    else
                    {
                        Node path = map.GetPath(start, end);
                        person = new MSCitizen(
                            map.MapArray[(int)start.X, (int)start.Y].Position + MSUnit.UNITZ_POSITION,
                            path, map, true, 0);
                    }

                    if (person != null)
                    {
                        if (mdg != null) units.Add(person);
                        else mobbers.Add(person);
                    }
                }
            }

            if( mobbers.Count > 0 )
                units.Add(mobbers.ElementAt<MSUnit>(MSRandom.Instance.GetUniformInt(mobbers.Count)));
        }