コード例 #1
0
        public RandomScrollingConsole() : base(80, 25)
        {
            messageData          = new Console(1, 1);
            messageData.CellData = CellData;
            IsVisible            = false;


            KeyboardHandler = (cons, info) =>
            {
                if (info.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Left))
                {
                    cons.ViewArea = new Rectangle(cons.ViewArea.X - 1, cons.ViewArea.Y, 80, 25);
                }

                if (info.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Right))
                {
                    cons.ViewArea = new Rectangle(cons.ViewArea.X + 1, cons.ViewArea.Y, 80, 25);
                }

                if (info.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Up))
                {
                    cons.ViewArea = new Rectangle(cons.ViewArea.X, cons.ViewArea.Y - 1, 80, 25);
                }

                if (info.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Down))
                {
                    cons.ViewArea = new Rectangle(cons.ViewArea.X, cons.ViewArea.Y + 1, 80, 25);
                }

                return(true);
            };
        }
コード例 #2
0
ファイル: Game1.cs プロジェクト: modulexcite/SadConsole
 public FPSCounterComponent(Game game)
     : base(game)
 {
     console = new CellsRenderer(new CellSurface(30, 1), new SpriteBatch(game.GraphicsDevice));
     console.CellData.DefaultBackground = Color.Black;
     console.CellData.Clear();
     console.Position = new Point(0, 10);
 }
コード例 #3
0
        public WorldGenerationConsole() : base(80, 25)
        {
            messageData          = new Console(1, 1);
            messageData.CellData = CellData;
            IsVisible            = false;

            KeyboardHandler = (cons, info) =>
            {
                if (info.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Left))
                {
                    cons.ViewArea = new Rectangle(cons.ViewArea.X - 1, cons.ViewArea.Y, 80 * ZoomLevel.X, 25 * ZoomLevel.Y);
                }

                if (info.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Right))
                {
                    cons.ViewArea = new Rectangle(cons.ViewArea.X + 1, cons.ViewArea.Y, 80 * ZoomLevel.X, 25 * ZoomLevel.Y);
                }

                if (info.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Up))
                {
                    cons.ViewArea = new Rectangle(cons.ViewArea.X, cons.ViewArea.Y - 1, 80 * ZoomLevel.X, 25 * ZoomLevel.Y);
                }

                if (info.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Down))
                {
                    cons.ViewArea = new Rectangle(cons.ViewArea.X, cons.ViewArea.Y + 1, 80 * ZoomLevel.X, 25 * ZoomLevel.Y);
                }

                if (info.IsKeyReleased(Microsoft.Xna.Framework.Input.Keys.Enter))
                {
                    messageData.CellData.Fill(Color.White, Color.Black, 0, null);
                    messageData.CellData.Print(0, 0, "Generating map, please wait...");
                    initialized      = true;
                    initializedStep2 = false;
                    initializedStep3 = false;
                }

                if (info.IsKeyReleased(Microsoft.Xna.Framework.Input.Keys.Space))
                {
                    if (CellData == generator.HeightMapRenderer)
                    {
                        CellData = generator.HeatMapRenderer;
                        messageData.CellData.Print(0, 0, $"[SPACE] Change Map Info [ENTER] New Map -- Heat    ", Color.White, Color.Black);
                    }
                    else if (CellData == generator.HeatMapRenderer)
                    {
                        CellData = generator.MoistureMapRenderer;
                        messageData.CellData.Print(0, 0, $"[SPACE] Change Map Info [ENTER] New Map -- Moisture", Color.White, Color.Black);
                    }
                    else if (CellData == generator.MoistureMapRenderer)
                    {
                        CellData = generator.BiomeMapRenderer;
                        messageData.CellData.Print(0, 0, $"[SPACE] Change Map Info [ENTER] New Map -- Biome   ", Color.White, Color.Black);
                    }
                    else
                    {
                        CellData = generator.HeightMapRenderer;
                        messageData.CellData.Print(0, 0, $"[SPACE] Change Map Info [ENTER] New Map -- Height  ", Color.White, Color.Black);
                    }
                }

                return(true);
            };
        }
コード例 #4
0
ファイル: Engine.cs プロジェクト: drock07/SadConsole
 /// <summary>
 /// Returns the amount of cells (X,Y) given the specified <see cref="CellSurface"/> and current <see cref="Engine.WindowWidth"/> and <see cref="Engine.WindowHeight"/> properties.
 /// </summary>
 /// <param name="surface">The cell surface.</param>
 /// <returns>The amount of cells along the X and Y axis.</returns>
 public static Point GetScreenSizeInCells(CellsRenderer surface)
 {
     return(new Point(WindowWidth / surface.CellSize.X, WindowHeight / surface.CellSize.Y));
 }
