protected override void Initialize()
        {
            base.Initialize();

            // the default viewport adapater is the simplest, it doesn't do any scaling at all
            // but is used by a Camera2D if no other adapter is specified.
            // this is often useful if you have a game with a large map and you want the player to see 
            // more of the map on a bigger screen.
            _defaultViewportAdapter = new DefaultViewportAdapter(GraphicsDevice);

            // the scaling viewport adapter stretches the output to fit in the viewport, ignoring the aspect ratio
            // this works well if the aspect ratio doesn't change a lot between devices 
            // or you don't like the black bars of the boxing adapter
            _scalingViewportAdapter = new ScalingViewportAdapter(GraphicsDevice, 800, 480);

            // the boxing viewport adapter uses letterboxing or pillarboxing to maintain aspect ratio
            // it's a little more complicated and needs to listen to the window client size changing event
            _boxingViewportAdapter = new BoxingViewportAdapter(GraphicsDevice, 800, 480);

            Window.ClientSizeChanged += (s, e) => _currentViewportAdapter.OnClientSizeChanged(); 
            
            // typically you'll only ever want to use one viewport adapter for a game, but in this sample we'll be 
            // switching between them.
            _currentViewportAdapter = _boxingViewportAdapter;
        }
        protected override void Update(GameTime gameTime)
        {
            var keyboardState = Keyboard.GetState();
            var mouseState = Mouse.GetState();
            var previousViewportAdapter = _currentViewportAdapter;

            if (keyboardState.IsKeyDown(Keys.Escape))
                Exit();

            if (keyboardState.IsKeyDown(Keys.D))
                _currentViewportAdapter = _defaultViewportAdapter;

            if (keyboardState.IsKeyDown(Keys.S))
                _currentViewportAdapter = _scalingViewportAdapter;

            if (keyboardState.IsKeyDown(Keys.B))
                _currentViewportAdapter = _boxingViewportAdapter;

            // if we've changed the viewport adapter mid game we need to reset the viewport back to the window size
            // this wouldn't normally be required if you're only ever using one viewport adapter
            if (previousViewportAdapter != _currentViewportAdapter)
            {
                GraphicsDevice.Viewport = new Viewport(0, 0, Window.ClientBounds.Width, Window.ClientBounds.Height);
                _currentViewportAdapter.OnClientSizeChanged();
            }

            // the viewport adapters can also scale mouse and touch input to the virtual resolution
            _mousePosition = _currentViewportAdapter.PointToScreen(mouseState.X, mouseState.Y);

            base.Update(gameTime);
        }
示例#3
0
        //protected override void Initialize()
        //{
        //    base.Initialize();

        //    _graphicsDeviceManager.IsFullScreen = true;
        //    _graphicsDeviceManager.PreferredBackBufferWidth = GraphicsDevice.DisplayMode.Width;
        //    _graphicsDeviceManager.PreferredBackBufferHeight = GraphicsDevice.DisplayMode.Height;
        //    _graphicsDeviceManager.ApplyChanges();
        //}

        protected override void LoadContent()
        {
            _viewportAdapter = new BoxingViewportAdapter(Window, GraphicsDevice, 800, 480);
            _font = Content.Load<BitmapFont>("Fonts/courier-new-32");

            _camera = new Camera2D(_viewportAdapter);
            _explosionAnimations = Content.Load<SpriteSheetAnimationGroup>("explosion-animations");

            _spriteBatch = new SpriteBatch(GraphicsDevice);

            _backgroundTexture = Content.Load<Texture2D>("black");

            var bulletTexture = Content.Load<Texture2D>("laserBlue03");
            var bulletRegion = new TextureRegion2D(bulletTexture);
            _bulletFactory = new BulletFactory(_entityManager, bulletRegion);

            SpawnPlayer(_bulletFactory);

            _meteorFactory = new MeteorFactory(_entityManager, Content);

            for (var i = 0; i < 13; i++)
            {
                _meteorFactory.SpawnNewMeteor(_player.Position);
            }
        }
        public Camera2D(ViewportAdapter viewportAdapter)
        {
            _viewportAdapter = viewportAdapter;

            Rotation = 0;
            Zoom = 1;
            Origin = new Vector2(viewportAdapter.VirtualWidth / 2f, viewportAdapter.VirtualHeight / 2f);
            Position = Vector2.Zero;
        }
