Ejemplo n.º 1
0
        public void Draw(ISpriteBatch spriteBatch, ISpriteLibrary spriteLibrary)
        {
            if (!this._player.IsAlive())
            {
                return;
            }

            var drawParameters = SetDrawParametersForFacedDirection(spriteLibrary);
            var frameCount     = (drawParameters.Texture.Width / Constants.TileLength);
            var position       = this.TimeWithinAnimation / AnimationLength;
            int frameIndex     = (int)Math.Floor(frameCount * position);

            var currentFoot = position >= 0.5;

            if (this._whichFootFlag != currentFoot)
            {
                this._player.PlaySound(currentFoot ? GameSound.PlayerMovesFirstFoot : GameSound.PlayerMovesSecondFoot);
                this._whichFootFlag = currentFoot;
            }

            // Calculate the source rectangle of the current frame.
            drawParameters.AreaWithinTexture = new Rectangle(frameIndex * Constants.TileLength, 0, Constants.TileLength, Constants.TileLength);

            // Draw the current frame.
            spriteBatch.DrawTexture(drawParameters);
        }
Ejemplo 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);
        }
Ejemplo n.º 3
0
 private void DrawLives(ISpriteBatch spriteBatch, int livesLeft)
 {
     if (livesLeft > 3)
     {
         spriteBatch.DrawTexture(this._life, new Vector2(480 - 16, 8), new Rectangle(0, 0, 10, 16));
         spriteBatch.DrawTexture(this._life, new Vector2(480 - 30, 8), new Rectangle(10, 0, 10, 16));
         DrawValue(spriteBatch, livesLeft + 100, 480 - 32, 8);
     }
     else
     {
         for (int i = 0; i < livesLeft; i++)
         {
             var destination = new Vector2(480 - ((i + 1) * 16), 8);
             spriteBatch.DrawTexture(this._life, destination, new Rectangle(0, 0, 10, 16));
         }
     }
 }
Ejemplo n.º 4
0
        public override void Draw(GameTime gameTime)
        {
            if (this._transitionTexture == null)
            {
                return;
            }

            ISpriteBatch spriteBatch = ScreenManager.SpriteBatch;

            spriteBatch.Begin();
            spriteBatch.DrawTexture(this._transitionTexture, Vector2.Zero, null);
            spriteBatch.End();
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
0
        private void DrawValue(ISpriteBatch spriteBatch, decimal value, int right, int top)
        {
            int i = 1;

            while (true)
            {
                int digit       = (int)(value % 10);
                var source      = new Rectangle(digit * 6, 0, 6, 16);
                var destination = new Vector2(right - (i * 8), top);
                spriteBatch.DrawTexture(this._digits, destination, source);
                value = Math.Floor(value / 10);
                if (value == 0)
                {
                    break;
                }
                i++;
            }
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Advances the time position and draws the current frame of the animation.
        /// </summary>
        /// <param name="gameTime">Time passed since the last call to Draw</param>
        /// <param name="spriteBatch">The SpriteBatch object to draw the sprite to</param>
        /// <param name="position">The position of the sprite</param>
        public void Draw(GameTime gameTime, ISpriteBatch spriteBatch, Vector2 position)
            {
            if (Animation == null)
                throw new NotSupportedException("No animation is currently playing.");
            
            // Advance the frame index
            this._advanceRoutine(gameTime);

            // Calculate the source rectangle of the current frame.
            var source = new Rectangle(FrameIndex * Tile.Width, 0, Tile.Width, Tile.Height);

            // Draw the current frame.
            spriteBatch.DrawTexture(Animation.Texture, position, source, this.Rotation, Origin, this.SpriteEffect);
            }
Ejemplo n.º 10
0
 private void DrawValue(ISpriteBatch spriteBatch, int value, int right, int top)
 {
     int i = 1;
     while (true)
         {
         int digit = value % 10;
         var source = new Rectangle(digit * 6, 0, 6, 16);
         Vector2 destination = new Vector2(right - (i * 8), top) + spriteBatch.WindowOffset;
         spriteBatch.DrawTexture(this._digits, destination, source, 0.0f, Vector2.Zero);
         value = value / 10;
         if (value == 0)
             break;
         i++;
         }
 }