Guest User

Untitled

a guest
May 14th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.99 KB | None | 0 0
  1. using System;
  2. using Microsoft.Xna.Framework;
  3. using Microsoft.Xna.Framework.Content;
  4. using Microsoft.Xna.Framework.Graphics;
  5. using Microsoft.Xna.Framework.Input;
  6.  
  7.  
  8. namespace EverMoreDeeper.MenuDesignPlaystyle.HeroClassesBtns
  9. {
  10.  
  11.     class AHeroClassBtn : AnimatedBtn
  12.     {
  13.         private GameWorld gameWorld;
  14.         private string heroClassTitle;
  15.  
  16.         Rectangle rectangle;
  17.         private bool thisToggled = false;
  18.         private bool clickBeganOnButton;
  19.  
  20.         public AHeroClassBtn(Texture2D newTexture, string newHeroClassTitle, Vector2 position) : base(position)
  21.         {
  22.             heroClassTitle = newHeroClassTitle;
  23.             sTexture = newTexture;
  24.  
  25.             FramesPerSecond = 9;
  26.  
  27.             AddAnimation(1, 0, 0, "Idle", 480, 360, new Vector2(0, 0));
  28.             AddAnimation(1, 0, 1, "Hovered", 480, 360, new Vector2(0, 0));
  29.             AddAnimation(1, 0, 2, "MouseDowned", 480, 360, new Vector2(0, 0));
  30.             AddAnimation(1, 0, 3, "Toggled", 480, 360, new Vector2(0, 0));
  31.  
  32.  
  33.             PlayAnimation("Idle");
  34.         }
  35.  
  36.         public override void Update(GameTime gameTime, MouseState mouse)
  37.         {
  38.             rectangle = new Rectangle((int)sPostion.X, (int)sPostion.Y, (int)480, (int)360);
  39.  
  40.             Rectangle mouseRectangle = new Rectangle(mouse.X, mouse.Y, 1, 1);
  41.  
  42.             if (!thisToggled)
  43.             {
  44.                 if (mouseRectangle.Intersects(rectangle) && mouse.LeftButton != ButtonState.Pressed)
  45.                 {
  46.                     PlayAnimation("Hovered");
  47.                 }
  48.  
  49.                 if (mouseRectangle.Intersects(rectangle) && mouse.LeftButton == ButtonState.Pressed)
  50.                 {
  51.                     PlayAnimation("MouseDowned");
  52.                     clickBeganOnButton = true;
  53.                 }
  54.  
  55.                 if (mouseRectangle.Intersects(rectangle) && mouse.LeftButton == ButtonState.Released && clickBeganOnButton == true)
  56.                 {
  57.                     thisToggled = true;
  58.                     PlayAnimation("Toggled");
  59.                     gameWorld.chosenClass = heroClassTitle;
  60.                 }
  61.  
  62.                 else
  63.                 {
  64.                     PlayAnimation("Idle");
  65.                     clickBeganOnButton = false;
  66.                 }
  67.             }
  68.  
  69.             //if (gameWorld.chosenClass != heroClassTitle)
  70.             //{
  71.             //    thisToggled = false;
  72.             //}
  73.  
  74.             //// Make sure it continuesly plays Toggled animation when toggled
  75.             //if (thisToggled)
  76.             //{
  77.             //    PlayAnimation("Toggled");
  78.             //}
  79.  
  80.  
  81.             float deltaTime = (float)gameTime.ElapsedGameTime.TotalSeconds;
  82.  
  83.             base.Update(gameTime, mouse);
  84.         }
  85.  
  86.  
  87.  
  88.         /// Runs every time an animation has finished playing
  89.         public override void AnimationDone(string animation)
  90.         {
  91.             if (!animation.Contains("Idle"))
  92.             {
  93.                 PlayAnimation("Idle");
  94.             }
  95.         }
  96.     }
  97. }
Add Comment
Please, Sign In to add comment