Пример #1
0
 public override void Draw(Camera cam, Microsoft.Xna.Framework.Graphics.Effect effect, Microsoft.Xna.Framework.GameTime gameTime)
 {
     if (!this.Enabled)
     {
         return;
     }
 }
Пример #2
0
 /// <summary>
 /// Creates a TextComponent with a filepath to a compiled <see cref="Microsoft.Xna.Framework.Graphics.SpriteFont"/> content file.
 /// </summary>
 /// <param name="fontPath">File path to a compiled <see cref="Microsoft.Xna.Framework.Graphics.SpriteFont"/> content file.</param>
 /// <param name="color">Color for each glyph to be drawn with.</param>
 /// <param name="shader">Shader used for rendering in a <see cref="Microsoft.Xna.Framework.Graphics.SpriteBatch"/>.</param>
 /// <param name="text">Text message to be rendered.</param>
 public TextComponent(string fontPath, Color color, Effect shader, string text = null) : base(true, null)
 {
     Color    = color;
     FontPath = fontPath;
     Shader   = shader;
     Text     = text;
 }
Пример #3
0
 /// <summary>
 /// Creates a TextComponent with a given <see cref="Microsoft.Xna.Framework.Graphics.SpriteFont"/>.
 /// </summary>
 /// <param name="font">SpriteFont reference containing the raw font data.</param>
 /// <param name="color">Color for each glyph to be drawn with.</param>
 /// <param name="shader">Shader used for rendering in a <see cref="Microsoft.Xna.Framework.Graphics.SpriteBatch"/>.</param>
 /// <param name="text">Text message to be rendered.</param>
 public TextComponent(SpriteFont font, Color color, Effect shader, string text = null) : base(true, null)
 {
     Color    = color;
     Font     = font;
     FontPath = null;
     Shader   = shader;
     Text     = text;
 }
Пример #4
0
        protected override void OnLoadContent()
        {
            Input.Define("left", Keys.A, Keys.Left);
            Input.Define("left", Buttons.DPadLeft);

            Input.Define("right", Keys.D, Keys.Right);
            Input.Define("right", Buttons.DPadRight);

            Input.Define("up", Keys.W, Keys.Up);
            Input.Define("up", Buttons.DPadUp);

            Input.Define("down", Keys.S, Keys.Down);
            Input.Define("down", Buttons.DPadDown);

            Input.Define("a", Keys.Z, Keys.N);
            Input.Define("a", Buttons.A);

            Input.Define("b", Keys.X, Keys.M);
            Input.Define("b", Buttons.B);

            Input.Define("start", Keys.Enter, Keys.Space);
            Input.Define("start", Buttons.Start);

            Input.Define("back", Keys.Escape);
            Input.Define("back", Buttons.Back);

//#if DEBUG
            Input.Define("reset", Keys.R);
            Input.Define("debug_1", Keys.D1);
            Input.Define("debug_2", Keys.D2);
            Input.Define("debug_3", Keys.D3);
            Input.Define("debug_4", Keys.D4);
            Input.Define("debug_5", Keys.D5);
            Input.Define("debug_6", Keys.D6);
            Input.Define("debug_7", Keys.D7);
            Input.Define("debug_8", Keys.D8);
            Input.Define("debug_9", Keys.D9);
            Input.Define("debug_10", Keys.D0);
//#endif

            Asset.AddPixelMask("circle_small", "mask/circle_small");
            Asset.AddPixelMask("circle_big", "mask/circle_big");

            EntityData.Init();
            DungeonData.Init();

            CrtEffect = Asset.LoadEffect("effects/CRT-easymode");
            CrtEffect.Parameters["InputSize"].SetValue(new Vector2(Width, Height));
            if (Global.CrtEnabled)
            {
                PostProcessor = CrtEffect;
            }
        }
Пример #5
0
 public override void Draw(Camera cam, Microsoft.Xna.Framework.Graphics.Effect effect, GameTime gameTime)
 {
     //Do nothing, we do not expect to draw something as abstract as physical object component
 }
