Esempio n. 1
0
        private DrawParameters SetDrawParametersForFacedDirection(ISpriteLibrary spriteLibrary)
        {
            DrawParameters drawParameters = default;

            switch (this._player.CurrentDirectionFaced)
            {
            case Direction.Left:
                drawParameters.Texture = spriteLibrary.GetSprite("Sprites/Player/PlayerLeftFacing");
                drawParameters.Effects = SpriteEffects.None;
                break;

            case Direction.Right:
                drawParameters.Texture = spriteLibrary.GetSprite("Sprites/Player/PlayerLeftFacing");
                drawParameters.Effects = SpriteEffects.FlipHorizontally;
                break;

            case Direction.Up:
                drawParameters.Texture = spriteLibrary.GetSprite("Sprites/Player/PlayerUpFacing");
                drawParameters.Effects = SpriteEffects.None;
                break;

            case Direction.Down:
                drawParameters.Texture = spriteLibrary.GetSprite("Sprites/Player/PlayerDownFacing");
                drawParameters.Effects = SpriteEffects.None;
                break;

            default:
                throw new InvalidOperationException();
            }
            drawParameters.Position = this._player.Position;
            return(drawParameters);
        }
Esempio n. 2
0
        public void Draw(ISpriteBatch spriteBatch, ISpriteLibrary spriteLibrary)
        {
            if (!this._gameObject.IsExtant)
            {
                return;
            }

            this._time %= this._lengthOfAnimation;
            var positionInAnimation = this._time / this._lengthOfAnimation;

            DrawParameters drawParameters = default;

            drawParameters.Texture = spriteLibrary.GetSprite(this._textureName);
            var frameCount = (drawParameters.Texture.Width / Constants.TileLength);
            int frameIndex = (int)Math.Floor(frameCount * positionInAnimation);

            // Calculate the source rectangle of the current frame.
            drawParameters.AreaWithinTexture = new Rectangle(frameIndex * Constants.TileLength, 0, Constants.TileLength, Constants.TileLength);
            drawParameters.Position          = this._gameObject.Position;
            drawParameters.Rotation          = this.Rotation;
            drawParameters.Effects           = this.SpriteEffect;
            drawParameters.Opacity           = this.Opacity;

            // Draw the current frame.
            spriteBatch.DrawTexture(drawParameters);
        }
Esempio n. 3
0
        private void DrawHull(ISpriteBatch spriteBatch, ISpriteLibrary spriteLibrary)
        {
            DrawParameters drawParameters = default;

            drawParameters.Texture = spriteLibrary.GetSprite(TextureName);

            // Calculate the source rectangle of the current frame.
            drawParameters.AreaWithinTexture = new Rectangle(0, 0, Constants.TileLength, Constants.TileLength);
            drawParameters.Position          = this._tank.Position;
            drawParameters.Rotation          = this._tank.HullRotation;

            // Draw the current frame.
            spriteBatch.DrawTexture(drawParameters);
        }
Esempio n. 4
0
        private void DrawTrack(ISpriteBatch spriteBatch, ISpriteLibrary spriteLibrary, int p2, double pctPositionInTrackAnimation)
        {
            DrawParameters drawParameters = default;

            drawParameters.Texture = spriteLibrary.GetSprite(TextureName);
            var frameCount = (drawParameters.Texture.Width / Constants.TileLength);
            int frameIndex = (int)Math.Floor(frameCount * pctPositionInTrackAnimation);

            // Calculate the source rectangle of the current frame.
            drawParameters.AreaWithinTexture = new Rectangle(frameIndex * Constants.TileLength, p2, Constants.TileLength, Constants.TileLength);
            drawParameters.Position          = this._tank.Position;
            drawParameters.Rotation          = this._tank.HullRotation;

            // Draw the current frame.
            spriteBatch.DrawTexture(drawParameters);
        }
Esempio n. 5
0
        private void DrawTurret(ISpriteBatch spriteBatch, ISpriteLibrary spriteLibrary)
        {
            Vector2 centreOfRotationForTurret = new Vector2(0, 3);
            double  x = centreOfRotationForTurret.Y * Math.Sin(this._tank.HullRotation) + centreOfRotationForTurret.X * Math.Cos(this._tank.HullRotation);
            double  y = centreOfRotationForTurret.Y * Math.Cos(this._tank.HullRotation) - centreOfRotationForTurret.X * Math.Sin(this._tank.HullRotation);
            Vector2 centreOfRotationForTurretAfterRotation = new Vector2((float)-x, (float)y);

            DrawParameters drawParameters = default;

            drawParameters.Texture = spriteLibrary.GetSprite(TextureName);

            // Calculate the source rectangle of the current frame.
            drawParameters.AreaWithinTexture = new Rectangle(32, 0, Constants.TileLength, Constants.TileLength);
            drawParameters.Position          = this._tank.Position + centreOfRotationForTurretAfterRotation;
            drawParameters.Rotation          = this._tank.TurretRotation;
            drawParameters.Centre            = new Vector2(16, 19); // this is always the same - this is the point where we rotate the turret around in the source rectangle

            // Draw the current frame.
            spriteBatch.DrawTexture(drawParameters);
        }