示例#5
0
        protected override void LoadContent()
        {
            _viewportAdapter = new BoxingViewportAdapter(Window, GraphicsDevice, 800, 480);
            _camera = new Camera2D(_viewportAdapter);
            _backgroundTexture = Content.Load<Texture2D>("vignette");
            _bitmapFont = Content.Load<BitmapFont>("montserrat-32");

            _spriteBatch = new SpriteBatch(GraphicsDevice);
        }
 public override void Draw(SpriteBatch spriteBatch, ViewportAdapter viewportAdapter)
 {
     var screenSize = SceneManager.Instance.VirtualSize;
     var screenRect = new Rectangle(0, 0, (int)screenSize.X, (int)screenSize.Y);
     spriteBatch.Begin(transformMatrix: SceneManager.Instance.ViewportAdapter.GetScaleMatrix(), samplerState: SamplerState.PointClamp);
     spriteBatch.Draw(_backgroundTexture, screenRect, Color.White);
     spriteBatch.Draw(_creditsTexture, _creditsPosition, Color.White);
     spriteBatch.Draw(_fadeOutTexture, screenRect, Color.White * _fadeOutAlpha);
     base.Draw(spriteBatch, viewportAdapter);
     spriteBatch.End();
 }
示例#7
0
 protected override void LoadContent()
 {
     _viewportAdapter = new BoxingViewportAdapter(GraphicsDevice, 800, 480);
     _camera = new Camera2D(_viewportAdapter);
     _spriteBatch = new SpriteBatch(GraphicsDevice);
     _texture = Content.Load<Texture2D>("monogame-extended-logo");
     _sprite = new Sprite(_texture)
     {
         Position = new Vector2(400, 240)
     };
 }
示例#8
0
        protected override void Initialize()
        {
            _viewportAdapter = new BoxingViewportAdapter(Window, GraphicsDevice, 800, 480);
            _camera = new Camera2D(_viewportAdapter);

            Window.AllowUserResizing = true;
            Window.Position = Point.Zero;

            Components.Add(_fpsCounter = new FramesPerSecondCounterComponent(this));

            base.Initialize();
        }
 internal MouseEventArgs(ViewportAdapter viewportAdapter, TimeSpan time, MouseState previousState, MouseState currentState, 
     MouseButton button = MouseButton.None)
 {
     PreviousState = previousState;
     CurrentState = currentState;
     Position = viewportAdapter != null
         ? viewportAdapter.PointToScreen(currentState.X, currentState.Y)
         : new Point(currentState.X, currentState.Y); 
     Button = button;
     ScrollWheelValue = currentState.ScrollWheelValue;
     ScrollWheelDelta = currentState.ScrollWheelValue - previousState.ScrollWheelValue;
     Time = time;
 }
示例#10
0
        public GuiManager(ViewportAdapter viewportAdapter, GraphicsDevice graphicsDevice)
        {
            Layout = new GuiGridLayout();

            _viewportAdapter = viewportAdapter;
            _inputManager = new InputListenerManager(viewportAdapter);
            _spriteBatch = new SpriteBatch(graphicsDevice);

            var mouseListener = _inputManager.AddListener<MouseListener>();
            mouseListener.MouseMoved += OnMouseMoved;
            mouseListener.MouseDown += (sender, args) => Layout.OnMouseDown(this, args);
            mouseListener.MouseUp += (sender, args) => Layout.OnMouseUp(this, args);
        }
