Exemple #1
0
        /*
         *  ‘******************************************************
         *  ‘***  takeDamage
         *  ‘***  Zach Languell
         *  ‘******************************************************
         *  ‘*** Drops ScoringObject if holding one
         *  ‘*** Method Inputs:
         *  ‘***    NA
         *  ‘*** Return value:
         *  ‘***    NA
         *  ‘******************************************************
         *  ‘*** 11/24/2015
         *  ‘******************************************************
         */

        public void takeDamage()
        {
            if (carriedObject != null)
            {
                carriedObject.dropObject(true);
            }
            carriedObject = null;
            playerState   = PlayerState.freeFlight;
            stateChange   = 0;
        }
Exemple #2
0
        /*
         *  ‘******************************************************
         *  ‘***  Update
         *  ‘***  Kevin Anderson
         *  ‘******************************************************
         *  ‘*** Updates player movements, animation and states
         *  ‘*** Method Inputs:
         *  ‘***    gameTime - game time elapse
         *          divingSound - SoundEffect - playerDiving
         *          pickUpSound - sound effect - pickUpSound2
         *  ‘*** Return value:
         *  ‘*** NA
         *  ‘******************************************************
         *  ‘*** 11/8/2015
         *  ‘******************************************************
         */

        public void Update(GameTime gameTime, SoundEffect divingSound, SoundEffect pickUpSound)
        {
            newKeyboardState   = Keyboard.GetState();
            rectangle          = new Rectangle(currentFrame * frameWidth, 0, frameWidth, frameHeight);
            origin             = new Vector2(rectangle.Width / 2, rectangle.Height / 2);
            collisionRectangle = new Rectangle((int)position.X, (int)position.Y, frameWidth, frameHeight);
            stateChange       += gameTime.ElapsedGameTime.TotalMilliseconds;
            switch (playerState)
            {
            case PlayerState.freeFlight:

                playerMovement(gameTime);

                if (newKeyboardState.IsKeyDown(Keys.Space) && stateChange > 500)
                {
                    stateChange    = 0;
                    playerState    = PlayerState.diving;
                    isDiveComplete = false;
                    lastPosition   = new Vector2(position.X, position.Y);
                    divingSound.Play();
                }
                break;

            case PlayerState.diving:

                if (this.position.Y < 600 && isDiveComplete == false)
                {
                    this.position.Y += 6;
                }
                if (this.position.Y >= 599)
                {
                    isDiveComplete = true;
                }

                if (this.position.Y > lastPosition.Y && isDiveComplete == true)
                {
                    this.position.Y -= 6;
                }
                if (this.position.Y <= lastPosition.Y && isDiveComplete == true && this.carriedObject == null)
                {
                    playerState = PlayerState.freeFlight;
                }
                else if (this.position.Y <= lastPosition.Y && isDiveComplete == true && this.carriedObject != null)
                {
                    playerState = PlayerState.hasObject;
                }
                break;

            case PlayerState.hasObject:
                playerMovement(gameTime);
                if (newKeyboardState.IsKeyDown(Keys.Space))
                {
                    if (carriedObject != null)
                    {
                        carriedObject.dropObject(false);
                    }
                    carriedObject = null;
                    playerState   = PlayerState.freeFlight;
                    stateChange   = 0;
                }
                position += new Vector2(0, 2);
                break;
            }
            if (wasdKeysUsed && isDiveComplete)
            {
                if (Keyboard.GetState().IsKeyDown(Keys.A))
                {
                    AnimateLeft(gameTime);
                    if (carriedObject != null)
                    {
                        carriedObject.movingLeft = true;
                    }
                }
                else
                {
                    if (carriedObject != null)
                    {
                        carriedObject.movingLeft = false;
                    }
                    AnimateRight(gameTime);
                }
            }
            else if (isDiveComplete)
            {
                if (Keyboard.GetState().IsKeyDown(Keys.Left))
                {
                    AnimateLeft(gameTime);
                    if (carriedObject != null)
                    {
                        carriedObject.movingLeft = true;
                    }
                }
                else
                {
                    if (carriedObject != null)
                    {
                        carriedObject.movingLeft = false;
                    }
                    AnimateRight(gameTime);
                }
            }
        }