Esempio n. 1
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);
        }
Esempio n. 2
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);
        }