Ejemplo n.º 1
0
        public Game1()
        {
            Content.RootDirectory = "Content";
            _graphics             = new GraphicsDeviceManager(this)
            {
                PreferredBackBufferWidth  = 1280,
                PreferredBackBufferHeight = 720
            };
            Window.AllowUserResizing = true;
            IsMouseVisible           = true;

            _humanKeyboard = new HumanKeyboardControls();
            KeyboardEventRegistry.OnKeyDown(Keys.Enter, () =>
            {
                if (_useCpuKeyboard)
                {
                    _cpuGuyDecorator.Deactivate();
                }
                else
                {
                    _cpuGuyDecorator.Activate();
                }
                _useCpuKeyboard = !_useCpuKeyboard;
            });

            KeyboardEventRegistry.OnKeyDown(Keys.B, () =>
            {
                _guy.BoundingBox.ShouldDraw = !_guy.BoundingBox.ShouldDraw;
            });
        }
Ejemplo n.º 2
0
        protected override void Update(GameTime gameTime)
        {
            var keyboardState = Keyboard.GetState();

            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed ||
                keyboardState.IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            KeyboardEventRegistry.Update(keyboardState);
            if (_useCpuKeyboard)
            {
                _cpuGuyDecorator.Update(gameTime);
            }
            else
            {
                _guy.Update(gameTime, keyboardState);
            }


            keepGuyOnCamera(_guy, _camera);

            _cameraController.Update(keyboardState);

            base.Update(gameTime);
        }
Ejemplo n.º 3
0
 public CpuGuyDecorator(Guy.Guy guy, SpriteFont font)
 {
     Guy              = guy;
     _font            = font;
     _controlPatterns = new CircularArray <CpuKeyboardControls>(
         CpuKeyboardControlsFactory.RunningCelebration(),
         CpuKeyboardControlsFactory.RunBackAndForth(),
         CpuKeyboardControlsFactory.Cannonball(),
         CpuKeyboardControlsFactory.JumpAndSquat());
     KeyboardEventRegistry.OnKeyDown(Keys.Left, OnLeft);
     KeyboardEventRegistry.OnKeyDown(Keys.Right, OnRight);
 }