Ejemplo n.º 1
0
        public Shape(Vector2 startingpnt, Random random)
        {
            _target              = null;
            _previousLoc         = new Vector2(-1, -1);
            _pointAttachment     = -1;
            _points              = new List <MagicPoint>();
            _shapePriority       = new Dictionary <Type, int>();
            _definedAttributes   = new Dictionary <string, int>();
            _castColorMod        = Color.White;
            _complexity          = 0;
            _damages             = new Dictionary <string, int>();
            _definedAttributes   = new Dictionary <string, int>();
            _finishedId          = new List <int>();
            _firstTarget         = false;
            _frame               = 0;
            _connections         = 0;
            _identifiedShapes    = new List <IDefinedShape>();
            _instabilityPoints   = 0;
            _instabilityProducts = new List <InstabilityProduct>();
            _speed               = .1f;
            _owners              = new List <ICaster>();
            _rotation            = 0;
            MagicPoint pnt = new MagicPoint();

            pnt.ID          = 0;
            pnt.Connections = new List <int>();
            pnt.Location    = startingpnt;
            pnt.FrameMod    = random.Next(0, 5);
            pnt.RotationMod = (float)(2 * Math.PI * random.NextDouble());
            pnt._rotdir     = random.Next(0, 2);
            if (pnt._rotdir == 0)
            {
                pnt._rotdir = -1;
            }
            else
            {
                pnt._rotdir = 1;
            }
            pnt.MoveToLocation = startingpnt;
            _points.Add(pnt);
        }
        /// <summary>
        /// add point from instability
        /// </summary>
        /// <param name="rand">random used within magic manager</param>
        /// <param name="instabilityPoints">instability points available for this IShape</param>
        /// <param name="shpe">IShape with instability</param>
        /// <returns>a number</returns>
        public static int AddPoint(Random rand, int instabilityPoints, IShape shpe)
        {
            int    originpnt = rand.Next(0, shpe.Points.Count - 1);
            double angle     = rand.NextDouble() * 2 * Math.PI;
            int    distance  = 1;

            if (instabilityPoints >= 1024)
            {
                distance = rand.Next(1, instabilityPoints / 1024);
            }
            instabilityPoints -= distance * 1024;
            distance          *= 10;
            MagicPoint pnt      = new MagicPoint();
            Vector2    location = new Vector2((float)Math.Cos(angle) * distance, (float)Math.Sin(angle) * distance);

            pnt.Location        = shpe.Points[originpnt].Location + location;
            pnt.Connections     = new List <int>();
            pnt.FrameMod        = rand.Next(0, 5);
            pnt.RotationMod     = (float)(2 * Math.PI * rand.NextDouble());
            pnt._moveToLocation = pnt.Location;
            pnt._rotdir         = rand.Next(0, 2);
            if (pnt._rotdir == 0)
            {
                pnt._rotdir = -1;
            }
            else
            {
                pnt._rotdir = 1;
            }
            shpe.Points.Add(pnt);
            if (instabilityPoints > 16384)
            {
                if (rand.Next(0, 5) == 0)
                {
                    int max = ((int)Math.Pow(2, shpe.Points.Count - 1));
                    if (max > 0)
                    {
                        int        connectionrand = rand.Next(0, max);
                        double     connectionsdub = Math.Log(connectionrand, 2);
                        int        connections    = shpe.Points.Count - 1 - (int)Math.Round(connectionsdub, MidpointRounding.AwayFromZero);
                        List <int> taken          = new List <int>();
                        if (connections >= shpe.Points.Count)
                        {
                            connections = 1;
                        }
                        //MagicPointConnection con = new MagicPointConnection();
                        for (int i = 0; connections > i; i++)
                        {
                            int point = rand.Next(0, shpe.Points.Count - 2 - i);
                            while (taken.Contains(point))
                            {
                                if (point < shpe.Points.Count - 2)
                                {
                                    point++;
                                }
                                else
                                {
                                    point = 0;
                                }
                            }
                            //con = new MagicPointConnection(location, shpe.Points[point]._location, PointConnectionType.Straight, shpe.Points.Count - 1, point);
                            //shpe.Connections.Add(con);
                            taken.Add(point);
                        }
                        instabilityPoints -= connections * 16384;
                    }
                }
            }
            return(0);
        }