Пример #1
0
        /// <summary>
        /// Checks if the key for shooting is pressed
        /// </summary>
        /// <param name="keyboardState">Keyboard state</param>
        /// <returns></returns>
        private bool ShootKeyPressed(IControllerState keyboardState)
        {
            if (keyboardState.IsKeyDown(Keys.A))
            {
                this.ShootDirection = SearchPattern.Left;
            }
            else if (keyboardState.IsKeyDown(Keys.D))
            {
                this.ShootDirection = SearchPattern.Right;
            }
            else if (keyboardState.IsKeyDown(Keys.W))
            {
                this.ShootDirection = SearchPattern.Up;
            }
            else if (keyboardState.IsKeyDown(Keys.S))
            {
                this.ShootDirection = SearchPattern.Down;
            }
            else
            {
                return false;
            }

            return true;
        }
Пример #2
0
 /// <summary>
 /// heals the hero when "1" is pressed
 /// </summary>
 /// <param name="keyboardState">keyboard state</param>
 /// <param name="gameTime">game time</param>
 private void OnDigitOne(IControllerState keyboardState, GameTime gameTime)
 {
     if (keyboardState.IsKeyDown(Keys.D1))
     {
         if (this.MedKits > 0 && !this.isMedKitUsed)
         {
             this.Heal(gameTime);
         }
     }
     else
     {
         this.PrepareMedKit(gameTime);
     }
 }
Пример #3
0
 /// <summary>
 /// Inspects objects when space is pressed
 /// </summary>
 /// <param name="keyboardState">key board state</param>
 /// <param name="gameTime">game time</param>
 private void OnSpacebar(IControllerState keyboardState, GameTime gameTime)
 {
     if (keyboardState.IsKeyDown(Keys.Space))
     {
         this.InspectNearbyObjects(gameTime);
     }
 }
Пример #4
0
        /// <summary>
        /// Move the Player
        /// </summary>
        /// <param name="gameTime">Game time</param>
        /// <param name="keyboardState">Keyboard state</param>
        private void Move(GameTime gameTime, IControllerState keyboardState)
        {
            PointF existingPosition = this.Position;
            Point existingMapPosition = this.MapPosition;

            var move = (float)(PlayerSpeed * gameTime.ElapsedTime.TotalSeconds);

            if (keyboardState.IsKeyDown(Keys.Left))
            {
                this.Position = new PointF(this.Position.X - move, this.Position.Y);
                this.WalkDirection = Direction.Left;
            }
            else if (keyboardState.IsKeyDown(Keys.Right))
            {
                this.Position = new PointF(this.Position.X + move, this.Position.Y);
                this.WalkDirection = Direction.Right;
            }
            else if (keyboardState.IsKeyDown(Keys.Up))
            {
                this.Position = new PointF(this.Position.X, this.Position.Y - move);
                this.WalkDirection = Direction.Up;
            }
            else if (keyboardState.IsKeyDown(Keys.Down))
            {
                this.Position = new PointF(this.Position.X, this.Position.Y + move);
                this.WalkDirection = Direction.Down;
            }
            else
            {
                this.WalkDirection = Direction.Still;
                return;
            }

            // The position on the map is represented by two integers (pixel accuracy)
            this.MapPosition = new Point((int)Math.Round(this.Position.X), (int)Math.Round(this.Position.Y));

            // Check if we can move on the next position
            // (not leaving the map and not colliding with walls or other objects)
            if (Collisions.IsNotCollding(this))
            {
                // Player was moved
                return;
            }

            // Player cannot go here, return the old coords
            this.Position = existingPosition;
            this.MapPosition = existingMapPosition;
        }