コード例 #5
0
        public SplashScreen()
            : base(80, 25)
        {
            IsVisible = false;

            // Setup the console text background
            string textTemplate = "sole SadCon";

            System.Text.StringBuilder text = new System.Text.StringBuilder(2200);

            for (int i = 0; i < CellData.Width * CellData.Height; i++)
            {
                text.Append(textTemplate);
            }
            this.CellData.Print(0, 0, text.ToString(), Color.Black, Color.Transparent);

            // Load the logo
            System.IO.Stream imageStream = System.IO.File.OpenRead("sad.png");
            var image = Texture2D.FromStream(Engine.Device, imageStream);

            imageStream.Dispose();

            // Configure the logo
            _consoleImage          = new CellsRenderer(new CellSurface(image.Width, image.Height), this.Batch);
            _consoleImage.Position = new Point(CellData.Width / 2 - image.Width / 2, -1);
            image.DrawImageToSurface(_consoleImage.CellData, new Point(0, 0), true);
            _consoleImage.Tint = Color.Black;

            // Configure the animations
            _animation = new InstructionSet();
            _animation.Instructions.AddLast(new Wait()
            {
                Duration = 0.3f
            });

            // Animation to move the angled gradient spotlight effect.
            var moveGradientInstruction = new CodeInstruction();

            moveGradientInstruction.CodeCallback = (inst) =>
            {
                _x += 1;

                if (_x > _cellData.Width + 50)
                {
                    inst.IsFinished = true;
                }

                Color[] colors     = new Color[] { Color.Black, Color.DarkBlue, Color.White, Color.DarkBlue, Color.Black };
                float[] colorStops = new float[] { 0f, 0.2f, 0.5f, 0.8f, 1f };

                Algorithms.GradientFill(CellSize, new Point(_x, 12), 10, 45, new Rectangle(0, 0, CellData.Width, CellData.Height), new ColorGradient(colors, colorStops), _cellData.SetForeground);
            };
            _animation.Instructions.AddLast(moveGradientInstruction);

            // Animation to clear the SadConsole text.
            _animation.Instructions.AddLast(new CodeInstruction()
            {
                CodeCallback = (i) => { _cellData.Fill(Color.Black, Color.Transparent, 0, null); i.IsFinished = true; }
            });

            // Animation for the logo text.
            var logoText = new ColorGradient(new Color[] { Color.Purple, Color.Yellow }, new float[] { 0.0f, 1f }).ToColoredString("[| Powered by SadConsole |]");

            logoText.SetEffect(new SadConsole.Effects.Fade()
            {
                DestinationForeground = Color.Blue, FadeForeground = true, FadeDuration = 1f, Repeat = false, RemoveOnFinished = true, Permanent = true, CloneOnApply = true
            });
            _animation.Instructions.AddLast(new DrawString(this)
            {
                Position = new Point(26, this.CellData.Height - 1), Text = logoText, TotalTimeToPrint = 1f, UseConsolesCursorToPrint = false
            });

            // Animation for fading in the logo picture.
            _animation.Instructions.AddLast(new FadeCellRenderer(_consoleImage, new ColorGradient(Color.Black, Color.Transparent), new TimeSpan(0, 0, 0, 0, 2000)));

            // Animation to blink SadConsole in the logo text
            _animation.Instructions.AddLast(new CodeInstruction()
            {
                CodeCallback = (i) =>
                {
                    SadConsole.Effects.Fade fadeEffect = new SadConsole.Effects.Fade();
                    fadeEffect.AutoReverse             = true;
                    fadeEffect.DestinationForeground   = new ColorGradient(Color.Blue, Color.Yellow);
                    fadeEffect.FadeForeground          = true;
                    fadeEffect.Repeat       = true;
                    fadeEffect.FadeDuration = 0.7f;

                    List <Cell> cells = new List <Cell>();
                    for (int index = 0; index < 10; index++)
                    {
                        var point = new Point(26, this.CellData.Height - 1).ToIndex(this.CellData.Width) + 14 + index;
                        cells.Add(_cellData[point]);
                    }

                    _cellData.SetEffect(cells, fadeEffect);
                    i.IsFinished = true;
                }
            });

            // Animation to delay, keeping the logo and all on there for 2 seconds, then destroy itself.
            _animation.Instructions.AddLast(new Wait()
            {
                Duration = 2.5f
            });
            _animation.Instructions.AddLast(new FadeCellRenderer(this, new ColorGradient(Color.Transparent, Color.Black), new TimeSpan(0, 0, 0, 0, 2000)));
            _animation.Instructions.AddLast(new CodeInstruction()
            {
                CodeCallback = (i) =>
                {
                    if (this.Parent != null)
                    {
                        this.Parent.Remove(this);
                    }

                    if (SplashCompleted != null)
                    {
                        SplashCompleted();
                    }
                }
            });
        }