Пример #6
0
 public override void Draw(Camera cam, Microsoft.Xna.Framework.Graphics.Effect effect, Microsoft.Xna.Framework.GameTime gameTime)
 {
 }
Пример #7
0
        public override void Render(DwarfTime gameTime, ChunkManager chunks, Camera camera, Microsoft.Xna.Framework.Graphics.SpriteBatch spriteBatch, Microsoft.Xna.Framework.Graphics.GraphicsDevice graphicsDevice, Microsoft.Xna.Framework.Graphics.Effect effect, bool renderingForWater)
        {
            if (GUIObject != null)
            {
                if (Enabled && IsVisible && camera.IsInView(GetBoundingBox()))
                {
                    Vector3 screenPos = camera.Project(GlobalTransform.Translation);
                    GUIObject.LocalBounds = new Rectangle((int)screenPos.X - GUIObject.LocalBounds.Width / 2,
                                                          (int)screenPos.Y - GUIObject.LocalBounds.Height / 2, GUIObject.LocalBounds.Width,
                                                          GUIObject.LocalBounds.Height);

                    GUIObject.IsVisible = true;
                }
                else
                {
                    GUIObject.IsVisible = false;
                }
            }
            base.Render(gameTime, chunks, camera, spriteBatch, graphicsDevice, effect, renderingForWater);
        }
