Hyluss icon

[Monogame PingPong] Bat

Hyluss | PRO | 10/30/18 01:27:25 PM UTC | 0 ⭐ | 489 👁️ | Never ⏰ | []
C# |

1.37 KB

|

None

|

0 👍

/

0 👎

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using System.Collections.Generic;
 
namespace PingPong
{
    public class Bat : Sprite
    {
        int timeSinceLastFrame = 0;
        int shiningMiliseconds = 300;
 
 
        public Bat(Texture2D texture)
          : base(texture)
        {
            Speed = 5f;
        }
 
        public override void Update(GameTime gameTime, List<Sprite> sprites)
        {
            if (Keyboard.GetState().IsKeyDown(Input.Up))
                Velocity.Y = -Speed;
            else if (Keyboard.GetState().IsKeyDown(Input.Down))
                Velocity.Y = Speed;
 
            Position += Velocity;
 
            Position.Y = MathHelper.Clamp(Position.Y, 0, Game1.ScreenHeight - _texture.Height);
 
            Velocity = Vector2.Zero;
 
            if (Shining)
            {
                ShineBat(gameTime);                
            }
        }
 
        void ShineBat(GameTime gameTime)
        {
            base.Color = Color.Yellow;
            timeSinceLastFrame += gameTime.ElapsedGameTime.Milliseconds;
            if (timeSinceLastFrame > shiningMiliseconds)
            {
                timeSinceLastFrame -= shiningMiliseconds;
                base.Color = Color.White;
                base.Shining = false;
            }
        }
    }
}

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