コード例 #1
0
        public override void Render(SpriteBatch spriteBatch, Entity entity, Vector2 position, GameTime gameTime)
        {
            var entitySprite           = _defaultSprite;
            var pickedUpEntityPosition = position;

            if (entity.IsHolding())
            {
                entitySprite            = _liftingSprite;
                pickedUpEntityPosition -= new Vector2(0, 18);
            }

            if (entity.IsMoving())
            {
                var moveFrame = FRAMES[(int)((8f * gameTime.GetTotalTime()) % 4)];
                entitySprite            = entitySprite.SubSprite(moveFrame, (int)Owner.Facing);
                pickedUpEntityPosition += PICKEDUP_ENTITY_OFFSETS[(int)((8f * gameTime.GetTotalTime()) % 4)];
            }
            else
            {
                entitySprite = entitySprite.SubSprite(2, (int)Owner.Facing);
            }

            if (entity.IsSwimming())
            {
                var waterDepth = 0.6f;

                var waterSprite = _waterEffect.SubSprite((int)(8 * gameTime.GetTotalTime()) % 5, 0);
                var upperHalf   = entitySprite.UpperHalf(waterDepth);
                var bottomHalf  = entitySprite.BottomHalf(waterDepth);

                spriteBatch.DrawSprite(bottomHalf, position + new Vector2(-entitySprite.Width / 2, 0), Color.DimGray * 0.5f);
                spriteBatch.DrawSprite(waterSprite, position - new Vector2(waterSprite.Width / 2, waterSprite.Height / 2), Color.White);
                spriteBatch.DrawSprite(upperHalf, position + new Vector2(-entitySprite.Width / 2, -upperHalf.Height), Color.White);

                pickedUpEntityPosition += new Vector2(0, upperHalf.Height - bottomHalf.Height);
            }
            else
            {
                spriteBatch.DrawSprite(entitySprite, position + new Vector2(-entitySprite.Width / 2, -entitySprite.Height) + new Vector2(0, 6), Color.White);
            }

            var pickedUpEntity = entity.GetHoldedEntity();

            if (pickedUpEntity != null && pickedUpEntity.HasComponent <Renderer>())
            {
                var renderer = pickedUpEntity.GetComponent <Renderer>();

                if (renderer != null)
                {
                    renderer.Render(spriteBatch, pickedUpEntity, pickedUpEntityPosition, gameTime);
                }
            }
        }
コード例 #2
0
        public static void DrawBox(this SpriteBatch spriteBatch, _Sprite sprite, Rectangle dest, float scale, Color color)
        {
            sprite = sprite.WithGrid(3, 3);

            var topLeft = sprite.SubSprite(0, 0);

            spriteBatch.DrawSprite(
                topLeft,
                dest.X,
                dest.Y,
                topLeft.Width * scale,
                topLeft.Height * scale,
                color);

            var topRight = sprite.SubSprite(2, 0);

            spriteBatch.DrawSprite(
                topRight,
                dest.X + dest.Width - topRight.Width * scale,
                dest.Y,
                topRight.Width * scale,
                topRight.Height * scale,
                color);

            var bottomLeft = sprite.SubSprite(0, 2);

            spriteBatch.DrawSprite(
                bottomLeft,
                dest.X,
                dest.Y + dest.Height - bottomLeft.Height * scale,
                bottomLeft.Width * scale,
                bottomLeft.Height * scale,
                color);

            var bottomRight = sprite.SubSprite(2, 2);

            spriteBatch.DrawSprite(
                bottomRight,
                dest.X + dest.Width - bottomRight.Width * scale,
                dest.Y + dest.Height - bottomRight.Height * scale,
                bottomRight.Width * scale,
                bottomRight.Height * scale,
                color);

            var top = sprite.SubSprite(1, 0);

            spriteBatch.DrawSprite(
                top,
                dest.X + top.Width,
                dest.Y,
                dest.Width - top.Width * 2,
                top.Height * scale,
                color);

            var bottom = sprite.SubSprite(1, 2);

            spriteBatch.DrawSprite(
                bottom,
                dest.X + bottom.Width * scale,
                dest.Y + dest.Height - bottom.Width * scale,
                dest.Width - bottom.Width * 2 * scale,
                bottom.Height * scale,
                color);

            var left = sprite.SubSprite(0, 1);

            spriteBatch.DrawSprite(
                left,
                dest.X,
                dest.Y + left.Height * scale,
                left.Width * scale,
                dest.Height - left.Height * 2 * scale,
                color);

            var right = sprite.SubSprite(2, 1);

            spriteBatch.DrawSprite(
                right,
                dest.X + dest.Width - right.Width * scale,
                dest.Y + right.Height * scale,
                right.Width * scale,
                dest.Height - right.Height * 2 * scale,
                color);
        }