Exemple #1
0
        public void HandleInput(GameTime gameTime)
        {
            if (Dead)
            {
                Revive();
            }

            if (InputHandler.IsKeyDown(Keys.W))
            {
                direction = Direction.Up;
                if (onGround)
                {
                    Jump();
                }
            }
            if (InputHandler.IsKeyDown(Keys.S))
            {
                direction = Direction.Down;
            }
            if (InputHandler.IsKeyDown(Keys.D))
            {
                velocity += accelerationAmount;
                direction = Direction.Right;
                if (InputHandler.IsKeyDown(Keys.W))
                {
                    direction |= Direction.Up;
                }
                if (InputHandler.IsKeyDown(Keys.S))
                {
                    direction |= Direction.Down;
                }
            }
            if (InputHandler.IsKeyDown(Keys.A))
            {
                velocity -= accelerationAmount;
                direction = Direction.Left;
                if (InputHandler.IsKeyDown(Keys.W))
                {
                    direction |= Direction.Up;
                }
                if (InputHandler.IsKeyDown(Keys.S))
                {
                    direction |= Direction.Down;
                }
            }
            if (InputHandler.IsKeyReleased(Keys.Space))
            {
                var bulletVelocity = Vector2.Zero;

                if (direction.HasFlag(Direction.Up))
                {
                    bulletVelocity -= Vector2.UnitY;
                }
                if (direction.HasFlag(Direction.Down))
                {
                    bulletVelocity += Vector2.UnitY;
                }
                if (direction.HasFlag(Direction.Left))
                {
                    bulletVelocity -= Vector2.UnitX;
                }
                if (direction.HasFlag(Direction.Right))
                {
                    bulletVelocity += Vector2.UnitX;
                }
                bulletVelocity *= bulletAcceleration;

                var bulletLocation = this.location + new Vector2(this.frameWidth / 2, this.frameHeight / 2);
                onShoot.Send(Name, bulletLocation.X, bulletLocation.Y, bulletVelocity.X, bulletVelocity.Y);

                EffectsManager.AddBulletParticle(Name, bulletLocation, bulletVelocity);
            }

            velocity += fallSpeed;
            HandleVelocity();
            CheckCollision(gameTime);
            onLocationChange.Send(Name, location.X, location.Y);

            Camera.Move((float)gameTime.ElapsedGameTime.TotalSeconds, WorldLocation, velocity, accelerationAmount.X);
        }