示例#11
0
        //protected override void Initialize()
        //{
        //    base.Initialize();

        //    _graphicsDeviceManager.IsFullScreen = true;
        //    _graphicsDeviceManager.PreferredBackBufferWidth = GraphicsDevice.DisplayMode.Width;
        //    _graphicsDeviceManager.PreferredBackBufferHeight = GraphicsDevice.DisplayMode.Height;
        //    _graphicsDeviceManager.ApplyChanges();
        //}

        protected override void LoadContent()
        {
            _viewportAdapter = new BoxingViewportAdapter(Window, GraphicsDevice, 800, 480);
            _guiManager = new GuiManager(_viewportAdapter, GraphicsDevice);
            _font = Content.Load<BitmapFont>("Fonts/courier-new-32");

            var normal = new GuiTextureRegionDrawable(new TextureRegion2D(Content.Load<Texture2D>("Gui/button-normal")));
            var pressed = new GuiTextureRegionDrawable(new TextureRegion2D(Content.Load<Texture2D>("Gui/button-clicked")));
            var hover = new GuiTextureRegionDrawable(new TextureRegion2D(Content.Load<Texture2D>("Gui/button-hover")));
            var buttonStyle = new GuiButtonStyle(normal, pressed, hover);
            var button = new GuiButton(buttonStyle)
            {
                Position = new Vector2(400, 240)
            };
            button.Clicked += (sender, args) =>
            {
                if (_player != null)
                {
                    Explode(_player.Position, 3);
                    _player.Destroy();
                    _player = null;
                }
            };
            _guiManager.Controls.Add(button);

            var labelStyle = new GuiLabelStyle(_font);
            var label = new GuiLabel(labelStyle, "Hello")
            {
                Position = new Vector2(100, 100)
            };
            label.MouseUp += (sender, args) => label.Text = args.Position.ToString();
            _guiManager.Controls.Add(label);
            
            _camera = new Camera2D(_viewportAdapter);
            _explosionAnimations = Content.Load<SpriteSheetAnimationGroup>("explosion-animations");

            _spriteBatch = new SpriteBatch(GraphicsDevice);

            _backgroundTexture = Content.Load<Texture2D>("black");

            var bulletTexture = Content.Load<Texture2D>("laserBlue03");
            var bulletRegion = new TextureRegion2D(bulletTexture);
            _bulletFactory = new BulletFactory(_entityManager, bulletRegion);

            SpawnPlayer(_bulletFactory);

            _meteorFactory = new MeteorFactory(_entityManager, Content);

            for (var i = 0; i < 13; i++)
                _meteorFactory.SpawnNewMeteor(_player.Position);
        }
示例#12
0
        protected override void Initialize()
        {
            _fpsCounter = new FramesPerSecondCounter();
            _viewportAdapter = new BoxingViewportAdapter(Window, GraphicsDevice, 800, 480);
            _camera = new Camera2D(_viewportAdapter);
            //{
            //    MinimumZoom = 0.1f,
            //    MaximumZoom = 2.0f,
            //    Zoom = 0.7833337f,
            //    Origin = new Vector2(400, 240),
            //    Position = new Vector2(408, 270)
            //};

            Window.AllowUserResizing = true;

            base.Initialize();
        }
        protected override void Initialize()
        {
            _viewportAdapter = new BoxingViewportAdapter(GraphicsDevice, 800, 480);
            _camera = new Camera2D(_viewportAdapter)
            {
                //Zoom = 0.5f,
                Origin = new Vector2(400, 240),
                //Position = new Vector2(408, 270)
            };

            Window.AllowUserResizing = true;
            Window.ClientSizeChanged += (s, e) => _viewportAdapter.OnClientSizeChanged();
            
            SetUpInput();

            base.Initialize();
        }
示例#14
0
        protected override void Initialize()
        {
            _fpsCounter = new FramesPerSecondCounter();
            _viewportAdapter = new BoxingViewportAdapter(GraphicsDevice, 800, 480);
            _camera = new Camera2D(_viewportAdapter)
            {
                MinimumZoom = 0.5f,
                MaximumZoom = 2.0f,
                Zoom = 0.5f,
                Origin = new Vector2(400, 240),
                Position = new Vector2(408, 270)
            };

            Window.AllowUserResizing = true;
            Window.ClientSizeChanged += (s, e) => _viewportAdapter.OnClientSizeChanged();

            base.Initialize();
        }
示例#15
0
        protected override void Initialize()
        {
            _viewportAdapter = new BoxingViewportAdapter(Window, GraphicsDevice, 800, 480);
            _camera = new Camera2D(_viewportAdapter)
            {
                MinimumZoom = 0.1f,
                MaximumZoom = 2.0f,
                Zoom = 0.7833337f,
                Origin = new Vector2(400, 240),
                Position = new Vector2(408, 270)
            };

            Window.Title = $"MonoGame.Extended - {GetType().Name}";
            Window.Position = Point.Zero;
            Window.AllowUserResizing = true;

            base.Initialize();
        }
