Hyluss

[Monogame PingPong] Bat

Oct 30th, 2018
558
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.37 KB | None | 0 0
  1. using Microsoft.Xna.Framework;
  2. using Microsoft.Xna.Framework.Graphics;
  3. using Microsoft.Xna.Framework.Input;
  4. using System.Collections.Generic;
  5.  
  6. namespace PingPong
  7. {
  8.     public class Bat : Sprite
  9.     {
  10.         int timeSinceLastFrame = 0;
  11.         int shiningMiliseconds = 300;
  12.  
  13.  
  14.         public Bat(Texture2D texture)
  15.           : base(texture)
  16.         {
  17.             Speed = 5f;
  18.         }
  19.  
  20.         public override void Update(GameTime gameTime, List<Sprite> sprites)
  21.         {
  22.             if (Keyboard.GetState().IsKeyDown(Input.Up))
  23.                 Velocity.Y = -Speed;
  24.             else if (Keyboard.GetState().IsKeyDown(Input.Down))
  25.                 Velocity.Y = Speed;
  26.  
  27.             Position += Velocity;
  28.  
  29.             Position.Y = MathHelper.Clamp(Position.Y, 0, Game1.ScreenHeight - _texture.Height);
  30.  
  31.             Velocity = Vector2.Zero;
  32.  
  33.             if (Shining)
  34.             {
  35.                 ShineBat(gameTime);                
  36.             }
  37.         }
  38.  
  39.         void ShineBat(GameTime gameTime)
  40.         {
  41.             base.Color = Color.Yellow;
  42.             timeSinceLastFrame += gameTime.ElapsedGameTime.Milliseconds;
  43.             if (timeSinceLastFrame > shiningMiliseconds)
  44.             {
  45.                 timeSinceLastFrame -= shiningMiliseconds;
  46.                 base.Color = Color.White;
  47.                 base.Shining = false;
  48.             }
  49.         }
  50.     }
  51. }
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment