Example #1
0
        private void MovePengo()
        {
            keyState = Keyboard.GetState();
            currentSprite = SpriteShow.hor;
            if (!isOnGround)
            {
                speed.Y += 0.3f;
                speed.X = 0;
                srcRect = new Rectangle(Game1.TILE_SIZE * 4, 0, Game1.TILE_SIZE, Game1.TILE_SIZE);
            }
            HandleRightButton();
            HandleLeftButton();
            HandleUpButton();

            pos += speed;
            hitbox.X = (int)(pos.X > 0 ? pos.X + 0.5f : pos.X - 0.5f);
            hitbox.Y = (int)(pos.Y > 0 ? pos.Y + 0.5f : pos.Y - 0.5f);
            if (hitbox.Y + hitbox.Height >= windowY)
            {
                pos.Y = windowY - hitbox.Height;
                isOnGround = true;
                speed.Y = 0;
                speed.X = 0;
            }
            if (isOnGround && moving)
            {
                srcRect = new Rectangle(Game1.TILE_SIZE * PengoAnimation(), 0, Game1.TILE_SIZE, Game1.TILE_SIZE);
                moving = false;
            }
        }
Example #2
0
 private void HandleRightButton()
 {
     if (keyState.IsKeyDown(Keys.Right) && !keyState.IsKeyDown(Keys.D))
     {
         speed.X = +2;
         moving = true;
         spriteFx = SpriteEffects.None;
     }
     if (keyState.IsKeyDown(Keys.D) && keyState.IsKeyDown(Keys.Right) && isOnGround)
     {
         speed.X = +4;
         spriteFx = SpriteEffects.None;
         srcRect = new Rectangle(Game1.TILE_SIZE * 5, 0, Game1.TILE_SIZE, Game1.TILE_SIZE);
         currentSprite = SpriteShow.slide;
     }
 }
Example #3
0
 private void HandleUpButton()
 {
     if (keyState.IsKeyDown(Keys.Up) && isOnGround && !isOnLadder)
     {
         speed.Y = -6;
         isOnGround = false;
         srcRect = new Rectangle(Game1.TILE_SIZE * 4, 0, Game1.TILE_SIZE, Game1.TILE_SIZE);
     }
     if (keyState.IsKeyDown(Keys.D) && isOnGround)
     {
         srcRect = new Rectangle(Game1.TILE_SIZE * 5, 0, Game1.TILE_SIZE, Game1.TILE_SIZE);
         currentSprite = SpriteShow.slide;
     }
     if (keyState.IsKeyDown(Keys.Up) && isOnLadder)
     {
         speed.Y = -1;
         isOnGround = false;
         srcRect = new Rectangle(Game1.TILE_SIZE * 6, 0, Game1.TILE_SIZE, Game1.TILE_SIZE);
         isOnLadder = false;
     }
 }
Example #4
0
 private void HandleLeftButton()
 {
     if (keyState.IsKeyDown(Keys.Left) && !keyState.IsKeyDown(Keys.D))
     {
         speed.X = -2;
         moving = true;
         spriteFx = SpriteEffects.FlipHorizontally;
     }
     if (keyState.IsKeyDown(Keys.D) && keyState.IsKeyDown(Keys.Left) && isOnGround)
     {
         speed.X = -4;
         spriteFx = SpriteEffects.FlipHorizontally;
         srcRect = new Rectangle(Game1.TILE_SIZE * 5, 0, Game1.TILE_SIZE, Game1.TILE_SIZE);
         currentSprite = SpriteShow.slide;
     }
 }