using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using System.Collections.Generic; using System; namespace Asteroids; public class Button { private Rectangle rect; private Color main; private Color Hover; private Color selected; private string text; public bool clicked; public int id; public int Key; public Button(int Key, Rectangle rect, Color main, Color Hover, int id, string text) { this.Key = Key; this.rect = rect; this.main = main; this.Hover = Hover; this.id = id; this.text = text; } public void draw(SpriteBatch _spriteBatch) { _spriteBatch.Draw(vars.ThePixel, rect, null, selected); _spriteBatch.DrawString(vars.Font, text, new Vector2(rect.Center.ToVector2().X-vars.Font.MeasureString(text).X/2, rect.Center.ToVector2().Y-vars.Font.MeasureString(text).Y/2), Color.White); } public void Update() { clicked = false; if(rect.Contains(Mouse.GetState().Position)) { selected = Hover; if(Mouse.GetState().LeftButton == ButtonState.Pressed) { clicked = true; } } else { selected = main; } } }