Пример #8
0
        /// <summary>
        /// Renders the given <see cref="Komodo.Core.ECS.Components.Drawable2DComponent"/> objects.
        /// </summary>
        /// <param name="components"><see cref="Komodo.Core.ECS.Components.Drawable2DComponent"/> objects to render.</param>
        /// <param name="spriteBatch"><see cref="Microsoft.Xna.Framework.Graphics.SpriteBatch"/> to render with.</param>
        /// <param name="drawBillboards">Whether or not to billboard the <see cref="Komodo.Core.ECS.Components.Drawable2DComponent"/>.</param>
        /// <param name="shader">Shader to render with.</param>
        private void DrawComponents(
            [NotNull] IEnumerable <Drawable2DComponent> components,
            [NotNull] SpriteBatch spriteBatch,
            bool drawBillboards = false,
            Effect shader       = null
            )
        {
            var oldViewMatrix  = Matrix.Identity;
            var oldWorldMatrix = Matrix.Identity;

            switch (shader)
            {
            case BasicEffect effect:
                oldViewMatrix  = effect.View;
                oldWorldMatrix = effect.World;
                break;

            case SpriteEffect _:
            case null:
            default:
                break;
            }
            try
            {
                switch (shader)
                {
                case BasicEffect effect:
                    effect.Projection = ActiveCamera != null ? ActiveCamera.Projection : Matrix.Identity;

                    if (drawBillboards)
                    {
                        effect.View = Matrix.Identity;
                    }
                    else
                    {
                        effect.View = ActiveCamera != null ? ActiveCamera.ViewMatrix : Matrix.Identity;
                    }
                    if (ActiveCamera != null && ActiveCamera.IsPerspective)
                    {
                        effect.World = Matrix.CreateScale(1f, -1f, 1f);
                    }
                    else
                    {
                        effect.World = Matrix.CreateScale(1f, 1f, 1f);
                    }
                    break;

                case SpriteEffect _:
                case null:
                default:
                    break;
                }
                spriteBatch.Begin(
                    SpriteSortMode.FrontToBack,
                    null,
                    TextureFilter,
                    DepthStencilState.DepthRead,
                    RasterizerState.CullNone,
                    shader
                    );
                foreach (var component in components)
                {
                    if (component.IsEnabled && component.Parent != null && component.Parent.IsEnabled && component.IsBillboard == drawBillboards)
                    {
                        DrawComponent(component, spriteBatch);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.ToString());
            }
            finally
            {
                spriteBatch.End();
                switch (shader)
                {
                case BasicEffect effect:
                    effect.View  = oldViewMatrix;
                    effect.World = oldWorldMatrix;
                    break;

                case SpriteEffect _:
                case null:
                default:
                    break;
                }
            }
        }
Пример #9
0
 /// <summary>
 /// Creates a SpriteComponent with a filepath to a compiled <see cref="Microsoft.Xna.Framework.Graphics.Texture2D"/> content file.
 /// </summary>
 /// <remarks>
 /// The <see cref="Microsoft.Xna.Framework.Graphics.Texture2D"/> will be loaded from disk once the relevant <see cref="Komodo.Core.ECS.Systems.Render2DSystem.Initialize"/>, <see cref="Komodo.Core.ECS.Systems.Render2DSystem.PreUpdate"/>, or <see cref="Komodo.Core.ECS.Systems.Render2DSystem.PostUpdate"/> is called.
 /// </remarks>
 /// <param name="texturePath">File path to a compiled <see cref="Microsoft.Xna.Framework.Graphics.Model"/> content file.</param>
 /// <param name="shader">Shader used for rendering in a <see cref="Microsoft.Xna.Framework.Graphics.SpriteBatch"/>.</param>
 public SpriteComponent(string texturePath, Effect shader) : base(true, null)
 {
     Shader      = shader;
     TexturePath = texturePath;
 }
Пример #10
0
 /// <summary>
 /// Creates a SpriteComponent with a given <see cref="Komodo.Core.Engine.Graphics.Texture"/>.
 /// </summary>
 /// <param name="texture">Texture reference containing the raw texture data.</param>
 /// <param name="shader">Shader used for rendering in a <see cref="Microsoft.Xna.Framework.Graphics.SpriteBatch"/>.</param>
 public SpriteComponent(Engine.Graphics.Texture texture, Effect shader) : base(true, null)
 {
     Shader      = shader;
     Texture     = texture;
     TexturePath = null;
 }
Пример #11
0
        /// <summary>
        /// Setup the game properties
        /// </summary>
        /// <param name="contentManager">the XNA content manager to be used</param>
        /// <param name="graphicDeviceManager">the XNA graphic manager to be used</param>
        public GameProperties(Microsoft.Xna.Framework.Content.ContentManager contentManager, Microsoft.Xna.Framework.GraphicsDeviceManager graphicDeviceManager, Microsoft.Xna.Framework.GameWindow window)
        {
            // load game properties
            System.Xml.XmlDocument config = new System.Xml.XmlDocument();
            config.Load(@"Content/config.xml");

            // try resolution
            try
            {
                graphicDeviceManager.PreferredBackBufferWidth  = Convert.ToInt32(config.GetElementsByTagName("resolutionX")[0].InnerText);
                graphicDeviceManager.PreferredBackBufferHeight = Convert.ToInt32(config.GetElementsByTagName("resolutionY")[0].InnerText);
                Screen screen = Screen.PrimaryScreen;
                window.Position = new Microsoft.Xna.Framework.Point(screen.Bounds.Width / 2 - graphicDeviceManager.PreferredBackBufferWidth / 2, screen.Bounds.Height / 2 - graphicDeviceManager.PreferredBackBufferHeight / 2);
            }
            catch (Exception)
            {
                graphicDeviceManager.PreferredBackBufferWidth  = 1280;
                graphicDeviceManager.PreferredBackBufferHeight = 720;
            }


            // try fullscreen
            try
            {
                int fullscreen = Convert.ToInt32(config.GetElementsByTagName("fullscreen")[0].InnerText);
                if (fullscreen == 1)
                {
                    Screen screen = Screen.PrimaryScreen;
                    window.IsBorderless = true;
                    window.Position     = new Microsoft.Xna.Framework.Point(screen.Bounds.X, screen.Bounds.Y);
                    graphicDeviceManager.PreferredBackBufferWidth  = screen.Bounds.Width;
                    graphicDeviceManager.PreferredBackBufferHeight = screen.Bounds.Height;
                    this.isFullscreen = true;
                }
                else
                {
                    this.isFullscreen = false;
                }
            }
            catch (Exception) { }

            graphicDeviceManager.ApplyChanges();

            // try language settings
            try
            {
                this.SelectedLanguage = config.GetElementsByTagName("language")[0].InnerText;
            }
            catch (Exception) { }


            this.currentGameState = GameState.LoadMenu;
            this.input            = new InputHandler();

            this.contentManager       = new Helper.ContentManager(contentManager);
            this.spriteBatch          = new Microsoft.Xna.Framework.Graphics.SpriteBatch(graphicDeviceManager.GraphicsDevice);
            this.graphicDeviceManager = graphicDeviceManager;
            this.gameWindow           = window;

            System.IO.BinaryReader Reader = new System.IO.BinaryReader(System.IO.File.Open(@"Content\Shader\main_shader.mgfxo", System.IO.FileMode.Open));
            this.baseShader = new Microsoft.Xna.Framework.Graphics.Effect(this.graphicDeviceManager.GraphicsDevice, Reader.ReadBytes((int)Reader.BaseStream.Length));
        }
Пример #12
0
        /// <summary>
        /// Setup the game properties
        /// </summary>
        /// <param name="contentManager">the XNA content manager to be used</param>
        /// <param name="graphicDeviceManager">the XNA graphic manager to be used</param>
        public GameProperties(Microsoft.Xna.Framework.Content.ContentManager contentManager, Microsoft.Xna.Framework.GraphicsDeviceManager graphicDeviceManager, Microsoft.Xna.Framework.GameWindow window)
        {
            // load game properties
            System.Xml.XmlDocument config = new System.Xml.XmlDocument();
            config.Load(@"Content/config.xml");

            // try resolution
            try
            {
                graphicDeviceManager.PreferredBackBufferWidth = Convert.ToInt32(config.GetElementsByTagName("resolutionX")[0].InnerText);
                graphicDeviceManager.PreferredBackBufferHeight = Convert.ToInt32(config.GetElementsByTagName("resolutionY")[0].InnerText);
                Screen screen = Screen.PrimaryScreen;
                window.Position = new Microsoft.Xna.Framework.Point(screen.Bounds.Width / 2 - graphicDeviceManager.PreferredBackBufferWidth / 2, screen.Bounds.Height / 2 - graphicDeviceManager.PreferredBackBufferHeight / 2);
            }
            catch (Exception)
            {
                graphicDeviceManager.PreferredBackBufferWidth = 1280;
                graphicDeviceManager.PreferredBackBufferHeight = 720;
            }

            // try fullscreen
            try
            {
                int fullscreen = Convert.ToInt32(config.GetElementsByTagName("fullscreen")[0].InnerText);
                if (fullscreen == 1)
                {
                    Screen screen = Screen.PrimaryScreen;
                    window.IsBorderless = true;
                    window.Position = new Microsoft.Xna.Framework.Point(screen.Bounds.X, screen.Bounds.Y);
                    graphicDeviceManager.PreferredBackBufferWidth = screen.Bounds.Width;
                    graphicDeviceManager.PreferredBackBufferHeight = screen.Bounds.Height;
                    this.isFullscreen = true;
                }
                else
                {
                    this.isFullscreen = false;
                }
            }
            catch (Exception) { }

            graphicDeviceManager.ApplyChanges();

            // try language settings
            try
            {
                this.SelectedLanguage = config.GetElementsByTagName("language")[0].InnerText;
            }
            catch(Exception){ }

            this.currentGameState = GameState.LoadMenu;
            this.input = new InputHandler();

            this.contentManager = new Helper.ContentManager(contentManager);
            this.spriteBatch = new Microsoft.Xna.Framework.Graphics.SpriteBatch(graphicDeviceManager.GraphicsDevice);
            this.graphicDeviceManager = graphicDeviceManager;
            this.gameWindow = window;

            System.IO.BinaryReader Reader = new System.IO.BinaryReader(System.IO.File.Open(@"Content\Shader\main_shader.mgfxo", System.IO.FileMode.Open));
            this.baseShader = new Microsoft.Xna.Framework.Graphics.Effect(this.graphicDeviceManager.GraphicsDevice, Reader.ReadBytes((int)Reader.BaseStream.Length));
        }