示例#16
0
        public GuiManager(ViewportAdapter viewportAdapter, GraphicsDevice graphicsDevice)
        {
            _viewportAdapter = viewportAdapter;
            _inputManager = new InputListenerManager(viewportAdapter);
            _spriteBatch = new SpriteBatch(graphicsDevice);

            Controls = new List<GuiControl>();

            var mouseListener = _inputManager.AddListener<MouseListener>();
            mouseListener.MouseMoved += (sender, args) =>
            {
                if (_focusedControl != null)
                    _focusedControl.OnMouseLeave(this, args);

                _focusedControl = FindFocusedControl(args.Position);

                if (_focusedControl != null)
                    _focusedControl.OnMouseEnter(this, args);

                DelegateMouseEvent(args, c => c.OnMouseMoved(this, args));
            };
            mouseListener.MouseDown += (sender, args) => DelegateMouseEvent(args, c => c.OnMouseDown(this, args));
            mouseListener.MouseUp += (sender, args) => DelegateMouseEvent(args, c => c.OnMouseUp(this, args));
        }
        public override void Draw(SpriteBatch spriteBatch, ViewportAdapter viewportAdapter)
        {
            base.Draw(spriteBatch, viewportAdapter);
            var debugMode = SceneManager.Instance.DebugMode;

            _backgroundHelper.Draw(_camera, spriteBatch);

            // Draw the map
            GameMap.Instance.Draw(_camera, spriteBatch);

            spriteBatch.Begin(transformMatrix: _camera.GetViewMatrix(), samplerState: SamplerState.PointClamp);

            // Draw the shops
            for (var i = 0; i < _shops.Count; i++)
            {
                _shops[i].Draw(spriteBatch);
            }

            // Draw the checkpoints
            for (var i = 0; i < _checkpoints.Count; i++)
            {
                _checkpoints[i].Draw(spriteBatch);
                if (debugMode) _checkpoints[i].DrawCollider(spriteBatch);
            }

            // Draw the coins
            for (var i = 0; i < _coins.Count; i++)
            {
                _coins[i].CoinSprite.Draw(spriteBatch);
                if (debugMode) _coins[i].CoinSprite.DrawCollider(spriteBatch);
            }

            // Draw the player
            _player.DrawCharacter(spriteBatch);
            _player.DrawHat(spriteBatch);
            if (debugMode) _player.DrawColliderBox(spriteBatch);

            // Draw the enemies
            foreach (var enemy in _enemies)
            {
                enemy.DrawCharacter(spriteBatch);
                if (debugMode) enemy.DrawColliderBox(spriteBatch);
                if (enemy is Boss)
                {
                    ((Boss)enemy).DrawInnerSprites(spriteBatch);
                }
            }

            // Draw the projectiles
            foreach (var projectile in _projectiles)
            {
                spriteBatch.Draw(projectile.Sprite);
                if (debugMode) spriteBatch.Draw(_projectilesColliderTexture, projectile.BoundingBox, Color.White * 0.5f);
            }

            // Draw the particles
            SceneManager.Instance.ParticleManager.Draw(spriteBatch);

            spriteBatch.End();

            spriteBatch.Begin(transformMatrix: SceneManager.Instance.ViewportAdapter.GetScaleMatrix(),
                samplerState: SamplerState.PointClamp);

            _player.DrawScreenFlash(spriteBatch);

            // Draw the Hud
            _gameHud.Draw(spriteBatch);

            // Draw the Boss Hud (if exists)
            ((Boss)_enemies.SingleOrDefault(enemy => enemy is Boss))?.Draw(spriteBatch);

            if (_stageCompleted)
                _stageCompletedHelper.Draw(spriteBatch);

            _pauseHelper.Draw(spriteBatch);

            spriteBatch.End();
        }
        public override void Draw(SpriteBatch spriteBatch, ViewportAdapter viewportAdapter)
        {
            base.Draw(spriteBatch, viewportAdapter);
            
            spriteBatch.Begin(samplerState: SamplerState.PointClamp, transformMatrix: viewportAdapter.GetScaleMatrix());

            // Background
            spriteBatch.Draw(_backgroundTexture, _backgroundTexture.Bounds, Color.White);

            // Strings
            DrawWithShadow(spriteBatch, PlayerManager.Instance.Ammo.ToString(), _ammoPosition);
            DrawWithShadow(spriteBatch, PlayerManager.Instance.Coins.ToString(), _coinsPosition);
            DrawWithShadow(spriteBatch, "HP", _hpTextPosition);
            DrawWithShadow(spriteBatch, "Lives", _livesTextPosition);

            // Hearts and lives
            DrawCenteredSpritesOnRectangle(spriteBatch, _hpSpritesArea, _heartSprite, PlayerManager.Instance.Hearts);
            DrawCenteredSpritesOnRectangle(spriteBatch, _livesSpritesArea, _lifeSprite, PlayerManager.Instance.Lives);
            
            for (var i = 0; i < GetCurrentStage(); i++)
            {
                var position = new Rectangle((int)_stageSelectionPositions[i].X, (int)_stageSelectionPositions[i].Y, 19, 19);
                spriteBatch.Draw(_stageSelectionSpritesheet, position, new Rectangle(76, 0, 19, 19), Color.White, 0f,
                    new Vector2(9, 9), SpriteEffects.None, 0f);
            }

            spriteBatch.DrawString(SceneManager.Instance.GameFont, MapPressMessage, _pressZTextPosition, _fontColor);
            
            // Map sprites
            _stageSelectionSprite.Draw(spriteBatch);
            _stageSelectionPeteSprite.Draw(spriteBatch);

            spriteBatch.End();
        }
        public override void Draw(SpriteBatch spriteBatch, ViewportAdapter viewportAdapter)
        {
            base.Draw(spriteBatch, viewportAdapter);

            var screenSize = SceneManager.Instance.VirtualSize;
            var gameFont = SceneManager.Instance.GameFont;

            spriteBatch.Begin(samplerState: SamplerState.PointClamp, transformMatrix: viewportAdapter.GetScaleMatrix());

            // Background
            spriteBatch.Draw(_backgroundTexture, _backgroundTexture.Bounds, Color.White);

            // Title
            var titleString = _titleStrings[SceneManager.Instance.TypeOfSceneSaves];
            var titleX = (SceneManager.Instance.VirtualSize.X - SceneManager.Instance.GameFontBig.MeasureString(titleString).X) / 2;
            spriteBatch.DrawTextWithShadow(SceneManager.Instance.GameFontBig, titleString, new Vector2(titleX, 10), Color.White);

            // Slots
            for (var i = 0; i < 3; i++)
            {
                var slotPosition = _slotsPosition[i].Location.ToVector2();

                // Check if the slot isn't empty
                if (_gameSaves[i].StagesCompleted > 0)
                {
                    // Pete Head
                    if (_slotIndex == i)
                    {
                        _peteAnimatedSprite.Position = slotPosition + _peteHeadPosition;
                        _peteAnimatedSprite.Draw(spriteBatch);
                    }
                    else
                    {
                        spriteBatch.Draw(_peteSpritesheet, slotPosition + _peteHeadPosition, _peteDefaultFrame, Color.White);
                    }

                    // Save Name
                    spriteBatch.DrawString(gameFont, "SAVE NAME", slotPosition + _namePosition, _fontColor);

                    // Stages
                    var divisorPosition = Vector2.Zero;
                    for (var j = 0; j < _gameSaves[i].StagesCompleted; j++)
                    {
                        var markPosition = slotPosition + _stagesPosition + ((_stagePeteMarkFrame.Width + 4) * j * Vector2.UnitX);
                        spriteBatch.Draw(_stageSpritesheet, markPosition, _stagePeteMarkFrame, Color.White);
                        if (j < SceneManager.MaxLevels - 1)
                        {
                            divisorPosition = markPosition + (_stagePeteMarkFrame.Width + 1) * Vector2.UnitX + (9 * Vector2.UnitY);
                            spriteBatch.Draw(_stageSpritesheet, divisorPosition, _stageDivisorFrame, Color.White);
                        }
                    }

                    if (_gameSaves[i].StagesCompleted < SceneManager.MaxLevels)
                    {
                        var nextMarkPos = (divisorPosition == Vector2.Zero) ? (slotPosition + _stagesPosition) : (divisorPosition - (9 * Vector2.UnitY) + (3 * Vector2.UnitX));
                        if (_slotIndex == i)
                        {
                            _nextStageMarkAnimatedSprite.Position = nextMarkPos;
                            _nextStageMarkAnimatedSprite.Draw(spriteBatch);
                        }
                        else
                        {
                            spriteBatch.Draw(_stageSpritesheet, nextMarkPos, _stageNextMarkFrame, Color.White);
                        }
                    }

                    // Lives
                    var lives = _gameSaves[i].Lives;
                    var livesWidth = (lives * _lifeFrame.Width) + (lives - 1);
                    var livesPosition = slotPosition + (_slotsPosition[i].Width - livesWidth - _livesPosition.X) * Vector2.UnitX + _livesPosition.Y * Vector2.UnitY;
                    for (var j = 0; j < lives; j++)
                    {
                        var lifePosition = livesPosition + ((_lifeFrame.Width + 1) * j * Vector2.UnitX);
                        spriteBatch.Draw(_iconsSpritesheet, lifePosition, _lifeFrame, Color.White);
                    }

                    // Hearts
                    var hearts = _gameSaves[i].Hearts;
                    var heartsWidth = (hearts * _heartFrame.Width) + (hearts - 1) * 5;
                    var heartsPosition = slotPosition + (_slotsPosition[i].Width - heartsWidth - _heartsPosition.X) * Vector2.UnitX + _heartsPosition.Y * Vector2.UnitY;
                    for (var j = 0; j < hearts; j++)
                    {
                        var heartPosition = heartsPosition + ((_heartFrame.Width + 5) * j * Vector2.UnitX);
                        spriteBatch.Draw(_iconsSpritesheet, heartPosition, _heartFrame, Color.White);
                    }

                    // Ammo
                    spriteBatch.Draw(_iconsSpritesheet, slotPosition + _ammoPosition, _ammoFrame, Color.White);
                    spriteBatch.DrawString(gameFont, _gameSaves[i].Ammo.ToString(), slotPosition + _ammoTextPosition, _fontColor);

                    // Coins
                    spriteBatch.Draw(_iconsSpritesheet, slotPosition + _coinsPosition, _coinFrame, Color.White);
                    spriteBatch.DrawString(gameFont, _gameSaves[i].Coins.ToString(), slotPosition + _coinsTextPosition, _fontColor);
                }
                else
                {
                    // Empty slot text
                    var emptySlotTextSize = gameFont.MeasureString(EmptySlotText);
                    var emptyPosition = new Vector2(slotPosition.X + (_slotsPosition[i].Width - emptySlotTextSize.X) / 2,
                        slotPosition.Y + (_slotsPosition[i].Height - emptySlotTextSize.Y) / 2);
                    spriteBatch.DrawString(gameFont, EmptySlotText, emptyPosition, _fontColor);
                }
            }

            IconsManager.Instance.DrawRightArrow(spriteBatch, _arrowPosition + _arrowPositionInc * Vector2.UnitY, false);

            var xOffset = SceneManager.Instance.GameFontSmall.MeasureString(ConfirmButtonLabel).X + 30;
            IconsManager.Instance.DrawActionButton(spriteBatch, new Vector2(5, screenSize.Y - 18), false, ConfirmButtonLabel, 1.0f, true);
            IconsManager.Instance.DrawCancelButton(spriteBatch, new Vector2(xOffset, screenSize.Y - 18), false, CancelButtonLabel, 1.0f, true);

            if (_loadingVisible)
            {
                spriteBatch.Draw(_loadingBackgroundTexture, new Rectangle(0, 0, (int)screenSize.X, (int)screenSize.Y),
                    Color.White * 0.5f);
                _loadingAnimatedSprite.Draw(spriteBatch);
            }

            spriteBatch.End();
        }
