Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Content;
- using Microsoft.Xna.Framework.Graphics;
- using Microsoft.Xna.Framework.Input;
- namespace EverMoreDeeper.MenuDesignPlaystyle.HeroClassesBtns
- {
- class AHeroClassBtn : AnimatedBtn
- {
- private GameWorld gameWorld;
- private string heroClassTitle;
- Rectangle rectangle;
- private bool thisToggled = false;
- private bool clickBeganOnButton;
- public AHeroClassBtn(Texture2D newTexture, string newHeroClassTitle, Vector2 position) : base(position)
- {
- heroClassTitle = newHeroClassTitle;
- sTexture = newTexture;
- FramesPerSecond = 9;
- AddAnimation(1, 0, 0, "Idle", 480, 360, new Vector2(0, 0));
- AddAnimation(1, 0, 1, "Hovered", 480, 360, new Vector2(0, 0));
- AddAnimation(1, 0, 2, "MouseDowned", 480, 360, new Vector2(0, 0));
- AddAnimation(1, 0, 3, "Toggled", 480, 360, new Vector2(0, 0));
- PlayAnimation("Idle");
- }
- public override void Update(GameTime gameTime, MouseState mouse)
- {
- rectangle = new Rectangle((int)sPostion.X, (int)sPostion.Y, (int)480, (int)360);
- Rectangle mouseRectangle = new Rectangle(mouse.X, mouse.Y, 1, 1);
- if (!thisToggled)
- {
- if (mouseRectangle.Intersects(rectangle) && mouse.LeftButton != ButtonState.Pressed)
- {
- PlayAnimation("Hovered");
- }
- if (mouseRectangle.Intersects(rectangle) && mouse.LeftButton == ButtonState.Pressed)
- {
- PlayAnimation("MouseDowned");
- clickBeganOnButton = true;
- }
- if (mouseRectangle.Intersects(rectangle) && mouse.LeftButton == ButtonState.Released && clickBeganOnButton == true)
- {
- thisToggled = true;
- PlayAnimation("Toggled");
- gameWorld.chosenClass = heroClassTitle;
- }
- else
- {
- PlayAnimation("Idle");
- clickBeganOnButton = false;
- }
- }
- //if (gameWorld.chosenClass != heroClassTitle)
- //{
- // thisToggled = false;
- //}
- //// Make sure it continuesly plays Toggled animation when toggled
- //if (thisToggled)
- //{
- // PlayAnimation("Toggled");
- //}
- float deltaTime = (float)gameTime.ElapsedGameTime.TotalSeconds;
- base.Update(gameTime, mouse);
- }
- /// Runs every time an animation has finished playing
- public override void AnimationDone(string animation)
- {
- if (!animation.Contains("Idle"))
- {
- PlayAnimation("Idle");
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment