Exemplo n.º 1
0
        /// <summary>
        /// Creates the full set of bolt segments between the start and end points. Based upon the
        /// algorithm found at http://gamedevelopment.tutsplus.com/tutorials/how-to-generate-shockingly-good-2d-lightning-effects--gamedev-2681
        /// by Michael Hoffman.
        /// </summary>
        /// <param name="source"></param>
        /// <param name="dest"></param>
        /// <returns></returns>
        protected virtual List <CCPoint> CreateBolt(CCPoint source, CCPoint dest)
        {
            var          results   = new List <CCPoint>();
            List <float> seglength = new List <float>();
            CCPoint      tangent   = dest - source;
            CCPoint      normal    = CCPoint.Normalize(new CCPoint(tangent.Y, -tangent.X));
            float        length    = tangent.Length;

            List <float> positions = new List <float>();

            positions.Add(0);

            for (int i = 0; i < length / 4; i++)
            {
                positions.Add(CCMacros.CCRandomBetween0And1());
            }

            positions.Sort();

            CCPoint prevPoint        = source;
            float   prevDisplacement = 0;

            for (int i = 1; i < positions.Count; i++)
            {
                float pos = positions[i];

                // used to prevent sharp angles by ensuring very close positions also have small perpendicular variation.
                float scale = (length * m_Jaggedness) * (pos - positions[i - 1]);

                // defines an envelope. Points near the middle of the bolt can be farther from the central line.
                float envelope = pos > 0.95f ? 20f * (1f - pos) : 1f;

                float displacement = -m_Sway + 2f * m_Sway * CCMacros.CCRandomBetween0And1();
                displacement -= (displacement - prevDisplacement) * (1 - scale);
                displacement *= envelope;

                CCPoint point = source + tangent * pos + normal * displacement;
                // Core segment
                results.Add(prevPoint);
                results.Add(point);
                // Length of this segment
                float ll = (point - prevPoint).Length;
                seglength.Add(ll);
                _TrackLength += ll;
                // Continue to the next segment.
                prevPoint        = point;
                prevDisplacement = displacement;
            }

            results.Add(prevPoint);
            results.Add(dest);
            _SegmentLengths = seglength.ToArray();
            return(results);
        }
Exemplo n.º 2
0
        public AtlasFastBitmap()
        {
            // Upper Label
            for (int i = 0; i < 100; i++)
            {
                //char str[6] = {0};
                string str;
                //sprintf(str, "-%d-", i);
                str = string.Format("-{0,d}-", i);
                CCLabelBMFont label = new CCLabelBMFont(str, "fonts/bitmapFontTest.fnt");
                AddChild(label);

                CCSize s = CCDirector.SharedDirector.WinSize;

                CCPoint p = new CCPoint(CCMacros.CCRandomBetween0And1() * s.Width, CCMacros.CCRandomBetween0And1() * s.Height);
                label.Position    = p;
                label.AnchorPoint = new CCPoint(0.5f, 0.5f);
            }
        }