Exemplo n.º 1
0
        protected override void Update(GameTime gameTime)
        {
            var deltaSeconds  = (float)gameTime.ElapsedGameTime.TotalSeconds;
            var keyboardState = Keyboard.GetState();

            //var mouseState = Mouse.GetState();

            //_mousePoint = _camera.ScreenToWorld(new Vector2(mouseState.X, mouseState.Y)).ToPoint();

            // camera
            if (keyboardState.IsKeyDown(Keys.R))
            {
                _camera.ZoomIn(deltaSeconds);
            }

            if (keyboardState.IsKeyDown(Keys.F))
            {
                _camera.ZoomOut(deltaSeconds);
            }

            // zombie
            if (keyboardState.IsKeyDown(Keys.Left))
            {
                _zombie.Walk(-1.0f);
            }

            if (keyboardState.IsKeyDown(Keys.Right))
            {
                _zombie.Walk(1.0f);
            }

            if (keyboardState.IsKeyDown(Keys.Space))
            {
                _zombie.Attack();
            }

            if (keyboardState.IsKeyDown(Keys.Up))
            {
                _zombie.Jump();
            }

            if (keyboardState.IsKeyDown(Keys.Enter))
            {
                _zombie.Die();
            }

            // update must be called before collision detection
            _zombie.Update(gameTime);
            _world.Update(gameTime);
            _camera.LookAt(_zombie.Position);

            base.Update(gameTime);
        }
        protected override void Update(GameTime gameTime)
        {
            var deltaSeconds  = (float)gameTime.ElapsedGameTime.TotalSeconds;
            var keyboardState = Keyboard.GetState();

            if (keyboardState.IsKeyDown(Keys.R))
            {
                _camera.ZoomIn(deltaSeconds);
            }

            if (keyboardState.IsKeyDown(Keys.F))
            {
                _camera.ZoomOut(deltaSeconds);
            }

            if (keyboardState.IsKeyDown(Keys.Left))
            {
                _zombie.Walk(-1.0f);
            }

            if (keyboardState.IsKeyDown(Keys.Right))
            {
                _zombie.Walk(1.0f);
            }

            if (keyboardState.IsKeyDown(Keys.Space))
            {
                _zombie.Attack();
            }

            if (keyboardState.IsKeyDown(Keys.Enter))
            {
                _zombie.Die();
            }

            _sprite.Position += new Vector2(-500, 0) * deltaSeconds;

            _spriteAnimator.Update(gameTime);
            _zombie.Update(gameTime);

            if (_sprite.Position.X < 0 - _sprite.GetBoundingRectangle().Width)
            {
                _sprite.Position = new Vector2(1900, _sprite.Position.Y);
            }

            base.Update(gameTime);
        }