Example #1
0
        public ComponentManager(ContentManager contentManager, Microsoft.Xna.Framework.GraphicsDeviceManager graphicsDeviceManager)
        {
            _contentManager     = contentManager;
            _resourceRepository = new ResourceRepository(new BasicResourceRepositoryConfiguration(), _contentManager);

            Font = _resourceRepository.GetFont();
            _spaceShipTexture = _resourceRepository.GetTextureByType(typeof(SpaceShip));

            var graphicsDevice = graphicsDeviceManager.GraphicsDevice;

            Configuration = new BasicGameConfiguration(
                _spaceShipTexture.Height,
                Font
                );

            graphicsDeviceManager.PreferredBackBufferWidth  = Configuration.ScreenSize.Width;
            graphicsDeviceManager.PreferredBackBufferHeight = Configuration.ScreenSize.Height;
            graphicsDeviceManager.ApplyChanges();

            SpaceShip      = new SpaceShip(Configuration, new Size(_spaceShipTexture.Width, _spaceShipTexture.Height));
            _ballTexture   = _resourceRepository.GetTextureByType(typeof(BasicBall));
            BallRepository = new BallRepository(Configuration, new Size(_ballTexture.Width, _ballTexture.Height));

            Balls = new List <IBall>();

            _drawer = new ComponentDrawer(graphicsDevice, Font);

            Prizes = new List <IPrize>();
            Shoots = new List <IShoot>();

            MediaPlayer.Volume = .03f;
        }
Example #2
0
 /// <summary>
 /// Toggles whether or not the game window renders in fullscreen or windowed mode
 /// </summary>
 /// <param name="shouldApplyChanges">Whether or not to apply the graphics changes immediately.</param>
 public void ToggleFullscreen(bool shouldApplyChanges = true)
 {
     GraphicsDeviceManager.ToggleFullScreen();
     if (shouldApplyChanges)
     {
         GraphicsDeviceManager.ApplyChanges();
     }
 }
Example #3
0
 public void InitGraphicsDevice(
     Microsoft.Xna.Framework.GraphicsDeviceManager manager,
     Microsoft.Xna.Framework.Graphics.GraphicsDevice device)
 {
     manager.PreferredBackBufferWidth  = _windowWidth;
     manager.PreferredBackBufferHeight = _windowHeight;
     manager.IsFullScreen             = _fullScreen;
     manager.PreferMultiSampling      = _preferMultiSampling;
     manager.PreparingDeviceSettings += OnPreparingDeviceSettings;
     manager.ApplyChanges();
 }
Example #4
0
        // Initialize all graphics properties.
        public void Initialize(XnaGraphicsDeviceManager xnaGraphics)
        {
            if (null != _graphics)
            {
                return;
            }

            _graphics = xnaGraphics;
            _graphics.PreferredBackBufferWidth = 800;
            _graphics.PreferredBackBufferHeight = 600;
            _graphics.IsFullScreen = false;
            _graphics.ApplyChanges();

            GraphicsDevice = _graphics.GraphicsDevice;
            SpriteBatch = new SpriteBatch(GraphicsDevice);
        }
Example #5
0
        // Initialize all graphics properties.
        public void Initialize(XnaGraphicsDeviceManager xnaGraphics)
        {
            if (null != _graphics)
            {
                return;
            }

            _graphics = xnaGraphics;
            _graphics.PreferredBackBufferWidth  = 800;
            _graphics.PreferredBackBufferHeight = 600;
            _graphics.IsFullScreen = false;
            _graphics.ApplyChanges();

            GraphicsDevice = _graphics.GraphicsDevice;
            SpriteBatch    = new SpriteBatch(GraphicsDevice);
        }
Example #6
0
        private void InternalSetupVideoSettings(int windowWidth, int windowHeight, bool?fullscreen = null, bool?vsync = null, float?pixelScale = null)
        {
            bool hasPresentingSettingsChanged = false,
                 hasViewSettingsChanged       = false;

            Microsoft.Xna.Framework.GraphicsDeviceManager graphics = XNAGameWrapper.GraphicsDeviceManager;

            if (fullscreen.HasValue && graphics.IsFullScreen != fullscreen.Value)
            {
                BeforeSwitchingFullscreen(fullscreen.Value);
                graphics.IsFullScreen        = fullscreen.Value;
                hasPresentingSettingsChanged = true;
            }

            windowWidth  = (int)Math.Max(windowWidth, WindowMinimumSize.Width);
            windowHeight = (int)Math.Max(windowHeight, WindowMinimumSize.Height);

            if (graphics.PreferredBackBufferWidth != windowWidth)
            {
                graphics.PreferredBackBufferWidth = windowWidth;
                hasPresentingSettingsChanged      = true;
            }

            if (graphics.PreferredBackBufferHeight != windowHeight)
            {
                graphics.PreferredBackBufferHeight = windowHeight;
                hasPresentingSettingsChanged       = true;
            }

            if (vsync.HasValue && graphics.SynchronizeWithVerticalRetrace != vsync.Value)
            {
                graphics.SynchronizeWithVerticalRetrace = vsync.Value;
                hasPresentingSettingsChanged            = true;
            }

            if (pixelScale.HasValue)
            {
                float scale = pixelScale.Value <= Math.Epsilon ? Math.Epsilon : pixelScale.Value;

                if (_pixelScale != scale)
                {
                    _pixelScale            = scale;
                    hasViewSettingsChanged = true;
                }
            }

            if (NextResizeMode == ResizeMode.KeepProportions && (_nextInternalWidth != Width || _nextInternalHeight != Height))
            {
                hasViewSettingsChanged = true;
            }

            if (!hasPresentingSettingsChanged)
            {
                if (hasViewSettingsChanged || NextResizeMode != ResizeMode)
                {
                    RefreshViewMode(NextResizeMode, PixelScale);
                }

                return;
            }

            graphics.ApplyChanges();
        }
Example #7
0
 /// <summary>
 /// Applies pending changes to the <see cref="Microsoft.Xna.Framework.GraphicsDeviceManager"/>.
 /// </summary>
 public void ApplyChanges()
 {
     GraphicsDeviceManager.ApplyChanges();
 }
Example #8
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));
        }