示例#20
0
        //protected override void Initialize()
        //{
        //    base.Initialize();

        //    _graphicsDeviceManager.IsFullScreen = true;
        //    _graphicsDeviceManager.PreferredBackBufferWidth = GraphicsDevice.DisplayMode.Width;
        //    _graphicsDeviceManager.PreferredBackBufferHeight = GraphicsDevice.DisplayMode.Height;
        //    _graphicsDeviceManager.ApplyChanges();
        //}

        protected override void LoadContent()
        {
            _viewportAdapter = new BoxingViewportAdapter(Window, GraphicsDevice, 800, 480);
            _guiManager = new GuiManager(_viewportAdapter, GraphicsDevice);
            _font = Content.Load<BitmapFont>("Fonts/courier-new-32");

            //var textureRegion = new TextureRegion2D(Content.Load<Texture2D>("Gui/9patch-2"));
            //var dialogPatch = new GuiPatchDrawable(textureRegion, 100, 100, 122, 111, Color.White);
            //var dialogStyle = new GuiButtonStyle(dialogPatch);
            //var dialog = new GuiButton(dialogStyle)
            //{
            //    HorizontalAlignment = GuiHorizontalAlignment.Stretch,
            //    VerticalAlignment = GuiVerticalAlignment.Stretch
            //};
            //_guiManager.Layout.Children.Add(dialog);

            var checkedOn = Content.Load<Texture2D>("Gui/button-clicked").ToGuiDrawable();
            var checkedOff = Content.Load<Texture2D>("Gui/button-normal").ToGuiDrawable();
            var checkBoxStyle = new GuiCheckBoxStyle(checkedOn, checkedOff);
            var checkBox = new GuiCheckBox(checkBoxStyle) {HorizontalAlignment = GuiHorizontalAlignment.Left};
            _guiManager.Layout.Children.Add(checkBox);

            var normal = Content.Load<Texture2D>("Gui/button-normal").ToGuiDrawable();
            var pressed = Content.Load<Texture2D>("Gui/button-clicked").ToGuiDrawable();
            var hover = Content.Load<Texture2D>("Gui/button-hover").ToGuiDrawable();
            var buttonStyle = new GuiButtonStyle(normal, pressed, hover);
            var button = new GuiButton(buttonStyle) {VerticalAlignment = GuiVerticalAlignment.Bottom};
            button.Clicked += (sender, args) =>
            {
                if (_player != null)
                {
                    Explode(_player.Position, 3);
                    _player.Destroy();
                    _player = null;
                }
            };
            _guiManager.Layout.Children.Add(button);

            var labelStyle = new GuiLabelStyle(_font);
            _scoreLabel = new GuiLabel(labelStyle, "Hello")
            {
                HorizontalAlignment = GuiHorizontalAlignment.Right,
                VerticalAlignment = GuiVerticalAlignment.Top
            };
            _guiManager.Layout.Children.Add(_scoreLabel);




            _guiManager.PerformLayout();

            _camera = new Camera2D(_viewportAdapter);
            _explosionAnimations = Content.Load<SpriteSheetAnimationGroup>("explosion-animations");

            _spriteBatch = new SpriteBatch(GraphicsDevice);

            _backgroundTexture = Content.Load<Texture2D>("black");

            var bulletTexture = Content.Load<Texture2D>("laserBlue03");
            var bulletRegion = new TextureRegion2D(bulletTexture);
            _bulletFactory = new BulletFactory(_entityManager, bulletRegion);

            SpawnPlayer(_bulletFactory);

            _meteorFactory = new MeteorFactory(_entityManager, Content);

            for (var i = 0; i < 13; i++)
                _meteorFactory.SpawnNewMeteor(_player.Position);
        }
        public override void Draw(SpriteBatch spriteBatch, ViewportAdapter viewportAdapter)
        {
            base.Draw(spriteBatch, viewportAdapter);
            spriteBatch.Begin(transformMatrix: viewportAdapter.GetScaleMatrix(), samplerState: SamplerState.PointClamp);

            // Background and Logo
            spriteBatch.Draw(_backgroundSprite);
            spriteBatch.Draw(_logoSprite);

            if (_phase == PressAnyButtonPhase)
            {
                spriteBatch.DrawString(SceneManager.Instance.GameFont, "Press Any Button", _pressAnyButtonPosition, _menuItemColor);
            }
            else if (_phase == MenuPhase)
            {
                // Menu
                for (var i = 0; i < _menuOptions.Length; i++)
                    spriteBatch.DrawString(SceneManager.Instance.GameFont, _menuOptions[i],
                        new Vector2(25, _menuY + (i * SceneManager.Instance.GameFont.LineHeight)), _menuItemColor);
                spriteBatch.Draw(_menuIcon);
            }

            spriteBatch.End();
        }
示例#22
0
文件: Game1.cs 项目: DuckDefense/duck
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here

            fpsCounter = new FramesPerSecondCounter();
            viewportAdapter = new BoxingViewportAdapter(GraphicsDevice, Settings.ResolutionWidth, Settings.ResolutionHeight);
            camera = new Camera2D(viewportAdapter)
            {
                Zoom = 1f
            };
            IsMouseVisible = true;

            //Window.AllowUserResizing = true;
            Window.ClientSizeChanged += (s, e) => viewportAdapter.OnClientSizeChanged();
            DatabaseConnector.SetConnectionString(Settings.ServerName, Settings.Username, Settings.Password, Settings.DatabaseName);
            base.Initialize();
        }
 public virtual void Draw(SpriteBatch spriteBatch, ViewportAdapter viewportAdapter) { }