Beispiel #1
0
        /// <summary>
        /// Creates an animated surface that looks like static.
        /// </summary>
        /// <param name="width">The width of the surface.</param>
        /// <param name="height">The height of the surface.</param>
        /// <param name="frames">How many frames the animation should have.</param>
        /// <param name="blankChance">Chance a character will be blank. Characters are between index 48-158. Chance is evaluated versus <see cref="System.Random.NextDouble"/>.</param>
        /// <returns>An animation.</returns>
        public static Consoles.AnimatedTextSurface CreateStatic(int width, int height, int frames, double blankChance)
        {
            var animation = new Consoles.AnimatedTextSurface("default", width, height, Engine.DefaultFont);
            var editor = new Consoles.SurfaceEditor(new Consoles.TextSurface(1, 1, Engine.DefaultFont));

            for (int f = 0; f < frames; f++)
            {
                var frame = animation.CreateFrame();
                editor.TextSurface = frame;

                for (int x = 0; x < width; x++)
                {
                    for (int y = 0; y < height; y++)
                    {
                        int character = Engine.Random.Next(48, 168);

                        if (Engine.Random.NextDouble() <= blankChance)
                            character = 32;

                        editor.SetGlyph(x, y, character);
                        editor.SetForeground(x, y, Color.White * (float)(Engine.Random.NextDouble() * (1.0d - 0.5d) + 0.5d));
                    }
                }

            }

            animation.AnimationDuration = 1;
            animation.Repeat = true;

            animation.Start();

            return animation;
        }
Beispiel #2
0
        /// <summary>
        /// Creates an animated surface that looks like static.
        /// </summary>
        /// <param name="width">The width of the surface.</param>
        /// <param name="height">The height of the surface.</param>
        /// <param name="frames">How many frames the animation should have.</param>
        /// <param name="blankChance">Chance a character will be blank. Characters are between index 48-158. Chance is evaluated versus <see cref="System.Random.NextDouble"/>.</param>
        /// <returns>An animation.</returns>
        public static Consoles.AnimatedTextSurface CreateStatic(int width, int height, int frames, double blankChance)
        {
            var animation = new Consoles.AnimatedTextSurface("default", width, height, Engine.DefaultFont);
            var editor    = new Consoles.SurfaceEditor(new Consoles.TextSurface(1, 1, Engine.DefaultFont));

            for (int f = 0; f < frames; f++)
            {
                var frame = animation.CreateFrame();
                editor.TextSurface = frame;

                for (int x = 0; x < width; x++)
                {
                    for (int y = 0; y < height; y++)
                    {
                        int character = Engine.Random.Next(48, 168);

                        if (Engine.Random.NextDouble() <= blankChance)
                        {
                            character = 32;
                        }

                        editor.SetGlyph(x, y, character);
                        editor.SetForeground(x, y, Color.White * (float)(Engine.Random.NextDouble() * (1.0d - 0.5d) + 0.5d));
                    }
                }
            }

            animation.AnimationDuration = 1;
            animation.Repeat            = true;

            animation.Start();

            return(animation);
        }
Beispiel #3
0
        /// <summary>
        /// Creates a new GameObject.
        /// </summary>
        public GameObject(Font font)
        {
            renderer  = new Consoles.TextSurfaceRenderer();
            animation = new Consoles.AnimatedTextSurface("default", 1, 1, Engine.DefaultFont);
            var frame = animation.CreateFrame();

            frame[0].GlyphIndex = 1;
            this.font           = animation.Font = font;
        }
 public static Consoles.AnimatedTextSurface ToFramework(AnimatedTextSurface serializedObject)
 {
     var animationSurface = new Consoles.AnimatedTextSurface(serializedObject.Name, serializedObject.Width, serializedObject.Height, serializedObject.Font);
     animationSurface.Frames = new List<TextSurfaceBasic>(serializedObject.Frames);
     animationSurface.CurrentFrameIndex = 0;
     animationSurface.AnimationDuration = serializedObject.AnimationDuration;
     animationSurface.Repeat = serializedObject.Repeat;
     animationSurface.Center = serializedObject.Center;
     return animationSurface;
 }
        public static Consoles.AnimatedTextSurface ToFramework(AnimatedTextSurface serializedObject)
        {
            var animationSurface = new Consoles.AnimatedTextSurface(serializedObject.Name, serializedObject.Width, serializedObject.Height, serializedObject.Font);

            animationSurface.Frames            = new List <TextSurfaceBasic>(serializedObject.Frames);
            animationSurface.CurrentFrameIndex = 0;
            animationSurface.AnimationDuration = serializedObject.AnimationDuration;
            animationSurface.Repeat            = serializedObject.Repeat;
            animationSurface.Center            = serializedObject.Center;
            return(animationSurface);
        }
 public static AnimatedTextSurface FromFramework(Consoles.AnimatedTextSurface surface)
 {
     return(new AnimatedTextSurface()
     {
         Frames = surface.Frames.ToArray(),
         Width = surface.Width,
         Height = surface.Height,
         AnimationDuration = surface.AnimationDuration,
         Name = surface.Name,
         Font = surface.Font,
         Repeat = surface.Repeat,
         Center = surface.Center
     });
 }