public Rectangle UpdateSprite(GameTime gameTime, PlayerDirection direction, bool isDeadly)
        {
            Timer += (float)gameTime.ElapsedGameTime.TotalMilliseconds;
            if (Timer > Interval)
            {
                CurrentFrame++;
                if (CurrentFrame > FrameCount - 1)
                {
                    const int positionOne = 0;
                    const int positionTwo = 50;
                    const int positionThree = 100;
                    const int postionFour = 150;

                    var directionCord = direction.Equals(PlayerDirection.Left) ? 74 : 148;

                    CurrentFrame = 0;

                    if(direction.Equals(PlayerDirection.None))
                    {
                        SourceRect = new Rectangle(100, 3, SpriteWidth, SpriteHeight);
                    }
                    else
                    {
                        if (_playerPosition.Equals(0))
                        {
                            SourceRect = new Rectangle(positionOne, directionCord, SpriteWidth, SpriteHeight);
                            if (!isDeadly)
                                SourceRect = new Rectangle(0, 0, 0, 0);
                        }
                        if (_playerPosition.Equals(1))
                        {
                            SourceRect = new Rectangle(positionTwo, directionCord, SpriteWidth, SpriteHeight);
                        }
                        if (_playerPosition.Equals(2))
                        {
                            SourceRect = new Rectangle(positionThree, directionCord, SpriteWidth, SpriteHeight);
                            if (!isDeadly)
                                SourceRect = new Rectangle(0, 0, 0, 0);
                        }
                        if (_playerPosition.Equals(3))
                        {
                            SourceRect = new Rectangle(postionFour, directionCord, SpriteWidth, SpriteHeight);
                        }

                        _playerPosition++;

                        if (_playerPosition.Equals(4))
                            _playerPosition = 0;
                    }
                }

                Timer = 0f;
            }

            return SourceRect;
        }
Beispiel #2
0
    void PlayerMove()
    {
        //Controls
        moveX = Input.GetAxis("Horizontal");
        moveY = Input.GetAxis("Vertical");



        PlayerRB.drag = 1f;

        PickUp = false;


        if (MoveX == 0)
        {
            playerAnimation.SetBool("isMoving", false);
        }
        else if (MoveX > 0)
        {
            playerAnimation.SetBool("isMoving", true);
        }
        else if (MoveX < 0)
        {
            playerAnimation.SetBool("isMoving", true);
        }

        if (moveY == 0)
        {
            PlayerRB.velocity = new Vector2(moveX * playerSpeed, PlayerRB.velocity.y);
        }
        else if (moveY > 0)
        {
            PlayerRB.drag     = 10f;
            PlayerRB.velocity = new Vector2(moveX * (playerSpeed / 2), PlayerRB.velocity.y);
        }
        else if (moveY < 0)
        {
            PickUp = true;
        }


        //Animations

        Vector2 localScale = this.transform.localScale;

        //Player Directions
        if (moveX < 0.0f && PlayerDirection.Equals(Direction.RIGHT))
        {
            localScale.x        *= -1;
            transform.localScale = localScale;
            playerDirection      = Direction.LEFT;
        }
        else if (moveX > 0.0f && PlayerDirection.Equals(Direction.LEFT))
        {
            localScale.x        *= -1;
            transform.localScale = localScale;
            playerDirection      = Direction.RIGHT;
        }
    }
Beispiel #3
0
 private void animatePlayer(GameTime gameTime)
 {
     if (moving && alive)
     {
         if (playerDirection.Equals(PlayerDirection.Down))
         {
             Animator.animate(gameTime, ref this.texture, Game1.textureManager.playerDown, 0.125f, ref this.animatorCounter, true);
         }
         else if (playerDirection.Equals(PlayerDirection.Left))
         {
             Animator.animate(gameTime, ref this.texture, Game1.textureManager.playerLeft, 0.125f, ref this.animatorCounter, true);
         }
         else if (playerDirection.Equals(PlayerDirection.Right))
         {
             Animator.animate(gameTime, ref this.texture, Game1.textureManager.playerRight, 0.125f, ref this.animatorCounter, true);
         }
         else if (playerDirection.Equals(PlayerDirection.Up))
         {
             Animator.animate(gameTime, ref this.texture, Game1.textureManager.playerUp, 0.125f, ref this.animatorCounter, true);
         }
     }
     else if (!alive)
     {
         Animator.animate(gameTime, ref this.texture, Game1.textureManager.playerDead, 0.125f, ref this.animatorCounter, true);
         // Start new game after player death animation
         if (this.texture.Equals(Game1.textureManager.playerDead.Last()))
         {
             this.gameScreen.StartGame();
             LivesComponent.lives--;
         }
     }
     else
     {
         if (playerDirection.Equals(PlayerDirection.Down))
         {
             this.texture = Game1.textureManager.playerDown.First();
         }
         else if (playerDirection.Equals(PlayerDirection.Left))
         {
             this.texture = Game1.textureManager.playerLeft.First();
         }
         else if (playerDirection.Equals(PlayerDirection.Right))
         {
             this.texture = Game1.textureManager.playerRight.First();
         }
         else if (playerDirection.Equals(PlayerDirection.Up))
         {
             this.texture = Game1.textureManager.playerUp.First();
         }
     }
 }
        public Rectangle UpdateSprite(GameTime gameTime, PlayerDirection direction, bool isDeadly)
        {
            Timer += (float)gameTime.ElapsedGameTime.TotalMilliseconds;
            if (Timer > Interval)
            {
                CurrentFrame++;
                if (CurrentFrame > FrameCount - 1)
                {
                    const int positionOne   = 0;
                    const int positionTwo   = 50;
                    const int positionThree = 100;
                    const int postionFour   = 150;

                    var directionCord = direction.Equals(PlayerDirection.Left) ? 74 : 148;

                    CurrentFrame = 0;

                    if (direction.Equals(PlayerDirection.None))
                    {
                        SourceRect = new Rectangle(100, 3, SpriteWidth, SpriteHeight);
                    }
                    else
                    {
                        if (_playerPosition.Equals(0))
                        {
                            SourceRect = new Rectangle(positionOne, directionCord, SpriteWidth, SpriteHeight);
                            if (!isDeadly)
                            {
                                SourceRect = new Rectangle(0, 0, 0, 0);
                            }
                        }
                        if (_playerPosition.Equals(1))
                        {
                            SourceRect = new Rectangle(positionTwo, directionCord, SpriteWidth, SpriteHeight);
                        }
                        if (_playerPosition.Equals(2))
                        {
                            SourceRect = new Rectangle(positionThree, directionCord, SpriteWidth, SpriteHeight);
                            if (!isDeadly)
                            {
                                SourceRect = new Rectangle(0, 0, 0, 0);
                            }
                        }
                        if (_playerPosition.Equals(3))
                        {
                            SourceRect = new Rectangle(postionFour, directionCord, SpriteWidth, SpriteHeight);
                        }

                        _playerPosition++;

                        if (_playerPosition.Equals(4))
                        {
                            _playerPosition = 0;
                        }
                    }
                }

                Timer = 0f;
            }

            return(SourceRect);
        }