Exemple #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 AnimatedSurface CreateStatic(int width, int height, int frames, double blankChance)
        {
            var animation = new AnimatedSurface("default", width, height, Global.FontDefault);
            var editor    = new SurfaceEditor(new BasicSurface(1, 1, Global.FontDefault));

            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 = Global.Random.Next(48, 168);

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

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

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

            animation.Start();

            return(animation);
        }
        public GameObjectTest() : base(80, 23)
        {
            var textAnimation = new AnimatedSurface("default", 14, 5);           // Animated surface size. 14,5

            fallingText = new SadConsole.GameHelpers.GameObject(textAnimation);

            var editor = new SadConsole.Surfaces.SurfaceEditor(new SadConsole.Surfaces.BasicSurface(1, 1));

            for (int line = 0; line < 5; line++)
            {
                var frame = textAnimation.CreateFrame();
                editor.TextSurface = frame;
                editor.Fill(Color.Purple, Color.DarkGray, 178, null);                 // 219 178
                editor.Print(1, line, "Hello World!");
            }

            textAnimation.AnimationDuration = 1;             // Set it to -1 to make it faster than 1 sec
            textAnimation.Repeat            = true;

            textAnimation.Start();

            fallingText.Animation = textAnimation;
            //fallingText.Position = new Point(1,1);

            Children.Add(fallingText);
        }
        public static GameObject CreateBlinkingFromGlyph(int glyph, float duration, Color color = new Color())
        {
            if (color == new Color())
            {
                color = Color.White;
            }

            var animation = new AnimatedSurface("anim", 1, 1);
            var editor    = new SurfaceEditor(animation.CreateFrame());

            editor.SetGlyph(0, 0, glyph, color);
            animation.CreateFrame();    //empty frame
            animation.AnimationDuration = duration;
            animation.Repeat            = true;
            animation.Start();
            return(new GameObject(animation));
        }
Exemple #4
0
        public override void Update(TimeSpan delta)
        {
            // If we're generating a new
            if (state == InitState.BeforeGeneration)
            {
                // Clear out the text surface
                TextSurface = new BasicSurface(1, 1);
                state       = InitState.Generating;

                SetMessage("Generating map, please wait...  ");

                // Kick off task
                loadingAnimation.Start();
                createRandomWorldTask = new Task <BasicSurface>(GenerateWorld);
                createRandomWorldTask.Start();
            }
            else if (state == InitState.Generating)
            {
                // Update the animation
                loadingAnimation.Update();

                // "Print" the animation to the message console.
                loadingAnimation.Copy(messageData.TextSurface, messageData.Width - 1, 0);

                // If task done...
                if (createRandomWorldTask.IsCompleted)
                {
                    SetMessage("[SPACE] Change Map Info [ENTER] New Map -- Biome   ");
                    this.TextSurface = createRandomWorldTask.Result;
                    state            = InitState.AfterGeneration;
                }
            }
            else if (state == InitState.AfterGeneration)
            {
                loadingAnimation.Stop();
                state = InitState.Completed;
            }
            else
            {
                base.Update(delta);
            }
        }