Skip to content

Instantly share code, notes, and snippets.

@TheRealNOIG
Last active March 1, 2016 20:19
Show Gist options
  • Save TheRealNOIG/47837fee2678fd4b6a94 to your computer and use it in GitHub Desktop.
Save TheRealNOIG/47837fee2678fd4b6a94 to your computer and use it in GitHub Desktop.
Button class fore pepe goes to prom
using System;
namespace PepeGoesToProm
{
public class Button
{
public Texture2D texture {get; set;}
public Rectangle positionSize {get; set;}
public bool clickedOn {get; set;}
public bool overButton {get; set;}
public AABB collisionBox;
private MouseState ms;
private Color defaultColor;
private Color hoverColor;
private Color clickedColor;
private Color color;
public void LoadContent(Texture2D texture, Rectangle positionSize){
this.texture = texture;
this.positionSize = positionSize;
collisionBox.min = new Vector2(this.positionSize.X, this.positionSize.Y);
collisionBox.max = new Vector2 (this.positionSize.X + this.positionSize.Width, this.positionSize.Y + this.positionSize.Height);
}
public void LoadContent(Texture2D texture, Rectangle sizePos, Color defualtColor, Color hoverColor, Color clickedColor){
this.texture = texture;
this.positionSize = positionSize;
this.defualtColor = defualtColor;
this.hoverColor = hoverColor;
this.clickedColor = clickedColor;
collisionBox.min = new Vector2(this.positionSize.X, this.positionSize.Y);
collisionBox.max = new Vector2 (this.positionSize.X + this.positionSize.Width, this.positionSize.Y + this.positionSize.Height);
}
public virtual void Update(){
}
public void Draw(SpriteBatch sb){
sb.Draw(texture, positionSize, color);
}
public bool isOverButton(){
if(ms.Position.X > collisionBox.min.X && ms.Position.X < collisionBox.max.X &&
ms.Position.Y > collisionBox.min.Y && ms.Position.Y < collisionBox.max.Y)
return = true;
else
return = false;
}
public bool isClickedOn(){
if (ms.Position.X > collisionBox.min.X && ms.Position.X < collisionBox.max.X &&
ms.Position.Y > collisionBox.min.Y && ms.Position.Y < collisionBox.max.Y && ms.LeftButton == ButtonState.Pressed)
return true;
else
return false;
}
public void ResetCollision(){
collisionBox.min = new Vector2 (this.positionSize.X, this.positionSize.Y);
collisionBox.max = new Vector2 (this.positionSize.X + this.positionSize.Width, this.positionSize.Y + this.positionSize.Height);
}
}
}
using System;
namespace PepeGoesToProm
{
public class ButtonManager
{
public List<Button> buttonsList = new List<Button>();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment